| Zombie simulator: reworking roads and a new car |
|
|
|
| Sunday, 07 February 2010 21:12 |
|
After playing around with the pathfinding for a while I decided I needed to make the roads wider. Technically, the cars would "just fit" onto half the road tile, but it was a tight squeeze. It was at this point the real issue showed up: cornering. Unless the cars came to a dead stop at each corner, there simply wasn't enough room to have them arc around bend without crossing into the oncoming lane, so they'd have to continue to take corners Light Cycle style, just as they had in the last video. Logically, simplest solution was just to expand the black road lines in the map bitmap to two pixels wide... that's when things became interesting. My current algorithm for working out the road pieces that make up the map is actually very simple:
Following this bit of logic it gets more technical where polygons are created, adjoining road sections are merged into single polygon runs, and finally it's all textured. Under the new system, the simplicity would be gone because it becomes lot harder to work out where each road piece begins and ends. I fooled around with various ideas for dealing with this new map layout, all of which invariably came back to some sort of bitmap to vector algorithm followed by identifying which parts of the vector image are the various straights, intersections, etc. Yuck. There had to be an easier way, and I finally found it. I redrew the map using double thick road lines, then added a bit of code at the top of the road analyser that would examine each pixel on the map, starting at the top left, then clear out any road pixel that did not have another road pixel either directly to the right or the directly below it. This modified map was passed into the regular road generator which ran without change, apart from tweaking the constant that sets the width of road pieces to double the size. Twelve lines of code, and Bob's your uncle. To celebrate, I took some time off coding to add a new vehicle, a two door 4WD, loosely based on a Mitsubishi Pajero. Here's a shot of the new car sitting on the new double wide road (that's still using the old road texture, now stretched, soon to be replaced).
|



