The Joyride Labs no longer actively work on this project. A lot of the information on this website is outdated. See this blog post to find out more.
Nikki and the Robots

Here we write about Nikki and the Robots development and other news. Be sure to subscribe! Visit our reddit forum and join IRC for even more info!

Merging Tiles

WARNING: This is a development post. So if you're not into programming, you might find it pretty boring...
When you use our level editor and place some tiles in a scene, these have to be converted into polygons and handed to chipmunk, the physics engine. If we do that naive and create a rectangle for every tile, there are lots of problems with Nikki being stuck were two tiles meet. So the tiles have to be merged together and altered in a certain way, to allow Nikki to move through the levels as elegantly as desired. I don't want to go into the details here, but I want to write about my use of QuickCheck.
QuickCheck is a test framework for Haskell that lets you check if certain properties hold for auto-generated arbitrary values. And as the tile merging algorithm is a little too complex for my little brain, that came in quite handy. So I wrote a test suite that checked, if the tile merging algorithm did the following two things:
  • return a list of polygons where Nikki can't get stuck and
  • preserve the exact area that is covered by the input polygons.
Without QuickCheck I wouldn't have fixed nearly as many nifty corner cases. Here is a picture of some auto-generated input data (on the left) and the generated polygons that would have been handed to chipmunk:
a lot of squares
(btw: The picture doesn't represent a failing test case. The generated test cases were much simpler, due to QuickCheck's great shrinking feature.)

Tags: , ,

Leave a Reply