-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBullet.java
More file actions
61 lines (41 loc) · 1.43 KB
/
Bullet.java
File metadata and controls
61 lines (41 loc) · 1.43 KB
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
//Kaushik Siruvuri, Ishaan Sharma, Supreet Mishra
import java.awt.*;
public class Bullet extends GameObject {
private Handler handler;
private HUD hud;
public Bullet(int x, int y, ID id, Handler handler) {
super(x, y, id);
this.handler = handler;
velY = -5;
}
public Rectangle getBounds() {
return new Rectangle((int) x, (int) y, 16, 16);
}
public void tick() {
y += velY;
if (y <= 0) handler.removeObject(this);
collision();
}
public void collision() {
for (int i = 0; i < handler.object.size(); i++) {
GameObject tempObject = handler.object.get(i);
if (tempObject.getId() == ID.BasicEnemy || tempObject.getId() == ID.Enemy2 || tempObject.getId() == ID.Enemy3) {
if (getBounds().intersects(tempObject.getBounds())) {
//collision code
handler.removeObject(tempObject);
handler.removeObject(this);
}
} else if (tempObject.getId() == ID.EnemyBoss) {
if (getBounds().intersects(tempObject.getBounds())) {
//collision code
hud.bossHEALTH -= 1;
handler.removeObject(this);
}
}
}
}
public void render(Graphics g) {
g.setColor(Color.green);
g.fillRect((int) x, (int) y, 16, 16);
}
}