forked from hoangsonww/Space-Invader-Game-JavaFX
-
Notifications
You must be signed in to change notification settings - Fork 0
/
BossEnemy.java
67 lines (51 loc) · 1.3 KB
/
BossEnemy.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.paint.Color;
import java.util.List;
public class BossEnemy extends Enemy {
private int health = 5;
private int WIDTH;
private int HEIGHT;
private int numHits = 5;
public BossEnemy(double x, double y) {
super(x, y);
SPEED = 1.0;
WIDTH = 50;
HEIGHT = 50;
health = 5;
}
@Override
public void update() {
// BossEnemy stays at the top of the screen
if (y < 40) {
y += SPEED;
}
}
public void takeDamage() {
health--;
if (health <= 0) {
setDead(true);
}
}
public void shoot(List<GameObject> newObjects) {
if (Math.random() < 0.015) {
newObjects.add(new EnemyBullet(x, y + HEIGHT / 2));
}
}
public void decreaseHealth() {
health--;
}
public boolean isDead() {
return health <= 0;
}
@Override
public void render(GraphicsContext gc) {
gc.setFill(Color.BLUE);
gc.fillRect(x - WIDTH / 2, y - HEIGHT / 2, WIDTH * 2, HEIGHT * 2);
}
public void hit() {
health--;
if (health <= 0) {
setDead(true);
}
}
}