-
Notifications
You must be signed in to change notification settings - Fork 0
/
Bullet.pde
43 lines (37 loc) · 794 Bytes
/
Bullet.pde
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
class Bullet extends GameObject
{
float timeToLive;
float theta;
float alive;
float speed = 3;
boolean active;
Bullet(float x, float y, float theta, float size, float timeToLive)
{
pos = new PVector(x, y);
forward = new PVector(0,1);
this.theta = theta;
this.size = size;
this.timeToLive = timeToLive;
this.alive = 0;
this.active = true;
}
void render()
{
if(active == true)
{
pushMatrix();
translate((pos.x+(forward.x*30))-5, pos.y+(forward.y*30));
rotate(theta);
fill(156, 156, 156);
rect(0, 0, 4, 6);
popMatrix();
update();
}
}
void update()
{
forward.x = -sin(theta);
forward.y = cos(theta);
pos.add(PVector.mult(PVector.mult(forward, speed), 5));
}
}