| scottie said: Bluuet Class import java.util.Random; import javax.swing.ImageIcon; public class Bullet extends Body { static final ImageIcon bullet = new ImageIcon("bullet.png"); static final Integer width = bullet.getIconWidth(); static final Integer height = bullet.getIconHeight(); // public Double yVelocity = y-SpaceShip.y; // public Double xVelocity = x-SpaceShip.x; // public Double yVelocity = SpaceShip.top(); public double yvelocity = Game.ship.getY(); public Double yVelocity = 3.0; public Double xVelocity = 3.0; public Bullet(Double xp, Double yp) { x = xp; y = yp; } public void draw(Game h, GameComponent canvas) { canvas.drawImage(bullet.getImage(), mapx(h, canvas, x), mapy(h, canvas, y)); } public Boolean offscreen() { return y > SpaceInvaders.ycanvas; } public void step(Game bw, GameComponent canvas) { // All they do is drop. y += yVelocity; x += xVelocity; } public Double width() { return (double) width; } public Double height() { return (double) height; } } |
That is exactly what I thought you did. You are gonna want to either pass the x and y coordinates or the SpaceShip object through a method. Maybe the constructor of the Bullet class.
public Bullet(Double xp, Double yp, SpaceShip ss) {
x = xp;
y = yp;
yVelocity = y-ss.y;
xVelocity = x-ss.x;
}
Also, why are you using Double instead of double?







