-
Notifications
You must be signed in to change notification settings - Fork 0
/
Laser.pde
136 lines (107 loc) · 2.82 KB
/
Laser.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
public class Laser
{
float x;
float y;
float w, h;
PVector laserEnd;
PVector velocity;
float size;
int distance;
ArrayList<Line> lineList = new ArrayList<Line>();
int range = 500;
Tank firedTank;
AudioPlayer fireSound;
public Laser(float centerX, float centerY, float firedAngle, float w, float h, AudioPlayer fireSound2, Tank firedTank2)
{
size=5;
float radAngle = firedAngle/360*TWO_PI;
laserEnd = new PVector(centerX+cos(radAngle)*(w/2.2), centerY+sin(radAngle)*(w/2.2));
PVector start = new PVector(centerX+cos(radAngle)*(w/2.2), centerY+sin(radAngle)*(w/2.2));
velocity = new PVector(cos(radAngle)*(BULLETSPEED*.5), sin(radAngle)*BULLETSPEED*.5);
distance = 0;
//laserEnd.add(velocity);
fireSound = fireSound2;
firedTank = firedTank2;
while (distance < range)
{
while (!laserCollision(this))
{
lineList.add(new Line(start.x, start.y, laserEnd.x, laserEnd.y));
if (laserTankCollision(this, false))
{
distance = range+100;
lineList.remove(lineList.size()-1);
break;
}
else
{
lineList.remove(lineList.size()-1);
}
laserEnd.add(velocity);
if ((distance + dist(start.x, start.y, laserEnd.x, laserEnd.y) > range))
{
break;
}
}
lineList.add(new Line(start.x, start.y, laserEnd.x, laserEnd.y));
distance += dist(start.x, start.y, laserEnd.x, laserEnd.y);
x=laserEnd.x;
y=laserEnd.y;
start.x = x;
start.y = y;
if (lineList.size() > 20)
break;
}
}
void displayFire(String team)
{
for (Line line: lineList)
{
line.displayLaser(team);
}
}
void fire(String team)
{
displayFire(team);
playFireSound();
laserTankCollision(this, true);
}
void display(String team)
{
for (Line line: lineList)
{
//requires Dashed Lines from tools->manage toosl->library
strokeWeight(1.5);
if (team == "Red")
{
stroke(#FF0000);
}
else if (team == "Green")
{
stroke(#00FF00);
}
else if (team == "Orange")
{
stroke(#ED8A05);
}
else
{
stroke(#0000FF);
}
dash.line(line.x1+OFFSETX, line.y1+OFFSETY, line.x2+OFFSETX, line.y2+OFFSETY);
stroke(#000000);
}
}
int getColumn()
{
return (int)(laserEnd.x/CELL_SIZE);
}
int getRow()
{
return (int)(laserEnd.y/CELL_SIZE);
}
void playFireSound()
{
fireSound.play();
}
}