-
Notifications
You must be signed in to change notification settings - Fork 0
/
Bullet.java
59 lines (46 loc) · 1.12 KB
/
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
47
48
49
50
51
52
53
54
55
56
57
58
59
package com.ks2002br.entities;
/*
* By Elisandro 12/2021 revisao geral
*/
import java.awt.*;
import java.util.LinkedList;
import com.ks2002br.frameworks.*;
public class Bullet extends GameObject {
private GameController gc;
public Bullet(float x, float y, int velX, long timer, GameController gc, ObjectId id) {
super(x, y, id);
this.spdX = velX;
this.timer = timer;
this.gc = gc;
}
@Override
public void tick(LinkedList<GameObject> obj) {
x += spdX;
isCollision();
}
private void isCollision() {
for (int i = 0; i < gc.obj.size(); i++) {
GameObject objTemp = gc.obj.get(i);
if (objTemp.getId() == ObjectId.BLOCO) {
if (getBounds().intersects(objTemp.getBounds())) {
gc.removeObj(this);
}
}
if (objTemp.getId() == ObjectId.ENEMY) {
if (getBounds().intersects(objTemp.getBounds())) {
gc.removeObj(gc.obj.get(i));
gc.removeObj(this);
}
}
}
}
@Override
public void render(Graphics g) {
g.setColor(new Color(255, 0, 0));
g.fillOval((int) x, (int) y, 16, 16);
}
@Override
public Rectangle getBounds() {
return new Rectangle((int) x, (int) y, 16, 16);
}
}