VIRB

Friends, Music and Video... we're helping you stay connected.

Game Dev - Dynamic Maps & Tiles

1 comment | posted Aug 2

I started this project and abandoned it about a year ago and now decided to pick it up again. So, I'll write this as it gets created to hopefully steer you all along the right path of game dev(i.e. look at all my mistakes and avoid them) This isn't the first game I've ever done but it certainly is the most ambitious. So, first things first, what type of game are you creating? This was already done for me as I had setteled on the classic Strategy RPG format a la Final Fantasy Tactics, Ogre Tactics, etc. The medieval/fantasy element is almost old hat by now so I'm going with a future take. Essentially the world is under nuclear winter and humans are delegated to reside in congested areas where there is still power.


With the basic idea down, I wanted to get started coding the game components and flesh out the experience as I went(this is probably one of the things to avoid, but I'm too impatient to actually sit down and plan out anything). The core element to any RPG(aside from a convoluted incomprehensible plot) is the combat, which is carried out on an isometric tiled map where sprites beat the hell out of each other. To create the map, you need to start with an array, like this one:



Pretty simple, each number denotes a different tile which has its own properties and movie clip associated with it. 2 is a generic grey tile while 4 is a black tile that is lower in relation with the others. (To make an iso tile, make a square 50x50 px, rotate it 45 degrees, then shrink the height to 25 px. To give the tiles weight, I added what looks like a front and side panel making the final dimensions 50x33 px) I name each tile "tile1_mc", "tile2_mc", etc. Now that a few sample tiles have been created, we can try putting together a dynamic map. You could place each tile individually in the timeline, but after the first few maps, you'd be to burnt out to continue. The other option is a bit of code but easy enough to handle. A dynamic map maker is essentially a nested for loop that pays close attention to the height and width of the tiles it is using.




The function has two parameters, the array that you will be pulling from and the target movie clip. This target is important as once this gets going it will be the entire world of your game, so I usually call it "world_mc". We set up X and Y as the start coordinates (0,0). Now set up the nested for loop and get things going. First, we use the data we have to get the correct movie clip, I'll use i=0 and j=0 so you can follow along. Map[0][0] is the number 2, which is a grey tile. So, clip now equals "tile2_mc" which is what tile2_mc's linkage is set to. The next variable "Name" is used to reference the clip later and is just "ground" plus a corresponding number.


Target.attachMovie(clip, Name, _root.world_mc.getNextHighestDepth() + 4, {_x:X, _y:Y});


That is the code that attaches "tile2_mc" to "world_mc". Stepping through it, Target is "world_mc", clip is "tile2_mc", Name is "ground0_mc" and the depth is set to 4 higher than the current highest depth in the clip. The X and Y coords are currently (0,0) so this is the most north western tile. It builds east and south from there. Now we increase our X position by 50px and Y by 25px. Note that it isn't 33 even though that is the dimensions of the clip. I want to hide that depth except on the outer edges. Once that iterates through the first row, we need to set X and Y back to origin and even further because we are building out. So, X drops 50 px * (i+1) and Y increase 25px * (i+1).


Now call the function with: createMap(map, world_mc); When done, it should look something like this(except mine has a sprite in it):



Wow I had a lot more to cover than I got to, but that'll have to wait till next week: Sprite Creation and Movement

1 comment

You must be logged in to post comments.


Dave Waller says:

That's looking nice - some nice tidy code too.

I was building something similar a while ago but ran into a number of problems - the worst of which was a severe FP slowdown as you moved through more complex maps.

Anyway, it's still online over athttp://d13design.co.uk/index.php?cat=5 if you want to take a look.

posted Sep 7