A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: [RESOLVED] [AS2] Hex maps

Threaded View

  1. #1
    Senior Wabbit
    Join Date
    Jul 2008
    Location
    Winchester, Uk
    Posts
    215

    resolved [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.

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
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center