Advertisement

Path finding algorthims for 2D Games???

Started by April 08, 2005 06:02 PM
6 comments, last by sled 19 years, 7 months ago
Hi, I've created (or at least started too). A small 2D game. Every sprite has a x and y location. A multidemensional vector of integers represents a map of tiles (tile size =48x64pixels). Each number in theMap represents a tpye of tile, so 0 is grass 2 is water etc. Using this the sprite can only walk on 0, everything else means the sprite can't move over it. My problem is how to get my sprites to find there way around such obsticles. For example. Say I have a map like so 0000000000 0000000000 0002222000 0002222000 0002222000 0002222000 0000000000 0000000000 IF this was a map where the top left tile was x=0 y=0 and the bottom right was x=10 y=8. Say I have a player sprite at x=0 y=4 and a enmemy sprite at x=10 amd y=4. If the enemey knows that the player is at 0,4. How can I get it to move to 0,4 and move around the object?? IS there any good articles on simple path finding?? Cheers
Lookup A* pathfinding. I have some code somewhere that demonstrates it.
Chess is played by three people. Two people play the game; the third provides moral support for the pawns. The object of the game is to kill your opponent by flinging captured pieces at his head. Since the only piece that can be killed is a pawn, the two armies agree to meet in a pawn-infested area (or even a pawn shop) and kill as many pawns as possible in the crossfire. If the game goes on for an hour, one player may legally attempt to gouge out the other player's eyes with his King.
Advertisement
Okay, this wasn't nearly as wonderful as I remember it being. I'm not even sure it's still A*, I kind of deviated a little from the original algorithm. Here it is anyway.



The example program uses Allegro, and there's no comments so if something doesn't work or make sense just yell.
Chess is played by three people. Two people play the game; the third provides moral support for the pawns. The object of the game is to kill your opponent by flinging captured pieces at his head. Since the only piece that can be killed is a pawn, the two armies agree to meet in a pawn-infested area (or even a pawn shop) and kill as many pawns as possible in the crossfire. If the game goes on for an hour, one player may legally attempt to gouge out the other player's eyes with his King.
You should take a look at James Matthews' A* Explorer that ships with sourcecode and you can test your own heuristics with the application.

Good luck

Eric
If you're really interested how A* Star and its variety of implementation
issues can be implemented
check out my article: go

PM me if it was any help

____________________Open Source ProjectsWebsite: www.nullpointer.chGames: | JCraft | Hotelbuster
This article was posted on GameDev just the other day and it covers A* pathfinding for beginners. I'd recommend it.
Advertisement
nice program
This site is a pretty good pathfinding resource:
http://www-cs-students.stanford.edu/~amitp/gameprog.html#paths

This topic is closed to new replies.

Advertisement