Game Development Community

First Blog: Map Generation and Pathfinding

by James Steinmetz · 04/19/2009 (9:38 am) · 2 comments

This is my first blog post, so I hope I am using MarkupLite right.

Here is an example of two script files I wrote for a turn-based strategy game I am currently working on. One file generates a map that is usable by the the pathfinding script I used. Here is a video.

I can possibly upload the actual script files if there is an interest for them. They are clean looking but un-commented at the moment.

If you can point me towards a better screen capturing program than jing; Please do.
Movie

What is happening here?

The function mapGeneration(6, 5, $map03) creates a 6 x 5 map by reading a string of letters from the variable in a separate CS file called $map03. Each letter represents a different kind of node: Open, Forest, Mountain and Unwalkable and sets the imagemaps and weight value appropriately. It also sets the name of the node and each related node. I used the naming convention Node#. So the relatedNodes field look like: "Node1 Node3 Node8".

I wrote a custom script for the pathfinding although it could be considered A*. I decided to write my own script because I thought it would give me more flexibility later on in development.

This is an example of $map03. As of right now, the map is mirrored from what you see here because of the way it reads the string. I should just have to change the nodes to being drawn right to left to fix it.

Update : I was able to fix the mirroring map by changing a math equation and replacing a + with a - in the mapGeneration function.

// 6 x 5		
$map03 =	"m" SPC "o" SPC "f" SPC "o" SPC "o" SPC "o" SPC
			"m" SPC "f" SPC "f" SPC "x" SPC "x" SPC "f" SPC
			"x" SPC "x" SPC "o" SPC "x" SPC "m" SPC "f" SPC
			"o" SPC "o" SPC "f" SPC "o" SPC "m" SPC "x" SPC
			"f" SPC "f" SPC "x" SPC "x" SPC "o" SPC "f";

There are probably a thousand better ways to write script.

About the author

Recent Blogs


#1
04/19/2009 (11:35 am)
Nice little video! Good work.
#2
04/20/2009 (6:31 am)
here comes the interest ! i would appreciate if u could upload your script files. i just bought the tbg in order to start my 2D turn-based-strategy-game project. and generate map + pathfinding is a exactly what i was looking for.

if u find out how to implement synchron movement in multiplayer in ur tbs game pls share your knowledge as well :)

thx dave