-
Notifications
You must be signed in to change notification settings - Fork 0
/
levels.lua
328 lines (296 loc) · 9.85 KB
/
levels.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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
math = require "math"
utils = require "utils"
sprite = require "sprite"
flammable_module = require "flammable"
barrel = require "explosives"
crate = require "crate"
water = require "water"
gas = require "gas"
buttons = require "buttons"
water_barrel = require "water_barrel"
mainDisplay = require "mainDisplay"
module(..., package.seeall)
edges = {} --1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
levels_capacity = {0, 600, 225, 500, 0,700, 750, 510,1100,900,1200,1200,300,500, 1300, 0}
level_pannable = {true, true, false, false, true, true, false, true, true, true, true,true,true,true,true, false}
background = display.newImage("Background1.png", 0, 0)
number_of_levels = 16
barrel_changed = false
background = display.newImage("Background1.png", 0, 0)
mainDisplay.mainDisplay:insert(background)
number_of_levels = 17
cur_level = 0
reset_lock = false
displacex = 0
displacey = 0
edge = {}
function edge:new(x, y, w, h, t)
local instance = {x=x, y=y}
instance.image = display.newRect(x, y, w, h)
instance.image.isVisible = false
--instance.image:setFillColor(255,0,0)
instance.type = t
instance.scroll_lock = false
--instance.image:addEventListener("touch", instance)
setmetatable(instance, {__index = edge})
return instance
end
function edge:reset()
self.scroll_lock = false
end
function edge:scroll()
if level_pannable[cur_level] == true then
if self.type == "top" then
if displacey < 0 then
mainDisplay.mainDisplay:translate(0, 10)
displacey = displacey + 10
end
elseif self.type == "bot" then
if mainDisplay.mainDisplay.height * mainDisplay.mainDisplay.yScale + displacey > display.contentHeight then
mainDisplay.mainDisplay:translate(0, -10)
displacey = displacey - 10
end
elseif self.type == "left" then
if displacex < 0 then
mainDisplay.mainDisplay:translate(10, 0)
displacex = displacex + 10
end
elseif self.type == "right" then
--pan right if we can
if mainDisplay.mainDisplay.width * mainDisplay.mainDisplay.xScale + displacex > display.contentWidth then
mainDisplay.mainDisplay:translate(-10, 0)
displacex = displacex - 10
end
end
end
--self.scroll_lock = false
end
function edge:contains(x, y)
if self.x < x and self.image.width+self.x > x and self.y < y and self.image.height+self.y > y then
return true
end
return false
end
function scrollTouch(event)
for i=1, 4 do
if edges[i]:contains(event.x, event.y)==true then
--print(edges[i].type.." registered")
edges[i].scroll_lock = true
else
edges[i].scroll_lock = false
end
end
event.x = event.x-displacex
event.y = event.y-displacey
if barrel.barrel_lock == false and buttons.scroll_mode == true then
barrel_changed = true
barrel.barrel_lock = true
end
if buttons.scroll_mode == false and barrel_changed == true then
barrel_changed = false
barrel.barrel_lock = false
end
--barrel.barrel_lock = buttons.scroll_mode
if buttons.scroll_mode == false then
gas.add_gas(event)
end
if event.phase=="ended" or event.phase=="cancelled" then
reset_edges()
end
end
function scroll_update()
buttons.animate_gas(gas.distance_allowed, gas.distance_covered)
for i=1, 4 do
if edges[i].scroll_lock == true then
edges[i]:scroll()
end
end
end
--[[function edge:touch(event)
self.scroll_lock = true
self.ev = event
print ("scroll activated"..self.type)
end]]
--add invisible scroll boundaries
edges[1] = edge:new(50, 50, display.contentWidth, 50, "top")
edges[2] = edge:new(0, 0, 50, display.contentHeight, "left")
edges[3] = edge:new(display.contentWidth-50, 0, 50, display.contentHeight, "right")
edges[4] = edge:new(0, display.contentHeight-50, display.contentWidth, 50, "bot")
function reset_edges()
for i=1, 4 do
edges[i]:reset()
end
end
function reset_level(event)
if(event.isShake == true) then
reset_lock = true
local prev_displacex = displacex
local prev_displacey = displacey
kill_level()
spawn_level(cur_level)
mainDisplay.mainDisplay:translate(prev_displacex, prev_displacey)
displacex = prev_displacex
displacey = prev_displacey
end
end
function kill_level()
barrel.barrel_lock = false
barrel_changed = false
mainDisplay.mainDisplay:translate(-displacex, -displacey)
displacex=0
displacey=0
table_size = table.getn(flammable_module.flammable_list)
for i =table_size, 1, -1 do
flammable_module.flammable_list[i]:burn_up()
end
buttons.kill_buttons()
barrel.ghost_flag = false
water.remove_all_water()
end
function spawn_level(level)
reset_lock = false
cur_level = level
gas.distance_allowed = levels_capacity[level]
gas.distance_covered = 0
if level == 0 then
--intro level goes here
elseif level == 1 then
barrel.spawn_barrel(100, 100)
crate.spawn_crate(100, 200)
crate.spawn_crate(100, 400)
elseif level == 2 then
barrel.spawn_barrel(100, 100)
crate.spawn_crate(200, 100)
crate.spawn_crate(380, 754)
elseif level ==3 then
crate.spawn_crate(50, 50)
crate.spawn_crate(50, 700)
barrel.spawn_barrel(100, 300)
barrel.spawn_barrel(100, 400)
barrel.spawn_barrel(100, 500)
crate.spawn_crate(430, 400)
elseif level == 4 then
crate.spawn_crate(400, 600)
crate.spawn_crate(100, 100)
barrel.spawn_barrel(160, 650)
barrel.spawn_barrel(100, 750)
elseif level == 5 then
crate.spawn_crate(100,100)
crate.spawn_crate(100,781)
crate.spawn_crate(860,100)
crate.spawn_crate(860,781)
barrel.spawn_barrel(440,414)
barrel.spawn_barrel(520,414)
barrel.spawn_barrel(480,454)
barrel.spawn_barrel(440,494)
barrel.spawn_barrel(520,494)
elseif level == 6 then
barrel.spawn_barrel(100,100)
crate.spawn_crate(100,250)
crate.spawn_crate(250,250)
crate.spawn_crate(100,700)
crate.spawn_crate(300,900)
elseif level == 7 then
crate.spawn_crate(400, 550)
crate.spawn_crate(100, 100)
barrel.spawn_barrel(160, 650)
barrel.spawn_barrel(100, 750)
water.spawn_water(150, 600)
water.spawn_water(200, 625)
water.spawn_water(250, 650)
water.spawn_water(300, 675)
water.spawn_water(350, 700)
water.spawn_water(400, 750)
elseif level == 8 then
barrel.spawn_barrel(100,100)
barrel.spawn_barrel(100,250)
barrel.spawn_barrel(400,700)
barrel.spawn_barrel(500,600)
crate.spawn_crate(100,550)
crate.spawn_crate(680,400)
crate.spawn_crate(680,750)
elseif level == 9 then
crate.spawn_crate(100,100)
crate.spawn_crate(860,900)
barrel.spawn_barrel(480,554)
water.spawn_water(100,300)
water.spawn_water(860,700)
elseif level == 10 then
crate.spawn_crate(480,50)
crate.spawn_crate(480,400)
crate.spawn_crate(100,754)
crate.spawn_crate(900,754)
crate.spawn_crate(480,954)
crate.spawn_crate(200,1150)
crate.spawn_crate(800,1150)
barrel.spawn_barrel(380,754)
barrel.spawn_barrel(480,754)
barrel.spawn_barrel(580,754)
barrel.spawn_barrel(300,1200)
barrel.spawn_barrel(480,1100)
barrel.spawn_barrel(650,1200)
elseif level == 11 then
barrel.spawn_barrel(100,100)
barrel.spawn_barrel(100,200)
barrel.spawn_barrel(480,950)
crate.spawn_crate(200,150)
crate.spawn_crate(600,300)
crate.spawn_crate(480,600)
crate.spawn_crate(480,954)
water.spawn_water(480,754)
elseif level == 12 then
barrel.spawn_barrel(110,110)
barrel.spawn_barrel(600,800)
crate.spawn_crate(250,250)
crate.spawn_crate(900,200)
crate.spawn_crate(480,654)
crate.spawn_crate(150,1100)
crate.spawn_crate(700,1100)
water.spawn_water(100,300)
water.spawn_water(275,100)
water.spawn_water(300,900)
water.spawn_water(500,900)
elseif level == 13 then
barrel.spawn_barrel(150,250)
barrel.spawn_barrel(600,200)
barrel.spawn_barrel(400,500)
barrel.spawn_barrel(300,600)
barrel.spawn_barrel(550,700)
crate.spawn_crate(250,400)
crate.spawn_crate(475,375)
crate.spawn_crate(275,800)
crate.spawn_crate(500,650)
crate.spawn_crate(450,950)
crate.spawn_crate(850,950)
water.spawn_water(600,1000)
water.spawn_water(400,200)
elseif level == 14 then
barrel.spawn_barrel(200,200)
barrel.spawn_barrel(500,700)
water.spawn_water(150,375)
water.spawn_water(315,360)
water.spawn_water(350,200)
elseif level == 15 then
crate.spawn_crate(200,200)
barrel.spawn_barrel(225,350)
--crate.spawn_crate(400,200)
barrel.spawn_barrel(350,400)
barrel.spawn_barrel(350,600)
crate.spawn_crate(175,625)
crate.spawn_crate(225,900)
barrel.spawn_barrel(175,1000)
barrel.spawn_barrel(225,1000)
barrel.spawn_barrel(300,1000)
barrel.spawn_barrel(625,1000)
crate.spawn_crate(700, 1000)
barrel.spawn_barrel(800,250)
crate.spawn_crate(800,400)
elseif level == 16 then
crate.spawn_crate(0, 0)
buttons.win_screen:new()
end
if level~=16 then
background:toBack()
buttons.spawn_btn(display.contentWidth-150, 0)
end
end