Flash prototype: walking on disappearing tiles
I remember an old c64 game (and some flash and javascript remakes) where you had to walk over all tiles in a stage, never walking on the same tile twice, because as you leave a tile, it disappears.
In this far-from-being-finished prototype, I took some pieces of code I found in a tutorial published on gotoandplay and coded this prototype.
Try to walk over all tiles, without falling down.
Cursor keys to move.
The whole actionscript is on the 1st frame
-
map = new Array();
-
generateMap();
-
drawIt(map);
-
_root.attachMovie("item", "sprite", 10000);
-
sprite._x = 40;
-
sprite._y = 40;
-
sprite.px = 2;
-
sprite.py = 2;
-
sprite.speed = 2;
-
sprite.steps = (20/sprite.speed);
-
sprite.moving = false;
-
sprite.count = 0;
-
sprite.dead = 0;
-
sprite.onEnterFrame = function() {
-
if (!this.dead) {
-
if (!this.moving) {
-
actual_tile = this.px+(this.py*7);
-
}
-
if ((Key.isDown(Key.LEFT)) && (!this.moving)) {
-
this.px--;
-
dir = "left";
-
this.moving = true;
-
}
-
if ((Key.isDown(Key.RIGHT)) && (!this.moving)) {
-
this.px++;
-
dir = "right";
-
this.moving = true;
-
} else if ((Key.isDown(Key.UP)) && (!this.moving)) {
-
this.py--;
-
dir = "up";
-
this.moving = true;
-
} else if ((Key.isDown(Key.DOWN)) && (!this.moving)) {
-
this.py++;
-
dir = "down";
-
this.moving = true;
-
}
-
if (this.moving) {
-
_root["tile_"+actual_tile]._alpha -= (100/sprite.steps);
-
trace(actual_tile+"-"+actual_tile%7+"-"+int(actual_tile/7));
-
map[actual_tile%7][int(actual_tile/7)] = 0;
-
if (this.count>=this.steps) {
-
this.moving = false;
-
this.count = 0;
-
} else {
-
switch (dir) {
-
case "left" :
-
this._x -= this.speed;
-
break;
-
case "right" :
-
this._x += this.speed;
-
break;
-
case "up" :
-
this._y -= this.speed;
-
break;
-
case "down" :
-
this._y += this.speed;
-
break;
-
}
-
this.count++;
-
}
-
}
-
if (!this.moving) {
-
valore = map[this.px][this.py];
-
if (valore == 0) {
-
this.dead = 1;
-
}
-
}
-
}
-
if (this.dead) {
-
this._alpha--;
-
if (this._alpha<0) {
-
this.dead = 0;
-
this._x = 40;
-
this._y = 40;
-
this.px = 2;
-
this.py = 2;
-
this._alpha = 100;
-
generateMap();
-
drawIt(map);
-
}
-
}
-
};
-
function drawIt(theMap) {
-
for (var y = 0; y<7; y++) {
-
for (var x = 0; x<7; x++) {
-
pos = x+(y*7);
-
if (theMap[x][y] == 1) {
-
_root.attachMovie("myTile", "tile_"+pos, pos);
-
_root["tile_"+pos]._x = x*20;
-
_root["tile_"+pos]._y = y*20;
-
}
-
}
-
}
-
}
-
function generateMap() {
-
map[0] = new Array(0, 0, 0, 0, 0, 0, 0);
-
map[1] = new Array(0, 1, 1, 1, 1, 1, 0);
-
map[2] = new Array(0, 1, 1, 1, 1, 1, 0);
-
map[3] = new Array(0, 1, 1, 1, 1, 1, 0);
-
map[4] = new Array(0, 1, 1, 1, 1, 1, 0);
-
map[5] = new Array(0, 1, 1, 1, 1, 1, 0);
-
map[6] = new Array(0, 0, 0, 0, 0, 0, 0);
-
}
Some comments to the code:
Lines 95-103 (yes, it's better to begin from the end): I define the map, in this case a 7*7 array. "1" means there is a tile on the floor, "0" means there is no floor, and you will fall down if you step over it.
Lines 83-94: Time to draw the map, attaching the same movieclip (a 20*20 red square) when I find a "1" in the map array.
Lines 1-13: Initializing the game and creating some variables, most of all about the main sprite (the 20*20 green square, the sprite you control)
Lines 15-36: Checking if an arrow key is pressed and if the sprite was already moving, then calculating new sprite's position according to the key pressed.
Lines 37-61: Routine that moves the main sprite and makes the floor disappear behind it
Lines 62-67: Checking if the sprite is on a tile or not
Lines 69-80: If the sprite is dead, because he has not floor under its feet, re-initialize the game and start again.
That's all at the moment, download the source code and give me feedback while I unleash some more ideas...
They can be easily customized to meet the unique requirements of your project.
19 Responses to “Flash prototype: walking on disappearing tiles”
Leave a Reply
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)


This is great and all.
But, I was wondering, would there be a way to make more levels with like bigger maps and such?
Joe, one way could be to make some squares black, being impassable, getting more and more. You’d have to be creative to make them successful and/or hard.
Will there be another tutorial on how to add more levels as i’m new to action script?
and i think the tutorial i fab !
thanks Mousey
Sure it will!!!!
??????????????????????????
do you put this in a flash file or no is it a move clip do you need to draw anything explain it geesis christ u moreon
i don’t get what you have to do.
i put the code in actions for the first frame and when i test movie nothing happens.
Its simple to make although i noticed its not all said it the tutorial,
First create a new document in flash with the dimentions:
140 by 140 and frame rate set to 40fps
Second you need 2 create 2 movie clips
one called my tile, make this a red square approx 19px by 19px. then in the library right click it and press export for action script, with the identifer set to my tile.
The next movie clip is called item make this the same as before but make it another colour (e.g. green) and when you set up the linkage set the identifer to item.
Last add the action script to the frame and it should work!
“??????????????????????????
do you put this in a flash file or no is it a move clip do you need to draw anything explain it geesis christ u moreon”
How old are you? I thought this tutorial was fine for someone with an IQ above 60…
Pretty awesome, especially considering how small the code is! I’m new to flash but not to programming, and this is already giving me some rad ideas to work on…
Was the C64 game reckless rufus by any chance?
Yeah, it was a good game, long live commodore64
Hi,
I found your blog via google by accident and have to admit that youve a really interesting blog :-)
Just saved your feed in my reader, have a nice day :)
Yea i’ll haft to try it. It’s sad thet im only 8 years old and i’m prity good at it.A’ll try that today. Ok
Dude I put the code in my first frame but nothing happens..
Also you could add holes already there, or powerups such as a bomb that destroys a 3×3 square. Perhaps you have to be a certain colour when touching certain tiles in later levels so you have to go to the tile that has the next colour first before you can destroy tiles of that colour
Hey im following the security tutorial how would i make a health pack dissipere
I was guessing that it would be like this code
Hi, excuse me for the dump question, but what code do you write when you want to remove the map – I mean, go to an end frame for the game or something like this. Just how to get rid of it, if you want to load something else.
I am newbie with Action Script and I will appreciate your help.
For an end frame, in the first frame or the frame the game is on, put stop(); to go to the next level or to the end page, put gotoAndStop(whatever frame the next level or end page is); somewhere but i don’t really know where.
how would i make it go to the next frame once the green square is on the last red square?
Hey, did you know your site is serving out malicious JS code?
Your site is on
http://www.malwaredomainlist.com/mdl.php?inactive=&sort=Date&search=&colsearch=All&ascordesc=DESC&quantity=100&page=0
2009/04/07_00:00 http://www.emanueleferonato.com/2006/11/26/flash-prototype-walking-on-disappearing-tiles/ 62.149.140.41 webx31.aruba.it compromised site/redirects to Mebroot itpuntoit snc, Emanuele info@itpuntoit.it