-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathspawner.lua
More file actions
72 lines (66 loc) · 2 KB
/
Copy pathspawner.lua
File metadata and controls
72 lines (66 loc) · 2 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
-- spawning system
hero = {}
function in_table(needle, haystack)
for k, v in pairs(haystack) do
if v == needle then
return true
end
end
return false
end
function table_index(needle, haystack)
for k, v in pairs(haystack) do
if v == needle then
return k
end
end
return -1
end
spawner = {}
spawner.items = { 204, 205, 206, 207, 220, 221, 222, 223, 59, 236, 237, 238, 239, 254, 62}
spawner.lookup = { 'player', 'cone', 'wall', 'shredder', 'computer', 'fan', 'boss_comp', 'copier', 'button', 'door1', 'door2', 'door3', 'door4', 'code', 'box' }
spawner.queue = {}
function spawner.init()
spawner.queue = {}
for x = 0, 128 do
for y = flr((ground - 104) / 8), flr(((ground - 104) / 8) + 16) do
for i in pairs(spawner.items) do
if in_table(mget(x, y), spawner.items) then
local which = table_index(mget(x, y), spawner.items)
mset(x, y, nil)
add(spawner.queue, { x = x * 8, y = y * 8, type = spawner.lookup[which] })
end
end
end
end
spawner.update(1/30)
end
function spawner.update(dt)
-- screen left is hero.x - 30
local hero_x = (hero and hero.x) or 0
local screen_right = flr((hero_x - 30)) + 128 + 32
for s in all(spawner.queue) do
if s.x <= screen_right then
if s.type == 'player' then
hero = assemblage.player(s.x, s.y)
elseif s.type == 'button' then
assemblage.button(s.x, s.y)
elseif s.type == 'door1' then
assemblage.door(s.type, s.x, s.y, 100 * 8 + 32, s.y, false)
elseif s.type == 'door2' then
assemblage.door(s.type, s.x, s.y, 16, s.y + 128)
elseif s.type == 'door3' then
assemblage.door(s.type, s.x, s.y, 111 * 8 + 36, s.y, false)
elseif s.type == 'door4' then
assemblage.door(s.type, s.x, s.y, 16, s.y + 128, true, true)
elseif s.type == 'code' then
assemblage.collectable('code', s.x, s.y)
elseif s.type == 'box' then
assemblage.box(s.x, s.y)
else
assemblage.machine(s.type, s.x, s.y)
end
del(spawner.queue, s)
end
end
end