Hi,
I'm new here, quite new to using Actionscript as well, but I need to create a tile based map using a 2d array. Its for a Pacman style game
I have tried to follow the tutorial on tonypa's site and so am using the same set up as that. I currently have the basic background along with the walls, however I am struggling to work out the code to randomly place pills onto the map. I know I need a FOR loop with a nested IF statement (to make sure pills arent placed over walls).
To make things slightly more complicated, all of the tiles are stored in one movie clip, frame 1 is walls, 2 is walkable, 3 is pills. I just have no idea of the code i need to use. I could do it if the placing didn't need to be random, i.e add to the array I have written.
So far I have the following (its a 30 x 30 array)
for (n = 0; n < maxPills; n++)
randx = Math.random()*30;
randy = Math.random()*30 ;
if (map[randx][randy] != tile.frame2)
map[randx][randy] = tile.frame3;
else
n--;
Here are a couple of examples of how I have declared the tiles. I have no idea how it works Im afraid, just was on the tonypa website and having no idea how to make tiles (and getting no help from my tutor) i just decided to use the code
game={tileW:30, tileH:30};
game.TileClass = function () {};
game.TileClass.prototype.walkable=false;
game.TileClass.prototype.frame=20;
game.Tile0= function () {};
game.Tile0.prototype.__proto__ = game.TileClass.prototype;
game.Tile0.prototype.walkable=true;
game.Tile0.prototype.frame=1;
game.Tile1= function () {};
game.Tile1.prototype.__proto__ = game.TileClass.prototype;
game.Tile1.prototype.walkable=false;
game.Tile1.prototype.frame=2;
they all refer to a movieclip named "tile" and are attached to the scene using the following code:
for (var i = 0; i < mapHeight; ++i) {
for (var j = 0; j < mapWidth; ++j) {
var name = "t_"+i+"_"+j;
game[name]= new game["Tile"+map[i][j]];
game.clip.attachMovie("tile", name, i*100+j*2);
game.clip[name]._x = (j*game.tileW);
game.clip[name]._y = (i*game.tileH);
game.clip[name].gotoAndStop(game[name].frame);
}
}