-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathshoot.lua
203 lines (151 loc) · 4.68 KB
/
shoot.lua
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
----------------------------------------------------------------------------------------------------
-- Code related to shooting bullets
----------------------------------------------------------------------------------------------------
-- this function sets the initial velocities for each bullet
-- it doesn't shoot - it relies on the "drawShot" function to continue
--
-- f - force additional to player's chosen force,
-- t - theta (angle) additional to player's chosen angle,
-- bulletIndex - index of the bullet
function setBulletInitialVelocity(f, t, bulletIndex)
if turn == 1 then
-- preturb it by a bit for jitter so it's not the same
f = player1.force + f -- + math.random() * 2
t = player1.angle + t -- + math.random() * 10
elseif turn == 2 then
f = player2.force + f -- + math.random() * 2
t = player2.angle + t -- + math.random() * 10
end
-- *** REDUCE THE FORCE BY some amount and reduce weight of planets by some amount
-- *** this will make the resolution of the shot higher!!?! ***
f = f / 2
-- calculate the x and y components of shot for initial force
allBullets[bulletIndex].vx = f * math.cos(0.0174533 * t)
allBullets[bulletIndex].vy = f * math.sin(0.0174533 * t)
end
-- to split a bullet (special bullet type allows for splitting while in air)
function split(x, y)
love.graphics.ellipse('line', x, y, 10, 10)
-- print("SPLIT @ ", x, y)
temp = 0
for i = 1, 3 do
temp = numOfBullets + i
allBullets[i] = {}
allBullets[temp].x = x
allBullets[temp].y = y
end
numOfBullets = numOfBullets + 3
temp = 0
for i = 1, 3 do
temp = numOfBullets - 3 + i
setBulletInitialVelocity(0.01, math.random(0, 360), temp)
end
end
function shotType1()
-- shoot only one bullet
numOfBullets = 1
for i = 1, numOfBullets do
allBullets[i] = {}
allBullets[i].x = shipX
allBullets[i].y = shipY
setBulletInitialVelocity(1, 1, i)
end
end
function shotType2()
-- shoot three bullets
numOfBullets = 30
for i = 1, numOfBullets do
allBullets[i] = {}
allBullets[i].x = shipX
allBullets[i].y = shipY
setBulletInitialVelocity(1, 1, i)
end
end
function shotType3()
-- shoot five bullets
numOfBullets = 5
for i = 1, numOfBullets do
allBullets[i] = {}
allBullets[i].x = shipX
allBullets[i].y = shipY
setBulletInitialVelocity(1, 1, i)
end
end
function shotType4()
-- shoot only one bullet
numOfBullets = 1
for i = 1, numOfBullets do
allBullets[i] = {}
allBullets[i].x = shipX
allBullets[i].y = shipY
setBulletInitialVelocity(1, 1, i)
end
end
function playerPressedShootButton()
dimTrails()
print("Whose is shooting? Player ", turn)
-- origin of the shot set to player's location
if turn == 1 then
shipX = player1.x
shipY = player1.y
player1.lastAngle = player1.angle
player1.lastForce = player1.force
elseif turn == 2 then
shipX = player2.x
shipY = player2.y
player2.lastAngle = player2.angle
player2.lastForce = player2.force
end
allBullets = {} -- reset to empty
-- make bullet benign
benign = 0
if bulType == 1 then
shotType1()
elseif bulType == 2 then
shotType2()
elseif bulType == 3 then
shotType3()
elseif bulType == 4 then
shotType4()
else
for i = 1, numOfBullets do
allBullets[i] = {}
allBullets[i].x = shipX
allBullets[i].y = shipY
setBulletInitialVelocity(2, 2, i)
end
end
love.graphics.setCanvas(canvas)
drawUI()
love.graphics.setCanvas()
shotInProgress = true
end
-- blow up a location in a pretty way
function explode(x, y)
temp = 0
love.graphics.setCanvas(canvas)
for i = 1, 10 do
temp = numOfBullets + i
allBullets[temp] = {}
randX = math.random(-20, 20)
randY = math.random(-20, 20)
radius = math.random(5, 15)
setExplodyColor()
love.graphics.ellipse('fill', x + randX, y + randY, radius, radius)
allBullets[temp].x = x + randX
allBullets[temp].y = y + randY
end
love.graphics.setCanvas()
numOfBullets = numOfBullets + 10
temp = 0
for i = 1, 10 do
temp = numOfBullets - 10 + i
setBulletInitialVelocity(1, math.random(0, 360), temp)
end
end
function setExplodyColor()
-- red 1 0 0
-- orange 1 0.5 0
-- yellow 1 1 0
love.graphics.setColor(1, math.random(0, 255) / 255, 0, 1)
end