Hey guys I need help with part 2 of my space invaders game. So far I have the missile shooting from the base but the missile is only fired once and that's it. I need to finish the code so that once the missile hits the top of the window a new missile is launched from the base. Any suggestions? Here is my code:
import java.awt.Graphics;
import java.awt.Image;
public class Bullet {
//CONSTANTS
private final String BULLET_ICON = "bullet.gif";
private final int MAX_WIDTH;
private final int MAX_HEIGHT;
// Initial speed at which the bullet moves vertically
private final double INITIAL_X_SPEED = 0.5;
private final Sprite SPRITE;
// VARIABLES
private double upperLeftX, upperLeftY; // Position of cannon on canvas
/*
* Create a new cannon object - Constructor
*/
public Bullet(int theX, int theY , int theMaxWidth, int theMaxHeight) {
upperLeftX = theX;
upperLeftY = theY;
MAX_WIDTH = theMaxWidth;
MAX_HEIGHT = theMaxHeight;
// Get the graphical representation of the cannon
SPRITE = SpriteStore.get().getSprite(BULLET_ICON);
}
public void draw(Graphics g) {
SPRITE.draw(g, (int) upperLeftX, (int) upperLeftY);
}
boolean isRight = true;
public boolean BulletAtTop = false;
public void move(){
if (isRight == true) {
upperLeftY = (upperLeftY - INITIAL_X_SPEED);
}
}
}