forked from TomK32/Poppy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
level.lua
42 lines (33 loc) · 969 Bytes
/
level.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
Level = class("Level")
function Level:initialize(level, seed)
-- merge the level's values into this
assert(game.levels[level], 'Level ' .. level .. ' is missing')
for k,v in pairs(game.levels[level]) do
self[k] = v
end
self.level = level
self.seed = seed + level
self.dt = 0
self.generator = MapGenerator(self.seed)
self.map = Map(28, 15, self.generator, self)
self.astar = AStar(self.map)
end
function Level:update(dt)
self.dt = self.dt + dt
for layer, entities in pairs(self.map.layers) do
for i, entity in pairs(entities) do
if game.stopped then return end
entity:update(dt)
if entity.dead == true then
table.remove(self.map.layers[layer], i)
end
end
end
for i, entity in ipairs(self.map:belowPosition(self.player.position)) do
if entity.playerEntered then
if game.stopped then return end
entity:playerEntered(self.player)
end
end
self.generator:update(dt)
end