A Flash Developer Resource Site

Results 1 to 9 of 9

Thread: tilebased help?

Threaded View

  1. #1
    Flash Incompetent ChaseNYC's Avatar
    Join Date
    Jun 2002
    Location
    new york city
    Posts
    693

    tilebased help?

    Alright I'm trying to make somewhat of a tilebased game... Really more so a learning experience and a way to experiment. The way I learn languages is by setting a goal and then just diving in and learning what I need as I go along and following tutorials. My acitonscript knowledge is limited and blurly, I have been messing around with actionscript for a few years but very on-and-off... I made the website www.hrprivacy.com which I'm not too proud of but has some reasonably intricate code, or at least I think so. ANYWAYS, assuming I'm not asking too much I am using tonypa's website (http://www.tonypa.pri.ee/tbw) as a tutorial and I like it very much but some of his explanations don't exactly cut it especially since there is no dialog. The following code I understand completely:

    Code:
    // our map is 2-dimensional array
    myMap = [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], 
    		 [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1],
    		 [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1],
    		 [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1],
    		 [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1],
    		 [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]];
    // declare game object that holds info
    game = {tileW:20, tileH:20};
    // walkable tile
    game.Tile0 = function () { };
    game.Tile0.prototype.walkable = true;
    game.Tile0.prototype.frame = 1;
    // wall tile
    game.Tile1 = function () { };
    game.Tile1.prototype.walkable = false;
    game.Tile1.prototype.frame = 2;
    now I start to lose it in this next section:

    Code:
    // building the world
    function buildMap(map) {
    i don't understand where this term map comes in...

    edit: i figured out the whole map thingy xD
    Code:
    	// attach empty mc to hold all the tiles and char
    	_root.attachMovie("empty", "tiles", ++d);
    This makes sense except the ++d, i'm guessing it has something to do with how many tiles to make?

    Code:
    	// declare clip in the game object
    	game.clip = _root.tiles;
    makes sense

    Code:
    	// get map dimensions
    	var mapWidth = map[0].length;
    	var mapHeight = map.length;
    im confused about what map[0].length value would be equal to and map.length, im not sure where those come from...

    the rest of the lines are the following but I guess the above is enough to try and understand for now...
    Code:
    	// loop to place tiles on stage
    	for (var i = 0; i<mapHeight; ++i) {
    		for (var j = 0; 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][j]]();
    			// attach tile mc and place it
    			game.clip.attachMovie("tile", name, i*100+j*2);
    			game.clip[name]._x = (j*game.tileW);
    			game.clip[name]._y = (i*game.tileH);
    			// send tile mc to correct frame
    			game.clip[name].gotoAndStop(game[name].frame);
    		}
    	}
    }
    // make the map
    buildMap(myMap);
    stop();
    i hope i'm not asking too much even though this post is pretty long... I'm just trying to make sense of some of this code... thanks in advance ^^
    Last edited by ChaseNYC; 08-08-2005 at 07:43 PM.
    mmm signature

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