Hey everyone. It's been a little while. I've been busy with work and the Global Game Jam (
http://mission-imp.tims-world.com) and everything.
I don't have a huge update, but I wanted to show off the map logic that I came up with.
Basically, I knew that I wanted my maps to work something like the Mario 3 maps. A series of nodes that you can navigate between (once they've opened up).
First, I defined my levels themselves, using JSON.
{"levels":[
{"id":0, "type":1, "style":0, "size":16, "density":1, "level":1, "connections":1, "enemies":[0], "spawnRate":10, "destructGoal":500 },
{"id":1, "type":1, "style":0, "size":16, "density":1, "level":1, "connections":1, "enemies":[0], "spawnRate":10, "destructGoal":600 },
{"id":2, "type":1, "style":0, "size":18, "density":1, "level":1, "connections":1, "enemies":[0], "spawnRate":9, "destructGoal":700 },
{"id":3, "type":1, "style":0, "size":18, "density":1, "level":1, "connections":2, "enemies":[0], "spawnRate":8, "destructGoal":800 },
{"id":4, "type":1, "style":0, "size":20, "density":1, "level":2, "connections":2, "enemies":[0], "spawnRate":7, "destructGoal":900 }
]}
This is the first 5 levels in the game, with all of the details that need to be passed to the map creator.
id = the level's id number
type = the kind of map it is - the only type I have right now is '1' which is 'destruction' where the goal is to fill up your destruction meter to 'win' that level.
style = is not used yet, but is planned to set the tiles used for this map, so we can have a variety of different looking cities.
size = how big the city is
density = how close the roads are packed together in the city
level = defines the height of the buildings - higher level means more taller buildings
connections = how many roads reach the edges of the city - which is also the spawn points for enemies
enemies = defines which enemies will spawn in this level (I only have tanks ["0"] right now)
spawnRate = how fast enemies spawn in seconds
destructGoal = how much the player has to destroy to beat the level
This file is read in when the game starts, and the level definitions get stuck in an array, so that if I want `level[0]` it gives me the properties of the first level, etc.
Next, I started setting up my map screen. This was much trickier than I expected. I knew that I wanted to have different 'worlds', each with their own levels, and I wanted to be able to allow for branching paths, and 'roads' that turned.
What I came up with was to define all the nodes on a map in another JSON file, including any 'pass-through' nodes.
{"nodes":[
{"world":0,"id":0,"level":0,"neighbors":[-1,-1,-1,1], "x":0, "y":0},
{"world":0,"id":1,"level":1,"neighbors":[-1,-1,0,2], "x":1, "y":0},
{"world":0,"id":2,"level":-1,"neighbors":[1,-1,-1,3], "x":2, "y":0},
{"world":0,"id":3,"level":2,"neighbors":[2,4,-1,7], "x":2, "y":1},
{"world":0,"id":4,"level":-1,"neighbors":[3,5,-1,-1], "x":2, "y":2},
{"world":0,"id":5,"level":-1,"neighbors":[4,6,-1,-1], "x":3, "y":2},
{"world":0,"id":6,"level":3,"neighbors":[5,-1,-1,-1], "x":3, "y":3},
{"world":0,"id":7,"level":4,"neighbors":[-1,-1,3,-1], "x":6, "y":1}
]}
This is what I have right now for the first map in the game, which uses those first 5 levels.
world = which world map this node is on
id = the id of this node
level = which level this node points to - the '-1's are 'pass-through' nodes.
neighbors = this is an array of the node-ids that this node directly connects to. I'll explain this more in a minute.
x and y = the position of this node on the map
I load these nodes in and build my map by using the x,y values.
It ends up looking something like this:

(I added the Blue lines and numbers for reference)
So, working out the 'neighbors' was really tricky. The array for 'neighbors' goes: UP, DOWN, LEFT, RIGHT. So, if you look at that first record: '[-1, -1, -1, 1]' it says that the first node #0 (which is at '0,0') has no neighbors UP, DOWN, or LEFT, but RIGHT points to node #1.
If the player is on node #0, and they hit RIGHT, they will move to the right, and end up at node #1.
node #1 says that it has a neighbor to the LEFT (#0, which we know about already), and a neighbor to the RIGHT (#2).
node #2 however is a pass-through node. It says that it has a neighbor UP (#1) and to the RIGHT (#3) So, when the player is on #1 and they hit RIGHT, it see that they should move to node #2, which it to the right, but, once they get there, the pass-through node looks at where they came FROM (they came from the RIGHT), and immediately sends them to that neighbor, which is #3. Node #3, though, is DOWN from node #2.
From node #3, if they hit UP, it goes to node #2, and, since node #2 sees that it's UP neighbor = 1, it sends them to the LEFT, over to node #1.
This works pretty great! In addition to the stuff in the JSON file, I have a few properties of the level such as if it's unlocked or beaten or not, which, depending on the flag, will prevent the player from moving along a path. Also, if the player is on a level node, they can hit FIRE to start that level, and it properly launches the PlayState - loading the map and everything.
So, the game is coming along! I'm going to try to work on the different enemies, level conditions, game over/level clear screens, and upgrade menus next.
I wonder if I should start looking for an artist yet...