Making a game with Flash Develop + Flixel: Part 9, More Maps

Previously:

(Want to bypass the long explanations and see the final product? Here, download this post’s code as a ZIP file.)

Moving from the last part, we notice that the number of tilemap data files has grown. We now have two (“map1.txt” and “house1.txt”) and, as we start to have a map per house, that number is only going to grow larger. As a result, an increasing amount of our MapGroup file will be devoted over to holding all of the embed information per file.

However, there is another solution to this problem. Instead having so many resources spread across different files, we can copy all of the embed information into one single file to act as a singleton access interface. Like our Registry object, this could serve to hold any changes or updates to filenames or placement.

We can call this our Assets object.

Thinking about our current MapGroup object, then, we can see that, in using setTileProperties twice for both the village and house maps, we can actually combine their functionality. Instead of making multiple instances of FlxTilemap, we can abstract out something we can name an AreaGroup that has an internal tilemap, the ability to hold characters, and what tile represents the exit or door.

From there, we can update our MapGroup object to use AreaGroup objects for the village and door, supplying the arguments needed and adding characters to the public property of whatever instance of an AreaGroup needs them.

Looking back at AreaGroup, you may have noticed the array points. In the first version posted, it is only looked for the first instance of the exit tile. It expected only one way out of an particular area.

However, our village has four houses. Potentially, we need four different exits (using at least two different tile numbers) and then to associate those houses with tilemap data.

So, to start to move in that direction, let’s add three more tilemap data files for houses.

House 2

0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,5,9,9,9,9,9,4,0,
0,0,0,0,0,3,1,1,1,1,1,2,0,
0,0,0,0,0,3,1,1,1,1,1,2,0,
0,0,0,0,0,3,1,1,1,1,1,2,0,
0,0,0,0,0,3,1,1,1,1,1,2,0,
0,0,0,0,0,3,1,1,1,1,1,2,0,
0,0,0,0,0,3,1,1,1,1,1,2,0,
0,0,0,0,0,3,1,1,1,1,1,2,0,
0,0,0,0,0,3,1,1,1,1,1,2,0,
0,0,0,0,0,6,8,8,10,8,8,7,0

House 3

0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,5,9,9,9,9,9,4,0,
0,0,0,0,0,3,1,1,1,1,1,2,0,
0,0,0,0,0,3,1,1,1,1,1,2,0,
0,0,0,0,0,3,1,1,1,1,1,2,0,
0,0,0,0,0,3,1,1,1,1,1,2,0,
0,0,0,0,0,3,1,1,1,1,1,2,0,
0,0,0,0,0,6,8,8,10,8,8,7,0

House 4

0,0,0,0,0,0,0,0,0,0,0,0,
0,0,5,9,9,9,9,9,9,9,9,4,
0,0,3,1,1,1,1,1,1,1,1,2,
0,0,3,1,1,1,1,1,1,1,1,2,
0,0,3,1,1,1,1,1,1,1,1,2,
0,0,3,1,1,1,1,1,1,1,1,2,
0,0,3,1,1,1,1,1,1,1,1,2,
0,0,3,1,1,1,1,1,1,1,1,2,
0,0,3,1,1,1,1,1,1,1,1,2,
0,0,3,1,1,1,1,1,1,1,1,2,
0,0,6,8,8,8,8,8,10,8,8,7

Update the Assets file:

Then, we can update the AreaGroup object to take an array of possible doortiles and use a separate function for exposing a map index.

And with that, we can update MapGroup to use these new properties and functions.

(Note: Right now, we are using hard-coded values for placement. Ideally, you should avoid that. Door placement should be read from a file or as part of a larger data set.)

Now, we can walk into different rooms (areas) by going through the doors to houses.

step1

In Part 10, we move to include Merchants and Enemies by extending NPCSprite as the start towards a basic battle and economic systems.