-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpattern.lua
More file actions
91 lines (82 loc) · 2.97 KB
/
pattern.lua
File metadata and controls
91 lines (82 loc) · 2.97 KB
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
-- bullet fire pattern functions
-- enemy bullet speed; constant for now but likely to be dynamic in future
local BULLET_SPEED = 120 -- px/s
local M = {}
-- inserts a bullet into the enemy's table at its position with the passed in
-- velocity
local function shoot(e, vel, kind)
table.insert(e.bullets, Bullet.fire(e.x, e.y, vel, kind))
end
function M.fire_aimed(e, player, params)
local speed = params.speed or BULLET_SPEED
local center = Player.center(player)
local a = math.atan(center.y - e.y, center.x - e.x)
local vel = { x = math.cos(a) * speed, y = math.sin(a) * speed }
local kind = params.kind or Bullet.kind.ENEMY_DEFAULT
shoot(e, vel, kind)
end
function M.fire_fan(e, player, params)
local speed = params.speed or BULLET_SPEED
local spread = params.spread or math.pi / 8
local n = params.n
local center = Player.center(player)
local base = math.atan(center.y - e.y, center.x - e.x)
for i = 1, n do
local t = n == 1 and 0 or (i - 1) / (n - 1) - 0.5
local a = base + t * spread
local vel = { x = math.cos(a) * speed, y = math.sin(a) * speed }
local kind = params.kind or Bullet.kind.ENEMY_DEFAULT
shoot(e, vel, kind)
end
end
-- n is bullets fired; gap_n is slots skipped. spread covers all slots
-- (n + gap_n), so wider gap also widens the wall. gap_shift offsets the gap in
-- slot units (-ve = left of aim). for centered output, n should be even.
function M.fire_wall(e, player, params)
local speed = params.speed or BULLET_SPEED
local spread = params.spread or math.pi * 5 / 6
local n = params.n
local gap_n = params.gap_n or 2
local slots = n + gap_n
local base = params.base_angle
if not base then
local center = Player.center(player)
base = math.atan(center.y - e.y, center.x - e.x)
end
local shift = params.gap_shift or 0
local gap_lo = math.floor(n / 2) + 1 + shift
if gap_lo < 1 then gap_lo = 1 end
if gap_lo > slots - gap_n + 1 then gap_lo = slots - gap_n + 1 end
local gap_hi = gap_lo + gap_n - 1
for i = 1, slots do
if i < gap_lo or i > gap_hi then
local t = slots == 1 and 0 or (i - 1) / (slots - 1) - 0.5
local a = base + t * spread
local vel = { x = math.cos(a) * speed, y = math.sin(a) * speed }
local kind = params.kind or Bullet.kind.ENEMY_DEFAULT
shoot(e, vel, kind)
end
end
end
function M.fire_ring(e, _player, params)
local speed = params.speed or BULLET_SPEED
local n = params.n
for i = 1, n do
local a = (i / n) * math.pi * 2
local vel = { x = math.cos(a) * speed, y = math.sin(a) * speed }
local kind = params.kind or Bullet.kind.ENEMY_DEFAULT
shoot(e, vel, kind)
end
end
function M.fire_spiral(e, _player, params)
local speed = params.speed or BULLET_SPEED
local n = params.n
for i = 1, n do
local a = e.spiral_angle + (i / n) * math.pi * 2
local vel = { x = math.cos(a) * speed, y = math.sin(a) * speed }
local kind = params.kind or Bullet.kind.ENEMY_DEFAULT
shoot(e, vel, kind)
end
e.spiral_angle += params.spin
end
return M