-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBullet.pde
58 lines (52 loc) · 1.66 KB
/
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
49
50
51
52
53
54
55
56
57
58
class Bullet {
PVector myPosition, myVelocity, mySpeed;
float myTheta, velocity, myXEnd, myYEnd, myDamage;
boolean myAiming;
boolean visible = true;
Bullet (PVector position, float velocity, float theta, float xEnd, float yEnd, boolean aiming, float damage) {
myPosition = position;
myVelocity = new PVector(15, 15);
this.velocity = velocity;
myXEnd = xEnd;
myYEnd = yEnd;
myAiming = aiming;
myDamage = damage;
// checks if the gun is aimed, adjusts the exit angle accordingly
if (myAiming) {
myTheta = theta + radians(random(-gunInnac, gunInnac));
} else {
myTheta = theta+radians(random(-2, 2) + random(-gunInnac, gunInnac));
}
// math to find angle the bullet will travl at
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;
}
}
float getDamage() {
return myDamage;
}
float getX() {
return myPosition.x;
}
float getY() {
return myPosition.y;
}
void drawBullet() {
pushMatrix();
myPosition.x += myVelocity.x;
myPosition.y += myVelocity.y;
translate(myPosition.x, myPosition.y);
rotate((myTheta));
rectMode(CENTER);
fill(0);
rect(80, 0, 5, 3);
popMatrix();
}
}