-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathweapons.lua
55 lines (42 loc) · 1.33 KB
/
weapons.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
local weapons = {}
function weapons.create(kind)
return {kind = kind, ready_time = 0}
end
local pos, controls, kind
function weapons.update()
for k,v in pairs(c_weapons) do
pos = c_positions[k]
controls = c_controls[k]
kind = weapons.kinds[v[1].kind]
if kind.fire_pressed and controls.fire_pressed then
kind.fire_pressed(v[1], pos.x, pos.y, controls.aim_x, controls.aim_y)
end
if kind.fire_down and controls.fire_down then
kind.fire_down(v[1], pos.x, pos.y, controls.aim_x, controls.aim_y)
end
if kind.altfire_pressed and controls.altfire_pressed then
kind.altfire_pressed(v[1], pos.x, pos.y, controls.aim_x, controls.aim_y)
end
if kind.altfire_down and controls.altfire_down then
kind.altfire_down(v[1], pos.x, pos.y, controls.aim_x, controls.aim_y)
end
end
end
--
weapons.kinds = {}
weapons.kinds["assault"] = {
-- fire_pressed = function(start_x, start_y, aim_x, aim_y)
-- end,
fire_down = function(weapon, start_x, start_y, aim_x, aim_y)
if weapon.ready_time < game_frame then
dx, dy = mymath.normalize(aim_x - start_x, aim_y - start_y)
ecs.spawn_shot("pellet", start_x, start_y, dx, dy, 20)
weapon.ready_time = game_frame + 8
end
end,
-- altfire_pressed = function(start_x, start_y, aim_x, aim_y)
-- end,
-- altfire_down = function(start_x, start_y, aim_x, aim_y)
-- end,
}
return weapons