-
Notifications
You must be signed in to change notification settings - Fork 0
/
shot_data.lua
424 lines (378 loc) · 12 KB
/
shot_data.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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
local shot_data = {}
function shot_data.spawn(class, x, y, dx, dy, owner, faction)
local pid = idcounter.get_id("shot")
shots[pid] = shot:new({
id = pid,
dx = dx, dy = dy, owner = owner, faction = faction
})
for i, v in pairs(shot_data[class]) do
shots[pid][i] = v
end
shots[pid].x, shots[pid].y = x, y
shots[pid].birth_time = ctime
if shots[pid]["duration_variance"] then
shots[pid]["duration"] = shots[pid]["duration"] + shots[pid]["duration_variance"] * love.math.random()
end
return pid
end
shot_data["pellet"] =
{
class = "pellet", name = "Machine Gun Bullet",
damage = 20,
color = color.ltblue,
sprite = "bullet",
half_w = 2, half_h = 2,
bounce_restitution = 0.8,
collides_with_terrain = true, collides_with_actors = true,
collide = function(self, hit, mx, my, mt, nx, ny)
if hit[1] == "block" then
if mainmap:block_at(hit[2], hit[3]) == "void" then
self:die(true)
else
-- reflect off, maybe
-- chance is based on the angle of incidence
local dot = self.dy * ny + self.dx * nx
if (love.math.random() * math.pi) < 2 * math.abs(math.acos(dot / mymath.vector_length(self.dx, self.dy)) - math.pi) - 0.2 then
self.dx = (self.dx - 2 * dot * nx) * self.bounce_restitution
self.dy = (self.dy - 2 * dot * ny) * self.bounce_restitution
else
mainmap:hurt_block(hit[2], hit[3], self.damage)
self:die()
audio.play('hit2')
end
end
elseif hit[1] == "enemy" then
enemies[hit[2]]:hurt(self.damage)
self:die()
audio.play('hit1')
camera.shake(10)
elseif hit[1] == "player" then
player:hurt(self.damage)
self:die()
audio.play('hit1')
camera.shake(10)
end
end,
explode = function(self)
spark_data.spawn("tripop", self.color, self.x, self.y,
0, 0, math.pi * love.math.random(0,1) / 2, -1 + 2 * love.math.random(0,1), -1 + 2 * love.math.random(0,1))
for i=1,5 do
angle = love.math.random() * math.pi * 2
v = 200 + 200 * love.math.random()
spark_data.spawn("spark_s", self.color, self.x, self.y,
v * math.cos(angle), v * math.sin(angle), 0, 1, 1)
end
end,
facing = function(self)
return math.atan2(self.dy, self.dx)
end
}
shot_data["plasma"] =
{
class = "plasma", name = "Plasma Sphere",
damage = 240,
color = color.yellow,
sprite = "plasma",
half_w = 6, half_h = 6,
gravity_multiplier = 0.6,
bounce_restitution = 0.8,
collides_with_terrain = true, collides_with_actors = true,
collide = function(self, hit, mx, my, mt, nx, ny)
if hit[1] == "block" then
if mainmap:block_at(hit[2], hit[3]) == "void" then
self:die(true)
else
-- reflect off
local dot = self.dy * ny + self.dx * nx
self.dx = (self.dx - 2 * dot * nx) * self.bounce_restitution
self.dy = (self.dy - 2 * dot * ny) * self.bounce_restitution
if not self.duration then
self.duration = ctime - self.birth_time + 1
end
end
elseif hit[1] == "enemy" then
self:die()
elseif hit[1] == "player" then
self:die()
end
end,
explode = function(self)
local dist
if self.faction == "player" then
for j,z in pairs(enemies) do
dist = mymath.dist(z.x, z.y, self.x, self.y)
if dist < 128 then
z:hurt(self.damage * (128 - dist) / 128)
end
end
elseif self.faction == "enemy" then
dist = mymath.dist(player.x, player.y, self.x, self.y)
if dist < 128 then
player:hurt(self.damage * (128 - dist) / 128)
end
end
for i = map.grid_at_pos(self.x) - 5, map.grid_at_pos(self.x) + 5 do
for j = map.grid_at_pos(self.y) - 5, map.grid_at_pos(self.y) + 5 do
dist = mymath.dist(img.tile_size * (i + 0.5), img.tile_size * (j + 0.5), self.x, self.y)
if dist < 128 then
mainmap:hurt_block(i, j, self.damage * (128 - dist) / 128)
end
end
end
spark_data.spawn("explosion", self.color, self.x, self.y,
0, 0, math.pi * love.math.random(0,1) / 2, -1 + 2 * love.math.random(0,1), -1 + 2 * love.math.random(0,1))
for i=1,14 do
angle = love.math.random() * math.pi * 2
v = 100 + 500 * love.math.random()
spark_data.spawn("spark_s", self.color, self.x, self.y,
v * math.cos(angle), v * math.sin(angle), 0, 1, 1)
end
for i=1,7 do
angle = love.math.random() * math.pi * 2
v = 80 + 400 * love.math.random()
spark_data.spawn("spark_m", self.color, self.x, self.y,
v * math.cos(angle), v * math.sin(angle), 0, 1, 1)
end
for i=1,4 do
angle = love.math.random() * math.pi * 2
v = 50 + 300 * love.math.random()
spark_data.spawn("spark_l", self.color, self.x, self.y,
v * math.cos(angle), v * math.sin(angle), 0, 1, 1)
end
audio.play('explosion')
camera.shake(40)
end,
facing = function(self)
return math.atan2(self.dy, self.dx)
end
}
shot_data["buckshot"] =
{
class = "buckshot", name = "Buckshot Pellet",
damage = 10, duration = 0.2, duration_variance = 0.2, silent_timeout = true,
color = color.rouge,
sprite = "bullet",
half_w = 2, half_h = 2,
collides_with_terrain = false, collides_with_actors = true,
collide = function(self, hit, mx, my, mt, nx, ny)
if hit[1] == "block" then
if mainmap:block_at(hit[2], hit[3]) == "void" then
self:die(true)
else
mainmap:hurt_block(hit[2], hit[3], self.damage)
self:die()
audio.play('hit2')
end
elseif hit[1] == "enemy" then
enemies[hit[2]]:hurt(self.damage)
self:die()
audio.play('hit1')
camera.shake(10)
elseif hit[1] == "player" then
player:hurt(self.damage)
self:die()
audio.play('hit1')
camera.shake(10)
end
end,
explode = function(self)
spark_data.spawn("tripop", self.color, self.x, self.y,
0, 0, math.pi * love.math.random(0,1) / 2, -1 + 2 * love.math.random(0,1), -1 + 2 * love.math.random(0,1))
for i=1,5 do
angle = love.math.random() * math.pi * 2
v = 200 + 200 * love.math.random()
spark_data.spawn("spark_s", self.color, self.x, self.y,
v * math.cos(angle), v * math.sin(angle), 0, 1, 1)
end
end,
facing = function(self)
return math.atan2(self.dy, self.dx)
end
}
shot_data["c4"] =
{
class = "c4", name = "Remote Charge",
damage = 240, silent_timeout = false,
color = color.orange,
sprite = "c4",
half_w = 2, half_h = 2,
gravity_multiplier = 0.6,
collides_with_terrain = true, collides_with_actors = true,
f = function(self)
if self.attach_point then
if self.attach_point[1] == "block" then
if not mainmap:grid_has_collision(self.attach_point.i, self.attach_point.j) then
-- block is gone, fall off
local angle = love.math.random() * math.pi * 2
local v = 20 + 100 * love.math.random()
self.dx = v * math.cos(angle)
self.dy = v * math.sin(angle)
self.gravity_multiplier = 0.6
self.collides_with_actors = true
self.collides_with_terrain = true
self.attach_point = nil
end
elseif self.attach_point[1] == "enemy" then
if not enemies[self.attach_point.id] then
-- enemy is gone, fall off
local angle = love.math.random() * math.pi * 2
local v = 20 + 100 * love.math.random()
self.dx = v * math.cos(angle)
self.dy = v * math.sin(angle)
self.gravity_multiplier = 0.6
self.collides_with_actors = true
self.collides_with_terrain = true
self.attach_point = nil
else
self.x = enemies[self.attach_point.id].x + self.attach_point.x_offset
self.y = enemies[self.attach_point.id].y + self.attach_point.y_offset
end
end
end
end,
collide = function(self, hit, mx, my, mt, nx, ny)
if hit[1] == "block" then
if mainmap:block_at(hit[2], hit[3]) == "void" then
self:die(true)
else
-- attach
self.attach_point = {"block", i = hit[2], j = hit[3], facing = ((ctime - self.birth_time) % 1) * 2 * math.pi}
self.dx = 0
self.dy = 0
self.gravity_multiplier = nil
self.collides_with_actors = false
self.collides_with_terrain = false
end
elseif hit[1] == "enemy" then
-- attach
self.attach_point = {"enemy", id = hit[2],
x_offset = self.x - enemies[hit[2]].x, y_offset = self.y - enemies[hit[2]].y,
facing = ((ctime - self.birth_time) % 1) * 2 * math.pi}
self.dx = 0
self.dy = 0
self.gravity_multiplier = nil
self.collides_with_actors = false
self.collides_with_terrain = false
elseif hit[1] == "player" then
-- anh, fuck it
self:die()
end
end,
explode = function(self)
local dist
if self.faction == "player" then
for j,z in pairs(enemies) do
dist = mymath.dist(z.x, z.y, self.x, self.y)
if dist < 128 then
z:hurt(self.damage * (128 - dist) / 128)
end
end
elseif self.faction == "enemy" then
dist = mymath.dist(player.x, player.y, self.x, self.y)
if dist < 128 then
player:hurt(self.damage * (128 - dist) / 128)
end
end
for i = map.grid_at_pos(self.x) - 5, map.grid_at_pos(self.x) + 5 do
for j = map.grid_at_pos(self.y) - 5, map.grid_at_pos(self.y) + 5 do
dist = mymath.dist(img.tile_size * (i + 0.5), img.tile_size * (j + 0.5), self.x, self.y)
if dist < 128 then
mainmap:hurt_block(i, j, self.damage * (128 - dist) / 128)
end
end
end
spark_data.spawn("explosion", self.color, self.x, self.y,
0, 0, math.pi * love.math.random(0,1) / 2, -1 + 2 * love.math.random(0,1), -1 + 2 * love.math.random(0,1))
for i=1,14 do
angle = love.math.random() * math.pi * 2
v = 100 + 500 * love.math.random()
spark_data.spawn("spark_s", self.color, self.x, self.y,
v * math.cos(angle), v * math.sin(angle), 0, 1, 1)
end
for i=1,7 do
angle = love.math.random() * math.pi * 2
v = 80 + 400 * love.math.random()
spark_data.spawn("spark_m", self.color, self.x, self.y,
v * math.cos(angle), v * math.sin(angle), 0, 1, 1)
end
for i=1,4 do
angle = love.math.random() * math.pi * 2
v = 50 + 300 * love.math.random()
spark_data.spawn("spark_l", self.color, self.x, self.y,
v * math.cos(angle), v * math.sin(angle), 0, 1, 1)
end
audio.play('explosion')
camera.shake(40)
end,
facing = function(self)
if self.attach_point then
return self.attach_point.facing
else
return ((ctime - self.birth_time) % 1) * 2 * math.pi
end
end
}
shot_data["missile"] =
{
class = "missile", name = "Homing Missile",
damage = 40,
color = color.green,
sprite = "missile",
half_w = 3, half_h = 3,
collides_with_terrain = true, collides_with_actors = true,
homing_coefficient = 4, cruise_speed = 1000,
f = function(self, dt)
if ctime - self.birth_time > 0.2 then
-- turn slowly towards the target
local facing = math.atan2(self.dy, self.dx)
local theta = 0
if self.target_id and enemies[self.target_id] then
theta = mymath.angle_difference(facing, math.atan2(enemies[self.target_id].y - self.y, enemies[self.target_id].x - self.x))
end
local new_speed = mymath.vector_length(self.dx, self.dy) * (1 - dt) + self.cruise_speed * (dt)
self.dx = new_speed * math.cos(facing + theta * (math.min(1, self.homing_coefficient * dt)))
self.dy = new_speed * math.sin(facing + theta * (math.min(1, self.homing_coefficient * dt)))
if love.math.random() < 12 * dt then
local angle = math.atan2(self.dy, self.dx) + math.pi
v = 200 + 200 * love.math.random()
spark_data.spawn("spark_s", self.color, self.x, self.y,
v * math.cos(angle), v * math.sin(angle), 0, 1, 1)
end
end
end,
collide = function(self, hit, mx, my, mt, nx, ny)
if hit[1] == "block" then
if mainmap:block_at(hit[2], hit[3]) == "void" then
self:die(true)
else
mainmap:hurt_block(hit[2], hit[3], self.damage)
self:die()
audio.play('hit2')
end
elseif hit[1] == "enemy" then
enemies[hit[2]]:hurt(self.damage)
self:die()
audio.play('hit1')
camera.shake(10)
elseif hit[1] == "player" then
player:hurt(self.damage)
self:die()
audio.play('hit1')
camera.shake(10)
end
end,
explode = function(self)
spark_data.spawn("tripop", self.color, self.x, self.y,
0, 0, math.pi * love.math.random(0,1) / 2, -1 + 2 * love.math.random(0,1), -1 + 2 * love.math.random(0,1))
for i=1,5 do
angle = love.math.random() * math.pi * 2
v = 200 + 200 * love.math.random()
spark_data.spawn("spark_s", self.color, self.x, self.y,
v * math.cos(angle), v * math.sin(angle), 0, 1, 1)
end
end,
facing = function(self)
return math.atan2(self.dy, self.dx)
end
}
return shot_data