-
Notifications
You must be signed in to change notification settings - Fork 69
/
Copy pathBullet.java
66 lines (57 loc) · 1.44 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
60
61
62
63
64
65
66
package ie.dit;
import processing.core.PVector;
public class Bullet extends GameObject
{
public Bullet(YASC yasc, float x, float y, float rotation)
{
super(yasc, x, y, rotation, 5);
}
public void render()
{
yasc.pushMatrix();
yasc.translate(pos.x, pos.y);
yasc.rotate(rotation);
yasc.line(0, -5, 0, 5);
yasc.popMatrix();
}
public void checkCollisions()
{
float dist = PVector.dist(yasc.aiShip.getPos(), pos);
if (dist < yasc.aiShip.size / 2)
{
yasc.aiShip.setHealth(yasc.aiShip.getHealth() - 1);
yasc.gameObjects.remove(this);
}
}
public void update()
{
// static methods on the Math class
forward.x = (float)Math.sin(rotation);
forward.y = - (float)Math.cos(rotation);
// pos += forward * speed
pos.add(PVector.mult(forward, speed));
if (pos.x < 0)
{
pos.x = yasc.width;
}
if (pos.x > yasc.width)
{
pos.x = 0;
}
if (pos.y < 0)
{
pos.y = yasc.height;
}
if (pos.y > yasc.height)
{
pos.y = 0;
}
alive += yasc.timeDelta;
if (alive >= 5.0)
{
yasc.gameObjects.remove(this);
}
checkCollisions();
}
float alive;
}