Saturday, April 28, 2007


I made a start on our second game today (Asteroids). Using out existing structure I began piecing together the main game by implementing all the abstract methods. The structure I put together in the early stages of the project allows the developer to make use of event based methods, (e.g. onMouseleftClick) which simplifies the development process dramatically. Looking over the current collision detection system I feel its not up to a satisfactory standard, forcing the actual game to rely on generating and managing the lists of collidable objects.

The code used for Missile Command is still fairly generic so I copied across most of it, more importantly the initialisation code because it contained a lot of the setup. I also built some game object's for the game, see below:

  • Asteroid - This object will take care of all the asteroids on the screen and handles its own collision event. When a bullet collides with this object it will split itself into two smaller asteroids and destroy itself.
  • Ship - This will be the player controlled space ship, the player can fire bullets from this object. If it collides with an asteroid it will lose health or possibly explode.
  • Bullet - This object is setup to collide with all other objects, but because it is so generic its important not to put to much logic in it.
After I combined all of these things I was left with a semi working version of asteroids, I was getting the bullets colliding with asteroids and the ship moving around the screen. The ships movement wasn't entirely right I set it up so it would turn hard like a car would but I believe in the real game you float freely in the same direction until you accelerate. I told Pete about the problem I was having and asked him if he could work that out for me instead, he has been invaluable when it comes to the math and physics of the game. Pete also said he would look into the collision detection code and try and improve it, which will be great.

Whilst testing the ships movement I discovered that it wasn't moving correctly, for example if you turned to the left and held the key down it would move left once and pause for half a second and then repeat the turn consistently. Its the pause that is causing the problem it could potential cause the player to fail or die. So to fix this problem I setup a boolean (true/false) for each key that makes use of the keyPress. When a button is pressed the boolean is turned on and for each logic update/frame that is rendered to the screen it makes a check to see if the boolean is on, if it is it will execute the logic for that press. The boolean is then turned off when the key is released. Using this method ensures the motion of movement is smooth and instantaneous.

Screenshot of the game so far.

No comments: