-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBullet.pde
48 lines (42 loc) · 975 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
47
48
class Bullet {
PVector pos, vel;
float size, angle;
color col;
Bullet(PVector loc, float ang) {
pos = loc;
vel = PVector.fromAngle(ang-PI/2).mult(18);
size = ship.space/8;
col = color(0, 255, 0);
angle = ang;
}
void setPos(PVector pos) {
this.pos = pos;
}
void edges() {
if (pos.x > width+size) pos.x = -size;
if (pos.x < -size) pos.x = width+size;
if (pos.y < -size) pos.y = height+size;
if (pos.y > height+size) pos.y = -size;
}
boolean outOfBounds() {
return (pos.x < 0 || pos.x > width || pos.y < 0 || pos.y > height);
}
boolean collideWithAsteriod(Asteriod a) {
return (dist(pos.x, pos.y, a.pos.x, a.pos.y) < a.avgRadius);
}
void update() {
pos.add(vel);
}
void show() {
pushMatrix();
translate(pos.x, pos.y);
rotate(angle);
pushStyle();
noStroke();
fill(col);
ellipseMode(RADIUS);
ellipse(0, 0, size, size);
popStyle();
popMatrix();
}
}