-
Notifications
You must be signed in to change notification settings - Fork 0
/
hotzone.lua
executable file
·81 lines (68 loc) · 1.99 KB
/
hotzone.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
local class = require "middleclass.middleclass"
local Drawable = require "drawable"
local HotZone = class("HotZone", Drawable)
local global = require "global"
local Human = require "human"
local Zombie = require "zombie"
function HotZone:initialize(x, y, w, h)
Drawable.initialize(self, x, y)
self.hitbox = global.addHitbox(self, x, y, w, h)
self.w = w
self.h = h
self.contains_human = false
self.contains_zombie = false
self.new_contains_human = false
self.new_contains_zombie = false
self.frame = 0
end
function HotZone:update(dt)
self.frame = (self.frame + 1) % 2
-- budget low-pass filter
if self.frame == 0 then
self.contains_human = false
self.contains_zombie = false
else
self.new_contains_human = false
self.new_contains_zombie = false
end
end
function HotZone:draw()
if self.contains_human and self.contains_zombie then
love.graphics.setColor(218, 165, 32)
elseif self.contains_human then
love.graphics.setColor(0, 255, 0)
elseif self.contains_zombie then
love.graphics.setColor(255, 255, 0)
else
love.graphics.setColor(0, 0, 255);
end
love.graphics.rectangle("line", self.x, self.y, self.w, self.h)
end
function HotZone:onCollision(other, dx, dy)
if other:isInstanceOf(Human) then
if self.frame == 0 then
self.contains_human = true
else
self.new_contains_human = true
end
elseif other:isInstanceOf(Zombie) then
if self.frame == 0 then
self.contains_zombie = true
else
self.new_contains_zombie = true
end
end
end
function HotZone:containsHuman()
return self.contains_human or self.new_contains_human
end
function HotZone:containsZombie()
return self.contains_zombie or self.new_contains_zombie
end
function HotZone:destroy()
if self.hitbox ~= nil then
global.removeHitbox(self.hitbox)
end
Drawable.destroy(self)
end
return HotZone