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 1, 5, 5, 5, 5],
[1, 1, 5, 6, 6, 6, 5, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 5, 5, 1, 1, 5, 1, 1, 4, 4, 1, 1, 1, 1, 1, 5, 1, 1, 1],
[7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7]];
//declare game object that holds info
game = {tileHeight:70};
game.cos30 = Math.cos(30*Math.PI/180);
game.tileSize = game.tileHeight/game.cos30/2;
//blank
game.Tile0 = function () { };
game.Tile0.prototype.walkable = true;
game.Tile0.prototype.frame = 1;
//Plains
game.Tile1 = function () { };
game.Tile1.prototype.walkable = true;
game.Tile1.prototype.frame = 2;
//Steppe
game.Tile2 = function () { };
game.Tile2.prototype.walkable = true;
game.Tile2.prototype.frame = 3;
//Desert
game.Tile3 = function () { };
game.Tile3.prototype.walkable = true;
game.Tile3.prototype.frame = 4;
//Snow
game.Tile4 = function () { };
game.Tile4.prototype.walkable = true;
game.Tile4.prototype.frame = 5;
//Water
game.Tile5 = function () { };
game.Tile5.prototype.walkable = false;
game.Tile5.prototype.frame = 6;
//Mountian
game.Tile6 = function () { };
game.Tile6.prototype.walkable = false;
game.Tile6.prototype.frame = 7;
//building the world
function buildMap(map) {
//attach empty mc to hold all the tiles and char
_root.attachMovie("empty", "tiles", ++d);
//declare clip in the game object
game.clip = _root.tiles;
//get map dimensions
var mapWidth = map[0].length;
var mapHeight = map.length;
//move game clip right and down so tiles appear on stage
game.clip._x = game.tileSize;
game.clip._y = game.tileHeight/2;
//loop to place tiles on stage
for (var j = 0; j<mapHeight; ++j) {
for (var i = 0; i<mapWidth; ++i) {
//name of new tile
var name = "t_"+i+"_"+j;
//make new tile object in the game
game[name] = new game["Tile"+map[i][j]]();
game.clip.attachMovie("tile", name, i*70+j*1);
//send tile mc to correct frame
game.clip[name].gotoAndStop(game[name].frame);
trace (game.clip[name]+" = "+game[name].frame);
game.clip[name]._x = i*game.tileSize*1.5;
game.clip[name]._y = j*game.tileHeight+i%2*game.tileHeight/2;
}
}
}
//make the map
buildMap(myMap);