|
-
[RESOLVED] [AS2] Hex maps
I am creating a hex map, the map is created from the array, all the tiles should be called in but I have found a the tiles are not appearing correctly
Ie line one of the array makes 36 tiles, these all appear though not to the frames asked only the first 10 appear (ie 0-9) so I believe the issue lies here, what is appearing so far is 5, 5, 5, 5, 5, 5, 5, 1, 1, 1 and the rest is followed by fails.
If anyone has any ideas please share, you can toggle full few and part view by pressing z.
You can see the swf at http://www.hobo-town.com/tbfc/map_test4.swf
My code is
Actionscript Code:
//1=Plains, 2=Steppe, 3=Desert, 4=Snow, 5=Water, 6=Mountian. myMap = [ [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 1, 1, 1, 1, 6, 6, 6, 1, 1, 1, 1, 1, 6, 6, 1, 1, 1, 1, 5, 5, 1, 1], [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 1, 1, 1, 1, 6, 6, 1, 1, 1, 1, 1, 1, 6, 1, 1, 1, 1, 1, 1, 5, 1, 1], [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 1, 1, 1, 1, 1, 1, 1, 1, 1, 5, 1, 1, 1, 1, 5, 5, 5, 1, 1, 5, 1], [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 1, 1, 1, 1, 1, 1, 1, 1, 5, 5, 5, 5, 1, 1, 1, 5, 5, 5, 1, 1], [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 1, 1, 5, 5, 1, 1, 1, 5, 5, 5, 5, 5, 1, 1, 1, 1, 1, 1], [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 1, 1, 5, 1, 1], [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 1, 1, 5, 5, 1, 1], [1, 5, 5, 6, 6, 1, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 1, 1, 1, 1, 5, 1, 1, 1, 5], [1, 1, 5, 6, 6, 6, 1, 1, 5, 1, 1, 1, 5, 1, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 1, 1, 1, 1, 1, 1, 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);
Last edited by Mr Wabbit; 03-23-2010 at 08:43 AM.
Reason: Updated
Trust my code, and not my english.
-
Updated the link to work and corrected the top paragraph, but still need someone to help fix my issue...
Trust my code, and not my english.
-
Code:
//1=Plains, 2=Steppe, 3=Desert, 4=Snow, 5=Water, 6=Mountian.
myMap = [
[5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 1, 1, 1, 1, 6, 6, 6, 1, 1, 1, 1, 1, 6, 6, 1, 1, 1, 1, 5, 5, 1, 1],
[5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 1, 1, 1, 1, 6, 6, 1, 1, 1, 1, 1, 1, 6, 1, 1, 1, 1, 1, 1, 5, 1, 1],
[5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 1, 1, 1, 1, 1, 1, 1, 1, 1, 5, 1, 1, 1, 1, 5, 5, 5, 1, 1, 5, 1],
[5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 1, 1, 1, 1, 1, 1, 1, 1, 5, 5, 5, 5, 1, 1, 1, 5, 5, 5, 1, 1],
[5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 1, 1, 5, 5, 1, 1, 1, 5, 5, 5, 5, 5, 1, 1, 1, 1, 1, 1],
[5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 1, 1, 5, 1, 1],
[5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 1, 1, 5, 5, 1, 1],
[1, 5, 5, 6, 6, 1, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 1, 1, 1, 1, 5, 1, 1, 1, 5],
[1, 1, 5, 6, 6, 6, 1, 1, 5, 1, 1, 1, 5, 1, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 1, 1, 1, 1, 1, 1, 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;
trace(game.tileSize);
//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;
//other
game.Tile7 = function() {
};
game.Tile7.prototype.walkable = false;
game.Tile7.prototype.frame = 8;
//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;
//loop to place tiles on stage
for (var i = 1; i<=mapHeight; i++) {
for (var j = 1; j<=mapWidth; j++) {
//name of new tile
var name = "t_"+i+"_"+j;
//make new tile object in the game
game[name] = new game["Tile"+map[i-1][j-1]]();
game.clip.attachMovie("tile",name,game.clip.getNextHighestDepth());
//send tile mc to correct frame
game.clip[name].gotoAndStop(game[name].frame);
trace(game.clip[name]+" = "+game[name].frame);
game.clip[name]._y = i*game.tileSize*1.5;
game.clip[name]._x = j*game.tileHeight+i%2*game.tileHeight/2;
}
}
}
//make the map
buildMap(myMap);
-
Thanks Dowsonk, your script was right but also wrong but in a different way, in which I was able to fix quickly and easily,
Using your script, as you added a few little items I had forgotten/ not really noticed that I should have added, let alone some my little layout errors, but that why you never program while falling asleep, talking of which, bed time.
I will place the changes to your script below so anyone looking at this in future might find this useful. The origional posted by dawsonk works for high hexs while the below changes work for long hexs
Actionscript Code:
game.clip[name]._y = j*game.tileHeight+i%2*game.tileHeight/2; game.clip[name]._x = i*game.tileSize*1.5; //You swapped the x and y round, this ment the tiles displayed in a straight line and not staggered for wide hexs.
//The rest were small swap arounds so it rendered landscape and not portrait var mapHeight = map[0].length; var mapWidth = map.length;
for (var j = 1; j<=mapWidth; j++) { for (var i = 1; i<=mapHeight; i++) { game[name] = new game["Tile"+map[j-1][i-1]]();
Last edited by Mr Wabbit; 03-25-2010 at 11:19 AM.
Trust my code, and not my english.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|