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.
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.
No comments:
Post a Comment