da5794b507
- Allow enemies to spawn on wall tiles
58 lines
1.2 KiB
Lua
58 lines
1.2 KiB
Lua
local physics = require("physics")
|
|
|
|
local enemies = {
|
|
enemies = {},
|
|
enemy_count = 0,
|
|
}
|
|
|
|
function enemies.add(self, enemy)
|
|
self.enemies[self.enemy_count + 1] = enemy
|
|
self.enemy_count = self.enemy_count + 1
|
|
end
|
|
|
|
function enemies.update(self, player, level, systems, dt)
|
|
local i = 1
|
|
while self.enemies[i] do
|
|
local e = self.enemies[i]
|
|
if not e.dead and e.update then
|
|
e:update(player, level, systems, dt)
|
|
end
|
|
|
|
if e.dead then
|
|
self.enemies[i] = self.enemies[#self.enemies]
|
|
self.enemies[#self.enemies] = nil
|
|
self.enemy_count = self.enemy_count - 1
|
|
i = i - 1
|
|
end
|
|
|
|
i = i + 1
|
|
end
|
|
end
|
|
|
|
function enemies.interact(self, player, systems)
|
|
local i = 1
|
|
while self.enemies[i] do
|
|
local e = self.enemies[i]
|
|
if e.interact and physics.boxCollide(e, player) then
|
|
e:interact(player, systems)
|
|
end
|
|
|
|
i = i + 1
|
|
end
|
|
end
|
|
|
|
function enemies.draw(self)
|
|
for i,e in ipairs(self.enemies) do
|
|
if e.draw then
|
|
e:draw()
|
|
end
|
|
end
|
|
end
|
|
|
|
function enemies.clear(self)
|
|
self.enemies = {}
|
|
self.enemy_count = 0
|
|
end
|
|
|
|
return enemies
|