-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProjectile.pde
46 lines (41 loc) · 1.19 KB
/
Projectile.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 Projectile {
PVector myPosition, myVelocity, mySpeed;
float myTheta, velocity, myXEnd, myYEnd;
boolean visible = true;
boolean toRemove;
Projectile (PVector position, float velocity, float theta, float xEnd, float yEnd) {
myPosition = position;
myVelocity = new PVector(15, 15);
myTheta = theta;
this.velocity = velocity;
myXEnd = xEnd;
myYEnd = yEnd;
// math for angle of projectile
if (mouseX >= truck.gunX()) {
myVelocity.y = ((float) ((velocity) * (Math.sin(Math.abs((myTheta))))));
myVelocity.x = ((float) Math.sqrt((((velocity)*(velocity))-((myVelocity.y)*(myVelocity.y)))));
if (mouseY < truck.getY()) {
myVelocity.y*=-1;
}
} else {
myVelocity.y = ((float) ((velocity) * (Math.sin(Math.abs((myTheta))))));
myVelocity.x = ((float) Math.sqrt((((velocity)*(velocity))-((myVelocity.y)*(myVelocity.y)))))*-1;
}
}
void setToRemove(boolean tr) {
toRemove = tr;
}
boolean getToRemove() {
return toRemove;
}
float getX() {
return myPosition.x;
}
float getY() {
return myPosition.y;
}
void update() {
myPosition.x += myVelocity.x;
myPosition.y += myVelocity.y;
}
}