-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy patheventmanager.lua
45 lines (36 loc) · 1.17 KB
/
eventmanager.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
EventManager = Object:extend()
local Timer = require 'libs/knife/knife/timer'
function EventManager:new(eventScript)
self.eventScript = eventScript
end
function EventManager:init()
self:deploy();
Timer.every(60, function() self:deploy() end)
end
function EventManager:deploy()
for i, event in ipairs(self.eventScript) do
Timer.after(event.time,
function()
local unit = event.unit(event.x, event.y, event.life, event.damage, Character.LOYALTY_ENEMY)
-- local overlap = false
-- for j, officer in ipairs(gameworld_officers) do
-- local u = vector(unit.bbox.x, unit.bbox.y)
-- local o = vector(officer.bbox.x, officer.bbox.y)
-- local d = u:dist(o)
-- overlap = d < unit.bbox.w
-- if overlap then
-- break
-- end
-- end
-- if not overlap then
table.insert(gameworld_officers, unit)
-- else
-- print('skip spawn enemy because overlap')
-- end
end)
end
end
function EventManager:update(dt)
Timer.update(dt)
end
return EventManager