Development history for the game: Cell (Part 2)
Cell (Originally Prits and Prots) was programmed in Flex and is currently open sourced here (named Mom) on github.com.
Here we look at how I created the physics and main collisions for our Cell game.
The cell game wouldn't be a game without other cell interactions, or at least the ability to pick up other prots. For this we needed data structures for spacial indexing. For this game I used a simple double layer grid based data structure.
There are always 9 (3x3) grids on display in total, and each grid contains the sprites to be displayed. This can be a good or poor design choice depending on how many sprites you want to be displayed on the screen. If you need a more cropped design then using sprites per grid and even setting the view to a constant 9 grid display can add a little too many sprites for the game to run well.
[our grids and buckets, you can see grids overlapping a sprite]
Each grid holds 10x10 buckets (sub grids) and so each object on the grid holds a 3x3 bucket array that points to the containers near to the object. This is very useful for performing fast collision detection. In the game Mom we create covers that can be any size (ie. a 1x1 bucket, or a 10x5 bucket array). With only a 3x3 bucket array the size of the object is restricted to each size of the bucket.
For collision detection I used a very basic recursive circle-to-circle collision detection to handle multiple collisions. The result isn't perfect, as there aren't any physics forces involved. A really great resource for collision detection using a grid can be found on the programming pages at metanetsoftware.com, which they used in there game N.
Since each object on the grid has a fixed radius, we don't need to worry about sprites overlapping. Here are two demos:
[Click the screen to add an object that performs an fixed radius recursive collision with the other objects]
[Use the arrow keys to move and space-bar to absorb]
Grids can be shifted to make appear that the world is much larger. World information can be loaded as the player moves further, while shifting grids. In this way new levels can be introduced by having the player move into a new grid.
In the second example you will notice more of the game play mechanics for allowing the cell to absorb other objects. These spheres are more like nutrients for the cell to create proteins. The actual Cell game idea was changed. A face was added to the player's cell and a more interactive design was implemented with story and sound. This is the final result of the game Cell. An updated version that is still in-progress is called Mom.