Talking about Pyramids of Ra game, and Flash.
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...
Never miss an update! Subscribe, and I will bother you by email only when a new game or full source code comes out.