New tile based platform engine – part 7 – trampolines
After the AS3 translation of AS2 part 6, it’s time to introduce trampolines.
Just like ladders, trampolines have their rules. Here they are:
1 – A trampoline does not act like a wall, so a player can walk through it just like a cloud
2 – A trampoline should never be placed over another trampoline
3 – When you land on a trampoline, your vertical speed is inverted
How does this affect gameplay?
Just try to play and reach that unreachable platform as shown in the picture

Here it is the actionscript: Read more
The great Multiwinia give-away
Sometimes Flash developers also work to game development on other platforms.
It’s the case of byronay that worked on Multiwinia, a multiplayer game that will make you challenge your opponent to a game of stick-man slaughter and witness devastating digital-war unfold.
Byron has decided to give away all 10 copies to random people and all you have to do to get one of those 10 copies is:
1 Download the demo copy of Multiwinia, from the Multiwinia website
2 Play the demo and take a screenshot of the game over screen showing you winning the game. Change the gamer tag to show your name and you have to have won the game to qualify.
3 Send the screenshot of you winning the game to dev[at]xiotexstudios.com. Make sure you put ‘The great Multiwinia give-away’ as the subject of the email.
Then Byron will choose the winners and post them his blog, where you can also find more information about the give-away in the official page.
At this time I wanted to know something more about RTS making and game developing on platforms different than Flash, and that’s the exclusive content Byron is sharing on this blog.
Byron’s opinions
Multiwinia was the first RTS game I have worked on. Previous games were games like Mutant Storm Empire for XBox 360 Live Arcade and NHL for XBox so Multiwinia was a fresh change. The biggest challenge was the sheer amount of activity going on in a single game and making sure that all 4 players saw the same thing. We did that by using a predictive physics system that when it worked well was a dream but when it went wrong was a nightmare to debug. The network protocol devised for this game is very light-weight and sends very little information between the clients and the server and yet we are able to have over 2000 units all having battles on screen. I must admit from a game point of view it is the game I am most proud to have worked on.
One of the biggest issues we had however was on the control mechanism – everybody has their own view on how an RTS game should be played and this caused a lot of issues with our beta testers and the magazines that were reviewing the game. In the end Chris Delay locked himself in a room for a week and came out with the current control methods we have and I think it works well.
Cheers,
Byron.
Let’s win the copy!
At the time I am writing, only 2 people won the free copy, so there are 8 more waiting for us.
What are you waiting for?
Triqui.com WordPress arcade now in beta
If you followed the Creation of a Flash arcade site using WordPress series you know I am about to release a WP Arcade theme with automatic game submission thanks to a plugin that parses MochiAds feed.
It’s time to open the beta to the public and make the site run.
It’s time to play, rate and comment games on triqui.com
As soon as you comment and rate games, I will be able to improve it thanks to your feedback.
Don’t forget I am about to release both the theme and the plugin for free a few days after the end of this month so your feedback is very appreciated.
Just a couple of technical information: the theme I am designing is a mix between the free version of Revolution Blog WordPress Theme and CSSEY, while the logo was made following Icey Styles in Photoshop tutorial.
New tile based platform engine – AS3 version
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; j<level_height; j++) {
-
for (i=0; i<level_width; i++) {
-
if (l[j][i] != 0) {
-
var t:tile = new tile();
-
t.x = i*tile_size;
-
t.y = j*tile_size;
-
t.gotoAndStop(l[j][i]);
-
level_container.addChild(t);
-
}
-
}
-
}
-
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;
-
level_container.addChild(h);
-
}
-
public function on_enter_frame(event:Event) {
-
ground_under_feet();
-
walking = false;
-
climbing = false;
-
if (press_left) {
-
xspeed-=speed;
-
walking = true;
-
}
-
if (press_right) {
-
xspeed += speed;
-
walking = true;
-
}
-
if (press_up) {
-
get_edges();
-
if (top_right == 6 || bottom_right == 6 || top_left == 6 || bottom_left == 6) {
-
jumping = false;
-
falling = false;
-
climbing = true;
-
climbdir = -1;
-
}
-
}
-
if (press_down) {
-
get_edges();
-
if (over == "ladder") {
-
jumping = false;
-
falling = false;
-
climbing = true;
-
climbdir = 1;
-
}
-
}
-
if (press_space) {
-
get_edges();
-
if (!falling && !jumping) {
-
jumping = true;
-
yspeed = -jump_speed;
-
}
-
}
-
if (!walking) {
-
xspeed *= friction;
-
if (Math.abs(xspeed)<0.5) {
-
xspeed = 0;
-
}
-
}
-
if (xspeed>max_speed) {
-
xspeed = max_speed;
-
}
-
if (xspeed<max_speed*-1) {
-
xspeed = max_speed*-1;
-
}
-
if (falling || jumping) {
-
yspeed += gravity;
-
}
-
if (climbing) {
-
yspeed = climb_speed*climbdir;
-
}
-
if (!falling && !jumping && !climbing) {
-
yspeed = 0;
-
}
-
xspeed += bonus_speed;
-
check_collisions();
-
h.x = x_pos;
-
h.y = y_pos;
-
xspeed -= bonus_speed;
-
}
-
public function ground_under_feet() {
-
bonus_speed = 0;
-
var left_foot_x = Math.floor((x_pos-6)/tile_size);
-
var right_foot_x = Math.floor((x_pos+5)/tile_size);
-
var foot_y = Math.floor((y_pos+9)/tile_size);
-
var left_foot = level[foot_y][left_foot_x];
-
var right_foot = level[foot_y][right_foot_x];
-
if (left_foot != 0) {
-
current_tile = left_foot;
-
} else {
-
current_tile = right_foot;
-
}
-
switch (current_tile) {
-
case 0 :
-
speed = air_acceleration;
-
friction = air_friction;
-
falling = true;
-
break;
-
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;
-
case 5 :
-
over = "cloud";
-
speed = ground_acceleration;
-
friction = ground_friction;
-
break;
-
case 6 :
-
over = "ladder";
-
speed = ground_acceleration;
-
friction = ground_friction;
-
break;
-
}
-
}
-
public function check_collisions() {
-
y_pos += yspeed;
-
get_edges();
-
// collision to the bottom
-
if (yspeed>0) {
-
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_bottom<bottom) {
-
y_pos = bottom*tile_size-9;
-
yspeed = 0;
-
falling = false;
-
jumping = false;
-
}
-
}
-
}
-
}
-
// collision to the top
-
if (yspeed<0) {
-
if ((top_right != 0 && top_right != 5 && top_right != 6) || (top_left != 0 && top_left != 5 && top_left != 6)) {
-
y_pos = bottom*tile_size+1+8;
-
yspeed = 0;
-
falling = false;
-
jumping = false;
-
}
-
}
-
x_pos += xspeed;
-
get_edges();
-
// collision to the left
-
if (xspeed<0) {
-
if ((top_left != 0 && top_left != 5 && top_left != 6) || (bottom_left != 0 && bottom_left != 5 && bottom_left != 6)) {
-
x_pos = (left+1)*tile_size+6;
-
xspeed = 0;
-
}
-
}
-
// collision to the right
-
if (xspeed>0) {
-
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.
New tile based platform engine – part 6 – ladders
It's time to introduce ladders.
Ladders are quite hard to do for one reason: there is a lot of ways of intending ladders.
Can the player jump when on a ladder?
Should a ladder act as a hole if the player walks on it?
These are only two of the many questions you may ask about ladders.
So I have to made some rules:
1) Player climbs the ladder up and down using UP and DOWN arrows
2) Player can jump when on a ladder
3) If the player is falling and encounters a ladder, he will keep falling until he presses UP or DOWN
4) Player can climb a ladder if at least one of its corners is in the ladder Read more
New tile based platform engine – part 5 – clouds
You asked for the clouds, and here they are.
Clouds are marked with a 5 in level array.
Next stop... ladders... Read more
New tile based platform engine – theory behind the player
This post will explain the theory behind the player of my tile based plaftorm engine, and answer to some questions readers made commenting steps 1 to 4
First, you must know how Flash converts coordinates to pixels.
The player in this platform is a rectangle whose width is 12 pixels and height is 18 pixels.
Its origin is set to (0, 0) so you should expect to have 6 pixels to the left, 6 to the right, 9 to the top and 9 to the bottom.
This is the theory that will make you fail your collision engine.
In this picture

You can see the red/white cross at in the center of the green rectangle (the player) representing the (0, 0) origin of the object, but if you look at the red pixel (yes, it's a pixel because the image is magnified) at real (0, 0) position, you will see it's not centered in the origin point as you could expect but it's moved one pixel to the right and one pixel to the bottom.
This happens because every pixel has a size, and its size is... one pixel.
So the red pixel starts at (0, 0) but its size makes him end at (1, 1).
For this reason, the right bottom yellow pixel it's not at (6, 9) as someone can imagine, but at (5, 8) while the left bottom one is a (-6, 8).
Fail to determine the real player edges and you will mess up the collision engine.
The couple of red pixels at the bottom of the rectangle, located at (-6, 9) and (5, 9) is not part of the player sprite, it's just a couple of pixels representing the feet of the player. The left and the right one.
Checking both feet can make me know what kind of tile the player has under its feet.
Obviously a player can have one foot on a tile and one foot on another tile.
That's why I had to decide the main foot. If your player has one foot on a normal tile and one foot on a ice tile, do I have to apply ground or ice friction?
I decided to make the left foot as the main one. This means if the left foot is not in the air, that's the foot that will inherit ground friction. If the left foot is in the air, then the main foot will be the right one.
This routine can (and will) be optimized in two ways: the first way checking if both feet are on the ground and looking for the tile in the middle of them.
The second way id determining if the player is facing left or right then assigning the right or left feet as the main one.
The other pixels (the yellow ones) are used to check collisions between the player and the environment... but I will talk about it later.
Now I would like to answer a couple of questions:
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.
Sure, but it would make harder to design level "on the fly" directly from the source code. Obviously the final version will have a matrix and an editor.
There is an inconsistency in that if the player gets on the conveyor belt throws you off. A related inconsistency is that the -> conveyor belt doesn’t affect you until you are on all the way but the <- conveyor belt starts as soon as you touch it
This is due because of the primary feet issue I described before.
That's all at the moment... next step... clouds... then more theory.
New tile based platform engine – part 4
For all jumping fanatics out there, I developed the jumping routine.
You can jump hitting SPACE, hope you like it.
From next post, I'll start explaining how I developed this script and obviously I will add a lot of tile types.
Now I need some decent pixel art to give the game a polished look.
And don't forget I am about to translate it into AS3... Read more
New tile based platform engine – part 3
In this 3rd step I introduced the gravity.
Now the hero starts on the top of the screen and he can walk "downhill" thanks to gravity.
During next step I'll introduce jumps, then a massive explication will follow.
And AS3 version, of course.
I have to say, making a platform engine is funny and a little harder than I expected. Read more
New tile based platform engine – part 2
In the second part of the engine, I added boundary walls.
Still raw code at the moment, but you can see it in action here.
It's the same thing as the one published in part 1, I just added walls and collisions.
One note... the hero now has its anchor point on its center, where in the previous example it was in the upper left corner Read more
Posts
- Rick Triqui: my first PlayCrafter game
- Prototype of a Flash game like Meeblings
- Games for the game developers!
- The art of debugging
- How to embed a text file in Flash
- Create a Flash game in minutes with PlayCrafter
- Upgrade your Flash CS4 to 10.0.2
- Play Mazeroll, my latest Box2D game
- Triqui MochiAds Arcade plugin for WordPress Released!!
- The MochiAds funnel
- Flash game creation tutorial - part 1
- Create a Lightbox effect only with CSS - no javascript needed
- Flash game creation tutorial - part 2
- Make a Flash game like Flash Element Tower Defense - Part 2
- Flash game creation tutorial - part 3
- Create a flash draw game like Line Rider or others - part 1
- Create a Flash Racing Game Tutorial
- Make a Flash game like Flash Element Tower Defense - Part 1
- Create a flash artillery game - step 1
- Create a flash draw game like Line Rider or others - part 5
- Flash game creation tutorial – part 5.2




(4.9 out of 5) - Flash game creation tutorial – part 3




(4.86 out of 5) - Creation of a platform game with Flash – step 2




(4.84 out of 5) - Create a survival horror game in Flash tutorial – part 1




(4.82 out of 5) - Create a flash artillery game – step 1




(4.82 out of 5) - Create a Flash Racing Game Tutorial




(4.8 out of 5) - Create a flash artillery game – step 2




(4.75 out of 5) - New tile based platform engine – part 6 – ladders




(4.74 out of 5) - Flash game creation tutorial – part 2




(4.73 out of 5) - The experiment – one year later




(4.7 out of 5)



