-
Notifications
You must be signed in to change notification settings - Fork 0
/
Beam.pde
145 lines (136 loc) · 3.96 KB
/
Beam.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
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
import java.util.ArrayList;
import java.util.*;
public class Beam
{
float angle;
Line line;
Tank targetTank;
Tank firedTank;
String team = "";
float w, h;
PImage img;
float time;
Float bezierPoints[];
Line bezier2;
AudioPlayer fireSound;
public Beam(float centerX, float centerY, float w2, float h2, float firedAngle, Tank firedTank2)
{
w = w2;
h = h2;
firedTank = firedTank2;
angle = firedAngle;
float radAngle = angle/360*TWO_PI;
line = new Line(centerX+cos(radAngle)*(w/2), centerY+sin(radAngle)*(w/2), centerX+cos(radAngle)*(1400), centerY+sin(radAngle)*(1400));
imageMode(CENTER);
team = firedTank.team;
img = loadImage("Beam/" + team + " Beam.png");
fireSound = minim.loadFile("Sounds/Death Ray.mp3");
}
public void display(float time2)
{
time = time2;
time = 3.5*30-time;
if (time >45)
{
noFill();
if (team == "Blue")
{
stroke(27, 30, 247);
} else if (team == "Green")
{
stroke(57, 240, 57);
}
else if (team == "Orange")
{
stroke(237,138,5);
}
else
{
stroke(204, 0, 0);
}
strokeWeight(7);
if (bezier2 != null)
{
bezier2.display2();
} else
{
line.display2();
}
if (bezierPoints != null)
{
bezier(bezierPoints[0]+OFFSETX, bezierPoints[1]+OFFSETY, bezierPoints[2]+OFFSETX, bezierPoints[3]+OFFSETY, bezierPoints[4]+OFFSETX, bezierPoints[5]+OFFSETY, bezierPoints[6]+OFFSETX, bezierPoints[7]+OFFSETY);
}
for (int i = 0; i < 100; i+=7)
{
float t = i/100.0;
float x, y, tx, ty, rand;
if (bezierPoints != null)
{
x = bezierPoint(bezierPoints[0], bezierPoints[2], bezierPoints[4], bezierPoints[6], t);
y = bezierPoint(bezierPoints[1], bezierPoints[3], bezierPoints[5], bezierPoints[7], t);
tx = bezierTangent(bezierPoints[0], bezierPoints[2], bezierPoints[4], bezierPoints[6], t);
ty = bezierTangent(bezierPoints[1], bezierPoints[3], bezierPoints[5], bezierPoints[7], t);
rand = (int)random(0, 3);
if (rand != 0)
{
pushMatrix();
float rad_angle = atan2(ty, tx);
rad_angle += PI;
translate(x, y);
rotate(rad_angle);
float r = sqrt(OFFSETX*OFFSETX+OFFSETY*OFFSETY);
float theta = atan(OFFSETY/OFFSETX)-rad_angle;
translate(r*cos(theta), r*sin(theta));
image(img, 0, 0);
popMatrix();
}
}
}
for (int i = 0; i < 100; i+=2)
{
float t = i/100.0;
float x, y, tx, ty, rand;
if (bezier2 != null)
{
x = bezier2.lerpX(t);
y = bezier2.lerpY(t);
rand = (int)random(0, 3);
if (rand == 0)
{
pushMatrix();
float rad_angle = bezier2.radAngle();
translate(x, y);
rotate(rad_angle);
float r = sqrt(OFFSETX*OFFSETX+OFFSETY*OFFSETY);
float theta = atan(OFFSETY/OFFSETX)-rad_angle;
translate(r*cos(theta), r*sin(theta));
image(img, 0, 0);
popMatrix();
}
} else
{
x = line.lerpX(t);
y = line.lerpY(t);
rand = (int)random(0, 3);
if (rand == 0)
{
pushMatrix();
float rad_angle = line.radAngle();
translate(x, y);
rotate(rad_angle);
float r = sqrt(OFFSETX*OFFSETX+OFFSETY*OFFSETY);
float theta = atan(OFFSETY/OFFSETX)-rad_angle;
translate(r*cos(theta), r*sin(theta));
image(img, 0, 0);
popMatrix();
}
}
}
}
strokeWeight(1);
}
void playFireSound()
{
fireSound.play();
}
}