QuadTree

Got all fired up to do collision detection for some reason, so I wrote a QuadTree implementation in Lua. Performs pretty well, especially when tuned right – it handles 256 objects bouncing around a 3×3 screen area at around 75% of one core on my desktop, and doesn’t start even dropping frames until I drop in 512 objects. In the scenario above (256 objects, 32x32px in size, bouncing around an area 960x720px in size), the engine is doing between 600 and 1000 collision checks per cycle; for comparison, brute-force checking for that many objects would require around 33,000 (and when I try it, the framerate drops from 60 to around 4).

Working with Tiled maps got me experimenting with XML formatting for my object definitions, too. I’ve already worked out a document style which encapsulates the animation and some basic logic, giving me a nice, compact way to sketch out player and enemy behavior. Next up: terrain collisions and physics.

Bookmark the permalink.

Comments are closed.