Talking about Platform game game, Actionscript 3, Flash and Game development.
First, I would like to say the engine is not finished as I have a lot of tile types to add.
This is the AS3 version of part 6.
I am fixing some glitches and preparing another post about the theory of platform games
This is the code
package {
import flash.display.Sprite;
import flash.ui.Mouse;
import flash.events.Event;
import flash.events.KeyboardEvent;
public class newplat06_as3 extends Sprite {
var over = "";
var bonus_speed = 0;
var press_left = false;
var press_right = false;
var press_up = false;
var press_down = false;
var press_space = false;
var x_pos = 0;
var y_pos = 0;
var tile_size = 20;
var ground_acceleration = 1;
var ground_friction = 0.8;
var air_acceleration = 0.5;
var air_friction = 0.7;
var ice_acceleration = 0.15;
var ice_friction = 0.95;
var treadmill_speed = 2;
var max_speed = 3;
var xspeed = 0;
var yspeed = 0;
var falling = false;
var gravity = 0.5;
var jump_speed = 6;
var climbing = false;
var climb_speed = 0.8;
var level = new Array();
var player = new Array(5,1);
var h:hero = new hero();
public function newplat06_as3() {
level[0] = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1];
level[1] = [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1];
level[2] = [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 6, 1, 0, 0, 0, 0, 1];
level[3] = [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 0, 0, 0, 0, 0, 1];
level[4] = [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 0, 0, 0, 0, 0, 1];
level[5] = [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 0, 0, 0, 0, 0, 1];
level[6] = [1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 6, 1, 0, 0, 0, 0, 0, 1];
level[7] = [1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 1];
level[8] = [1, 1, 1, 1, 0, 0, 0, 0, 0, 5, 5, 0, 0, 0, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 1];
level[9] = [1, 1, 1, 1, 3, 3, 3, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 4, 4, 4, 4, 1, 1];
create_level(level);
addEventListener(Event.ENTER_FRAME,on_enter_frame);
stage.addEventListener(KeyboardEvent.KEY_DOWN, key_down);
stage.addEventListener(KeyboardEvent.KEY_UP, key_up);
}
public function key_down(event:KeyboardEvent) {
if (event.keyCode == 32) {
press_space = true;
}
if (event.keyCode == 37) {
press_left = true;
}
if (event.keyCode == 38) {
press_up = true;
}
if (event.keyCode == 39) {
press_right = true;
}
if (event.keyCode == 40) {
press_down = true;
}
}
public function key_up(event:KeyboardEvent) {
if (event.keyCode == 32) {
press_space = false;
}
if (event.keyCode == 37) {
press_left = false;
}
if (event.keyCode == 38) {
press_up = false;
}
if (event.keyCode == 39) {
press_right = false;
}
if (event.keyCode == 40) {
press_down = false;
}
}
public function create_level(l) {
var level_container:Sprite = new Sprite();
var level_height = l.length;
var level_width = l[0].length;
addChild(level_container);
for (j=0; jmax_speed) {
xspeed = max_speed;
}
if (xspeed0) {
if ((bottom_right != 0 && bottom_right != 6) || (bottom_left != 0 && bottom_left != 6)) {
if (bottom_right != 5 && bottom_left != 5) {
y_pos = bottom*tile_size-9;
yspeed = 0;
falling = false;
jumping = false;
} else {
if (prev_bottom0) {
if ((top_right != 0 && top_right != 5 && top_right != 6) || (bottom_right != 0 && bottom_right != 5 && bottom_right != 6)) {
x_pos = right*tile_size-6;
xspeed = 0;
}
}
prev_bottom = bottom;
}
function get_edges() {
// right edge
right = Math.floor((x_pos+5)/tile_size);
// left edge
left = Math.floor((x_pos-6)/tile_size);
// bottom edge
bottom = Math.floor((y_pos+8)/tile_size);
// top edge
top = Math.floor((y_pos-9)/tile_size);
// adjacent tiles
top_right = level[top][right];
top_left = level[top][left];
bottom_left = level[bottom][left];
bottom_right = level[bottom][right];
}
}
}
The result is the same, so no need to publish it… just download the source code.
Never miss an update! Subscribe, and I will bother you by email only when a new game or full source code comes out.