-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSpit.pde
62 lines (54 loc) · 1.78 KB
/
Spit.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
class Spit extends Projectile {
float offset;
Spit(PVector position, float velocity, float theta, float xEnd, float yEnd) {
super(position, velocity, theta, xEnd, yEnd);
myPosition = position;
myVelocity = new PVector(20, 20);
offset = theta;
for (Emu e : emus) {
if (myXEnd > e.getX()) {
myTheta = atan((e.getY() - myYEnd)/(e.getX() - myXEnd));
} else {
myTheta = (atan((myYEnd-e.getY())/(myXEnd - e.getX()))) + radians(180);
}
myTheta+=radians(offset*6);
}
this.velocity = velocity;
myXEnd = xEnd;
myYEnd = yEnd;
if (xEnd >= myPosition.x) {
myVelocity.y = ((float) ((velocity) * (Math.sin(Math.abs((myTheta))))));
myVelocity.x = ((float) Math.sqrt((((velocity)*(velocity))-((myVelocity.y)*(myVelocity.y)))));
if (yEnd < myPosition.y) {
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;
}
}
// truck.get = emu position
// myX = end location
float geTheta() {
for (Emu e : emus) {
if (myXEnd > e.getX()) {
myTheta = atan((e.getY() - myYEnd)/(e.getX() - myXEnd));
} else {
myTheta = (atan((myYEnd-e.getY())/(myXEnd - e.getX()))) + radians(180);
}
}
return myTheta + offset*3;
}
void update() {
super.update();
pushMatrix();
translate(myPosition.x, myPosition.y);
rotate(myTheta);
image(spitImage, 0, 0);
popMatrix();
if (myPosition.x > truck.getX() - 100 && myPosition.x < truck.getX() + 100 && myPosition.y > truck.getY() - 100 && myPosition.y < truck.getY() + 100) {
truck.reduceHP(0.04);
toRemove = true;
}
}
}