+1 Our Site! Let your friends know you like us.

Wednesday, December 14, 2011

Pathfinding (And Resuscitation)

Okay, so it's been a little while since anything went up here.
A long while.
Now that admissions of guilt are over, to the future! For the past couple of weeks I've been preparing for LudumDare #22 (click the link for a description if you don't know what that is), working out some problems that afflicted me last time, trying out some new concepts, getting better at commenting my code, and just generally practicing. I can't tell you how excited I am! No really, I can't. My motivation is a little bit gone at the moment, I've been quite sick this week.
Regardless, I *will* be participating, and I'll force myself to like it if I have to.
Today, I managed to implement some relatively simple pathfinding in a node-based system. Essentially, you split your playing map into nodes. You assign each node a list of neighboring nodes. After giving the system a starting node and an ending node, it determines which neighboring node has the shortest distance as the crow flies to the ending node, then makes that node the current node. This process is repeated, adding every node that has been visited to a "closed" list that it will not re-visit. Once the ending node is reached, the closed list becomes your path!
My system will *always* find a path if one exists (which is possible that it doesn't, considering some nodes are "unwalkable"), although it will not always be the shortest. It works well enough to satisfy me though! Especially since I spent all of my waking day throwing my currently broken brain at this problem, and all I've got is a barely working algorithm that is some 50 lines of code long... XP
Anyways, thanks for reading, and look for more posts from me soon!

No comments:

Post a Comment