-
Notifications
You must be signed in to change notification settings - Fork 2
/
temple.lua
58 lines (48 loc) · 1.36 KB
/
temple.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
local DIFFICULTY = require('difficulty')
define_tile_code("catmummy")
local temple = {
identifier = "temple",
title = "Temple",
theme = THEME.TEMPLE,
width = 4,
height = 6,
file_name = "temp.lvl",
}
local level_state = {
loaded = false,
callbacks = {},
}
local overall_state = {
difficulty = DIFFICULTY.NORMAL,
}
local function update_file_name()
if overall_state.difficulty == DIFFICULTY.HARD then
temple.file_name = "temp-hard.lvl"
elseif overall_state.difficulty == DIFFICULTY.EASY then
temple.file_name = "temp-easy.lvl"
else
temple.file_name = "temp.lvl"
end
end
temple.set_difficulty = function(difficulty)
overall_state.difficulty = difficulty
update_file_name()
end
temple.load_level = function()
if level_state.loaded then return end
level_state.loaded = true
level_state.callbacks[#level_state.callbacks+1] = set_pre_tile_code_callback(function(x, y, layer)
spawn_entity(ENT_TYPE.MONS_CATMUMMY, x, y, layer, 0, 0)
return true
end, "catmummy")
end
temple.unload_level = function()
if not level_state.loaded then return end
local callbacks_to_clear = level_state.callbacks
level_state.loaded = false
level_state.callbacks = {}
for _,callback in ipairs(callbacks_to_clear) do
clear_callback(callback)
end
end
return temple