Sunday, October 25, 2009

iPhone Game Project

My first iPhone game project is underway...



(click the image to make it larger)

Step one is learning all about basic physics and how to pull off physics in Flash. I have so far tackled basic velocity and trajectory along with some collision math (when two or more object bump into each other.)

In the above screen shot you can see an iPhone sized screen with 100 objects bouncing around the screen at random velocity, spinning at random rates, all random sizes and one of three random shapes. Next notice the colors. That is only helpful to me at the moment while I am programming but the color coding goes like this:

  • Green: the object recently bounces off of the west wall.
  • Yellow: the object recently bounced off of the north wall.
  • Orange: the object recently bounced off of the east wall.
  • Blue: the object recently bounced off of the south wall.
  • Red: Two or more objects recently collided with the object.
  • White: the object recently collided with another object but is currently not touching another object nor is it touching an outer wall.


Here is another screen shot with 400 objects all bouncing around the screen!


Almost nothing is anything other than red, meaning that flash is working hard to calculate a whole bunch of collisions. Technically, with 400 objects on the screen that means that Flash would potentially need to calculate 400 x 400 possible combinations of objects colliding. I recently learned a little trick about how to pull this off without demanding that amount of CPU power to collision detection. Basically, in short, I have divided the screen space into a grid and I am only testing for collision against objects that share reasonable proximity. This drastically cuts down on the number of tests. Next I can avoid testing similar converse cases meaning if I test if Object-A and Object-B are colliding then I don't have to test if Object-B and Object-A are colliding (that would be a valid test [permutation], but a redundant one.) That cuts the tests way back again. Finally, to keep track of objects I am sorting them into Vector (or data-type-based) Arrays which just cuts process time for lists of objects to test... in half!

Here is one more screen shot of the same view but with only 25 objects bouncing around...



You can see more colors at work depicting bounce-state in this example since there are fewer collision opportunities.

So, currently there are over 75,000 iPhone apps out there which means there are likely not many more opportunities falling into the "completely unique" category. Whatever game idea this evolves into, well... there will likely already be "an app for that." So I am not worried about competition. I am in search of killer cool ideas. My first game might be something simple like rounds of flying a spaceship through an asteriod field (like this game here) and each new screen would get increasingly more complicated. I have a few ideas for interesting ways to make the effort more challenging using multitouch and the accelerometer (when you tilt the iPhone) , but we will see.

Below is a tweaked version of this for the blog here (only 50 objects set into motion with object collision turned off):

No comments: