|
RHS |
BallGame 02
Shooting spaceship
Add functionality to the spaceship from BallGame 01 so it can shoot.
Each time you press the spacebar a bullet object should be created with the default position given by the tip of the spaceship.
You can use this class : bullet.java
A bullet should have its position updated for each "time-click". The position should only change in the y-direction so the bullet moves upward. When the bullet reaches the top of the frame it is not needed anymore and should be disposed.
As you should be able to add bullets for each press on the spacebar your game will need to handle a collection of bullets. Each bullet must be updated and drawn in each time-click.
Using images
Using the ImagesLoader.java (see chapter 4 for a detailed description) we can make the game look a little nicer.
Change the SpaceShip.java and Ball.java so they draw an image instead of the boring geometric figure.
Don't waste your time on finding fancy images - its not important. Use these:
grenade.gif for the ball and
ufo.gif for the spaceship.
Hint: As an ImageLoader object can load and manage several images it's probably a good idea to hold that object in the controller part of your game. Then when an image should be drawn by the ball or spaceship object your controller should pass the correct image to the draw() method. this way its also easy to change the image when needed (i.e. when something explodes).