-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBullet.pde
More file actions
98 lines (83 loc) · 2.11 KB
/
Bullet.pde
File metadata and controls
98 lines (83 loc) · 2.11 KB
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import java.lang.Math;
public class Bullet{
double x, y, angle, size;
int count;
boolean owner;
Vector velocity;
final double PI = 3.14159265359;
Locals locals;
public Bullet(double x, double y, double angle, Locals l){
locals = l;
this.x = x;
this.y = y;
this.angle = angle - PI/2;
this.size = 5;
this.count = 0;
this.owner = true;
this.velocity = Vector.fromAngle(this.angle);
this.velocity.mult(8);
}
public void travel(){
x += velocity.x;
y += velocity.y;
}
public void setOwner(boolean b){
owner = b;
}
public boolean isOwner(){
return owner;
}
public boolean bound(){
if (x + size < 0){
x = width + size;
}
else if (x - size > width){
x = 0 - size;
}
if (y + size < 0){
y = height + size;
}
else if (y - size > height){
y = 0 - size;
}
if(count > 900){
return true;
}
else{
count += 8;
return false;
}
}
public void checkHit(){
for (Asteroid a : locals.asteroids){
double distance = dist(a.getX(), a.getY(), x, y);
if (distance < a.getSize()/2 + size/2){
locals.player.addScore(a.getScore());
a.explode();
count = 1000;
break;
}
}
}
public void show(){
pushMatrix();
ellipseMode(CENTER);
translate((float) x, (float) y);
travel();
noStroke();
fill(255);
ellipse(0, 0, (float) size, (float) size);
popMatrix();
if (owner)
checkHit();
}
public double getX(){
return x;
}
public double getY(){
return y;
}
private double dist(double x1, double y1, double x2, double y2){
return Math.sqrt(Math.pow(x2-x1, 2) + Math.pow(y2-y1, 2));
}
}