By using this site, you agree to our Privacy Policy and our Terms of Use. Close

Alright, Ill post all (or at least the relevant parts) of my code

the SpaceShip class


import java.util.Random;
import javax.swing.ImageIcon;

public class SpaceShip extends Body {

static final ImageIcon ship = new ImageIcon("ship.png");

static final Integer width = ship.getIconWidth();

static final Integer height = ship.getIconHeight();

public SpaceShip(Double xp, Double yp) {
x = xp;
y = yp;

}

public Integer clip = 7;

public Integer ammo = 70;

public void draw(Game h, GameComponent canvas) {

canvas.drawImage(ship.getImage(), mapx(h, canvas, x),
mapy(h, canvas, y));

}

public void step(Game bw, GameComponent canvas) {
if (canvas.leftPressed) {
x += -2;
if (x x = 0.0;
}
if (canvas.rightPressed) {
x += 2;
if (x > canvas.xdim - width)
x = 1.0 * canvas.xdim - width;
}
if (canvas.upPressed) {
y += -2;
if (y y = 0.0;
}
if (canvas.downPressed) {
y += 2;
if (y > canvas.ydim - height)
y = 1.0 * canvas.ydim - height;

}

if (canvas.rPressed) {
canvas.rPressed = false;
ammo = (ammo -7 + clip);
clip += 7;
System.out.println(ammo);
}


if (canvas.spacePressed) {
canvas.spacePressed = false;
if (clip >= 1) {
bw.missiles.add(new Missile(x + width / 2 - Missile.width / 2, y));
clip += -1;
System.out.println(clip);
}
}
}

public Double width() {
return (double) width;
}

public Double height() {
return (double) height;
}
}