-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBullet.pde
46 lines (42 loc) · 933 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
44
45
46
class Bullet {
float baseSpeed = 10;
float baseLifetime = 60;
//State
PVector position;
float angle;
float remainingLifetime;
boolean alive = true;
float speed;
Bullet(float x, float y, float angle) {
position = new PVector(x, y);
this.angle=angle;
remainingLifetime = baseLifetime;
speed = baseSpeed;
}
void update() {
remainingLifetime--;
if (remainingLifetime<0){
alive=false;
}
position.x += speed*cos(angle);
position.y += speed*sin(angle);
position.x = position.x%width;
position.y = position.y%height;
if (position.x < 0) {
position.x = width + position.x;
}
if (position.y < 0) {
position.y = height + position.y;
}
}
void drawToScreen() {
if (alive){
pushMatrix();
strokeWeight(2);
stroke(#EAFEFF);
fill(255);
ellipse(position.x, position.y, 2, 2);
popMatrix();
}
}
}