If you are looking for AS3 version of step 10, here it is… made by Robin vd Vleuten from the Netherlands with scrolling included!
Hello Emanuele,
I made it with flex so I use a swc to access the tiles. All the code is now in one actionscript-file, but I’m trying to convert the code in different classes. I will email it also when its finished if you’re interested in it.
Also many thanks for helping me out with the basics of a platform engine. It helped me a lot with a project I’m working on.
Regards,
Robin
P.S. Just another cool thing I had forgot to tell you. I made the game scrollable with just 2 extra lines of code :D
Here it is the source code…
package {
import flash.display.Sprite;
import flash.events.Event;
import flash.events.KeyboardEvent;
[SWF(width='500', height='400', frameRate='40', backgroundColor='0xffffff')]
public class Platform extends Sprite
{
private var over:String = "";
private var bonus_speed:Number = 0;
private var press_left:Boolean = false;
private var press_right:Boolean = false;
private var press_up:Boolean = false;
private var press_down:Boolean = false;
private var press_space:Boolean = false;
private var x_pos:Number = 0;
private var y_pos:Number = 0;
private var tile_size:Number = 20;
private var ground_acceleration:Number = 1;
private var ground_friction:Number = 0.8;
private var air_acceleration:Number = 0.5;
private var air_friction:Number = 0.7;
private var ice_acceleration:Number = 0.15;
private var ice_friction:Number = 0.95;
private var treadmill_speed:Number = 2;
private var max_speed:Number = 3;
private var xspeed:Number = 0;
private var yspeed:Number = 0;
private var falling:Boolean = false;
private var gravity:Number = 0.5;
private var jump_speed:Number = 6;
private var climbing:Boolean = false;
private var climb_speed:Number = 0.8;
private var coins:Array = new Array();
private var level:Array = new Array();
private var levelObj:Array = new Array
private var keys:Array = new Array();
private var player:Array = new Array();
private var enemy:Array = new Array();
private var walkable_tiles:Array = new Array(0, 5, 6, 7);
private var h:hero = new hero();
private var level_container:Sprite = new Sprite();
private var bottom:Number;
private var left:Number;
private var right:Number;
private var top:Number;
private var bottom_left:Number;
private var bottom_right:Number;
private var top_left:Number;
private var top_right:Number;
private var climbdir:Number;
private var current_tile:Number;
private var friction:Number;
private var speed:Number;
private var jumping:Boolean;
private var walking:Boolean;
private var prev_bottom:Number;
public function Platform()
{
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, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 0, 0, 0, 0, 0, 1];
level[4] = [1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 6, 0, 0, 0, 0, 0, 1];
level[5] = [1, 0, 0, 0, 0, 1, 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, 1, 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, 1, 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, 9, 0, 0, 0, 5, 5, 0, 0, 0, 7, 0, 0, 6, 0, 0, 0, 0, 7, 0, 1];
level[9] = [1, 1, 1, 1, 1, 1, 1, 2, 2, 8, 8, 8, 8, 1, 1, 3, 3, 1, 4, 4, 1, 8, 1, 8, 1];
player = [4,8];
coins[0] = [2, 2];
coins[1] = [23, 4];
enemy[0] = [10, 3, -2];
enemy[1] = [3, 3, -2];
keys[0] = [1, 5, 5, 8];
create_level(level);
addEventListener(Event.ENTER_FRAME,onEnterFrame);
stage.addEventListener(KeyboardEvent.KEY_DOWN, key_down);
stage.addEventListener(KeyboardEvent.KEY_UP, key_up);
}
public function key_down(event:KeyboardEvent):void
{
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):void
{
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:Array):void
{
var level_height:Number = l.length;
var level_width:Number = l[0].length;
addChild(level_container);
for (var j:Number = 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) {
if ((bottom_right == 7 || bottom_left == 7) && (Math.abs(yspeed)>1))
{
// trampoline
yspeed *= -1;
jumping = true;
falling = true;
}else {
y_pos = bottom*tile_size-9;
yspeed = 0;
falling = false;
jumping = false;
}
} else {
if (prev_bottom0) {
if (!is_walkable(top_right) || !is_walkable(bottom_right)) {
x_pos = right * tile_size - 6;
xspeed = 0;
}
}
prev_bottom = bottom;
}
public function get_edges():void
{
right = Math.floor((x_pos+5)/tile_size);
left = Math.floor((x_pos-6)/tile_size);
bottom = Math.floor((y_pos+8)/tile_size);
top = Math.floor((y_pos-9)/tile_size);
top_right = level[top][right];
top_left = level[top][left];
bottom_left = level[bottom][left];
bottom_right = level[bottom][right];
}
public function place_player():void
{
x_pos = (player[0] * tile_size) + (tile_size / 2);
y_pos = (player[1] * tile_size) + (tile_size / 2 + 1);
h.x = x_pos;
h.y = y_pos;
}
public function is_walkable(tile:int):Boolean {
var walkable:Boolean = false;
for (var i:int = 0; i < walkable_tiles.length; i++)
{
if (tile == walkable_tiles[i])
{
walkable = true;
break;
}
}
return (walkable);
}
}
}
And this is the result:
Download the source code and make big kudos to Robin!!