New tile based platform engine – part 1
I am about to develop a tile based platform engine that (in my opinion) will allow to create a lot of different games just changing some parameters.
At the moment it only allows to move horizontally but everything is planned, from rooms to jumps, ladders and ropes.
My goal is making the developer only focus on level design.
The most interesting thing is I am developing both AS2 and AS3 versions of the engine.
The other platform engine I created some time ago is discontinued. This will be better.
In this first part, we have four tile types:
Ground: the normal ground, with a normal acceleration and friction
Ice: a slippery tire, with reduced acceleration and friction
Left and right treadmills: these tiles will increase/decrease your speed according to their arrow
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 | tile_size = 20;
ground_acceleration = 1;
ground_friction = 0.8;
ice_acceleration = 0.15;
ice_friction = 0.95;
treadmill_speed = 2;
max_speed = 3;
xspeed = 0;
level = new Array();
level[0] = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
level[1] = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
level[2] = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
level[3] = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
level[4] = [1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 1, 3, 3, 3, 3, 1, 1, 4, 4, 4, 4, 1, 1];
player = [1, 3];
function create_level(l) {
_root.createEmptyMovieClip("level_container", 1);
level_height = l.length;
level_width = l[0].length;
for (y=0; y<level_height; y++) {
for (x=0; x<level_width; x++) {
if (l[y][x] != 0) {
t = level_container.attachMovie("tile", "t"+y+"_"+x, _root.level_container.getNextHighestDepth(), {_x:x*tile_size, _y:y*tile_size});
t.gotoAndStop(l[y][x]);
}
}
}
x_pos = player[0]*tile_size;
y_pos = player[1]*tile_size;
level_container.attachMovie("hero", "hero", _root.level_container.getNextHighestDepth(), {_x:x_pos, _y:y_pos});
}
create_level(level);
_root.onEnterFrame = function() {
ground_under_feet();
walking = false;
if (Key.isDown(Key.LEFT)) {
xspeed -= speed;
walking = true;
}
if (Key.isDown(Key.RIGHT)) {
xspeed += speed;
walking = true;
}
if (!walking) {
xspeed *= friction;
if (Math.abs(xspeed)<0.5) {
xspeed = 0;
}
}
if (xspeed>max_speed) {
xspeed = max_speed;
}
if (xspeed<-max_speed) {
xspeed = -max_speed;
}
xspeed += bonus_speed;
x_pos += xspeed;
level_container.hero._x = x_pos;
xspeed -= bonus_speed;
};
function ground_under_feet() {
bonus_speed = 0;
y_feet = Math.floor(y_pos/tile_size)+1;
x_feet = Math.floor((x_pos+tile_size/2)/tile_size);
switch (level[y_feet][x_feet]) {
case 1 :
over = "ground";
speed = ground_acceleration;
friction = ground_friction;
break;
case 2 :
over = "ice";
speed = ice_acceleration;
friction = ice_friction;
break;
case 3 :
over = "treadmill";
speed = ground_acceleration;
friction = ground_friction;
bonus_speed = -treadmill_speed;
break;
case 4 :
over = "treadmill";
speed = ground_acceleration;
friction = ground_friction;
bonus_speed = treadmill_speed;
break;
}
} |
Move the player with arrows keys, more information to come during next days…
Download the source code and enjoy…
They can be easily customized to meet the unique requirements of your project.















(20 votes, average: 4.65 out of 5)









This post has 23 comments
HanClinto
Fantastic stuff, thanks so much!
Josh of Cubicle Ninjas
You’re awesome. Looking forward to seeing this engine come to life. :)
Anthrax
Can’t you show how to make a sprite? I’ve already done it, but that would be beneficial to others.
Also, you need to show how to make a scrolling background. I’ve also tried that, but it sucks.
Awesome tutorials!
Jack Hopkins
Nice! Will you be rewriting this in AS3?
Nutter666
Jack – Yeah he said he’s doing it in AS2 & AS3… Nice one Emanuele…. you create a platform engine….just after ive made my own..and you make it better =/… just kidding can’t wait to see how this turns out
Greg
He says he will in the description.
Koi Games
yeah, I’d love the code on as 3.0.
I think it’s time to create as 3.0 emanuele. People are already testing as 4.0…
RipeX
Very nice! :D
Anthrax
Don’t forget to make him jump!!
Wouldn’t a matrix be better than an array of arrays? It would be all one variable, and it would make a level editor easier to design, in my opinion.
Keep up the good work!
LanoG
A very useful code. Perhaps I can suggest other things to add as a tile such as non-moving item, trap, teleport, enemy etc.
One more suggestion is, in AS3.0, it is easier to create game level in different class, so that we can easyly edit tiles code.
Jerry
I agree with Anthrax that a matirx would be better the a list of arrays and make level building easier.
New tile based platform engine - part 2 : Emanuele Feronato
[...] the same thing as the one published in part 1, I just added walls and [...]
Gregory Athons
THIS is by far my favorite tutorial on your site. I am very ready to read the next couple parts for this tutorials. Thank you very much
New tile based platform engine - theory behind the player : Emanuele Feronato
[...] player of my tile based plaftorm engine, and answer to some questions readers made commenting steps 1 to [...]
Nathan
Koi Games-Please don’t discontinue your as2 stuff emanuele! There are a few of us still stuck in the dark ages(Flash 8)
Javier Lázaro
Thanks for all this series. I want to make a tile based game, and this will be very helpful.
fraser
im confused are we meant to make the tiles as seperate movieclips or in the one movieclip like the older platform engine
labs.VETTIGHEID » Blog Archive » AS3 Platform Engine
[...] I came on a very interesting blog about game design in actionscript. Emanuele had some really good tutorials about making a platform game in AS2. And in about 3 hours I had my own AS3 port of his engine and [...]
Tile based game: Level Editor
[...] time ago Emanuele Feronato post a series of tutorials about creating an Platform Tile Based Game, this inspire me and I decide to contribute his cause [...]
Level Editor
[...] you follow Emanuele Feronato may be you remember the Platform Tile Engine series, well I create a level editor he publish on his [...]
G84 Level Editor — Group 84 Blog
[...] time ago Emanuele Feronato post a series of tutorials about making a Platform Tile based Game. This tutorials inspired me and I decide contribute his cause with a Level Editor. More info in his [...]
ArowanaW
I’m still confused about a few lines of code, to be honest..
Can you explain to me, what does (level[y_feet][x_feet]) do?
And what’s the over variable for?
1120: Access of undefined property - Flashforum
[...] [...]