-
Notifications
You must be signed in to change notification settings - Fork 0
/
periodic.lua
56 lines (42 loc) · 1.29 KB
/
periodic.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
local global = require "global"
local class = require "middleclass.middleclass"
local Static = require "static"
local Periodic = class("Periodic", Static)
local drawing = require "drawing"
function Periodic:initialize(x, y, hotzone, image)
Static.initialize(self, x, y)
self.stopsHumans = false
self.cooldown = 0
self.max_cooldown = 30
self.hotzone = hotzone
self.image = image
self.callback = callback
end
function Periodic:stopsBullets()
return false
end
function Periodic:update(dt)
if self.hotzone:containsHuman() and not self.hotzone:containsZombie() then
self.cooldown = self.cooldown + dt
elseif self.hotzone:containsZombie() and not self.hotzone:containsHuman() then
self.cooldown = self.cooldown - dt
end
if self.cooldown >= self.max_cooldown then
self.cooldown = 0
self:trigger()
elseif self.cooldown < 0 then
self.cooldown = 0
end
end
function Periodic:draw()
love.graphics.setColor(255, 255, 255)
love.graphics.draw(self.image, self.x, self.y)
drawing.bar(self.x, self.y - 5,
self.image:getWidth(), 3,
self.cooldown / self.max_cooldown,
{0, 255, 255},
{0, 0, 255})
end
function Periodic:trigger()
end
return Periodic