-
Notifications
You must be signed in to change notification settings - Fork 2
/
ice_caves.lua
144 lines (124 loc) · 4.9 KB
/
ice_caves.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
local clear_embeds = require('clear_embeds')
local DIFFICULTY = require('difficulty')
define_tile_code("ice_turkey")
define_tile_code("ice_yeti")
define_tile_code("ice_idol")
local ice_caves = {
identifier = "ice",
title = "Ice Caves",
theme = THEME.ICE_CAVES,
width = 4,
height = 13,
file_name = "ice.lvl",
}
local level_state = {
loaded = false,
callbacks = {},
}
local overall_state = {
idol_collected = false,
run_idol_collected = false,
difficulty = DIFFICULTY.NORMAL,
}
ice_caves.set_idol_collected = function(collected)
overall_state.idol_collected = collected
end
ice_caves.set_run_idol_collected = function(collected)
overall_state.run_idol_collected = collected
end
local function update_file_name()
if overall_state.difficulty == DIFFICULTY.HARD then
ice_caves.file_name = "ice-hard.lvl"
elseif overall_state.difficulty == DIFFICULTY.EASY then
ice_caves.file_name = "ice-easy.lvl"
else
ice_caves.file_name = "ice.lvl"
end
end
ice_caves.set_difficulty = function(difficulty)
overall_state.difficulty = difficulty
update_file_name()
end
ice_caves.load_level = function()
if level_state.loaded then return end
level_state.loaded = true
-- Spawn a turkey in ice that must be extracted.
level_state.callbacks[#level_state.callbacks+1] = set_pre_tile_code_callback(function(x, y, layer)
local ice_uid
clear_embeds.perform_block_without_embeds(function()
ice_uid = spawn_entity(ENT_TYPE.FLOOR_ICE, x, y, layer, 0, 0)
end)
local turkey_uid = spawn_entity_over(ENT_TYPE.ITEM_ALIVE_EMBEDDED_ON_ICE, ice_uid, 0, 0)
local turkey = get_entity(turkey_uid)
turkey.inside = ENT_TYPE.MOUNT_TURKEY
turkey.animation_frame = 239
turkey.color.a = 130
return true
end, "ice_turkey")
level_state.callbacks[#level_state.callbacks+1] = set_post_entity_spawn(function(entity)
if level ~= ICE_LEVEL then return end
-- Spawn the ice turkey dead so it can't be ridden.
kill_entity(entity.uid, false)
end, SPAWN_TYPE.ANY, 0, ENT_TYPE.MOUNT_TURKEY)
-- Spawn a yeti in ice that must be extracted.
level_state.callbacks[#level_state.callbacks+1] = set_pre_tile_code_callback(function(x, y, layer)
local ice_uid
clear_embeds.perform_block_without_embeds(function()
ice_uid = spawn_entity(ENT_TYPE.FLOOR_ICE, x, y, layer, 0, 0)
end)
local yeti_uid = spawn_entity_over(ENT_TYPE.ITEM_ALIVE_EMBEDDED_ON_ICE, ice_uid, 0, 0)
local yeti = get_entity(yeti_uid)
yeti.inside = ENT_TYPE.MONS_YETI
local texture_definition = TextureDefinition.new()
texture_definition.texture_path = "Data/Textures/monsters03.png"
texture_definition.width = 2048
texture_definition.height = 2048
texture_definition.tile_width = 128
texture_definition.tile_height = 128
texture_definition.sub_image_offset_x = 128 * 11 -- Let the computer do the math.
texture_definition.sub_image_offset_y = 128 * 4
texture_definition.sub_image_width = 128
texture_definition.sub_image_height = 128
local new_texture = define_texture(texture_definition)
yeti:set_texture(new_texture)
yeti.animation_frame = 0
yeti.color.a = 130
return true
end, "ice_yeti")
-- Spawn an idol in ice that must be extracted.
level_state.callbacks[#level_state.callbacks+1] = set_pre_tile_code_callback(function(x, y, layer)
local ice_uid
clear_embeds.perform_block_without_embeds(function()
ice_uid = spawn_entity(ENT_TYPE.FLOOR_ICE, x, y, layer, 0, 0)
end)
if overall_state.difficulty == DIFFICULTY.EASY or overall_state.run_idol_collected then
-- Do not spawn the idol in easy or if it has been collected.
return true
end
local idol_uid = spawn_entity_over(ENT_TYPE.ITEM_ALIVE_EMBEDDED_ON_ICE, ice_uid, 0, 0)
local idol = get_entity(idol_uid)
if overall_state.idol_collected then
idol.inside = ENT_TYPE.ITEM_MADAMETUSK_IDOL
idol.animation_frame = 172
else
idol.inside = ENT_TYPE.ITEM_IDOL
idol.animation_frame = 31
end
idol.color.a = 130
return true
end, "ice_idol")
level_state.callbacks[#level_state.callbacks+1] = set_post_entity_spawn(function(entity)
-- Set the price to 0 so the player doesn't get gold for returning the idol.
entity.price = 0
end, SPAWN_TYPE.ANY, 0, ENT_TYPE.ITEM_IDOL, ENT_TYPE.ITEM_MADAMETUSK_IDOL)
end
ice_caves.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 ice_caves