forked from hoangsonww/Space-Invader-Game-JavaFX
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Bullet.java
46 lines (36 loc) · 1001 Bytes
/
Bullet.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.paint.Color;
public class Bullet extends GameObject {
public static final int WIDTH = 4;
public static final int HEIGHT = 20;
private static final double SPEED = 7;
public Bullet(double x, double y) {
super(x, y, WIDTH, HEIGHT); // Pass the WIDTH and HEIGHT constants
}
@Override
public void update() {
y -= SPEED;
}
@Override
public void render(GraphicsContext gc) {
gc.setFill(Color.YELLOW);
gc.fillRect(x - WIDTH / 2, y - HEIGHT / 2, WIDTH, HEIGHT);
}
// In Bullet class
@Override
public double getWidth() {
return WIDTH;
}
@Override
public double getHeight() {
return HEIGHT;
}
private boolean dead = false;
public void setDead(boolean dead) {
this.dead = dead;
}
@Override
public boolean isDead() {
return dead;
}
}