-
Notifications
You must be signed in to change notification settings - Fork 0
/
trigger.lua
78 lines (56 loc) · 1.46 KB
/
trigger.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
Trigger = class("Trigger", Entity)
---
-- Trigger:initialize
-- Creates an immobile polygon shape.
--
-- @param vertices A table of vertices
--
function Trigger:initialize(data)
self.vertices = data.points
self.id = data.id or ""
self.solid = data.solid or false
self.triggerAnim = 0
Entity.initialize(self, 0, 0, "static", love.physics.newChainShape(true, unpack(self.vertices)))
self.fixture:setSensor(not self.solid)
end
---
-- Trigger:update
-- Updates the Trigger.
--
-- @param dt Delta time
--
function Trigger:update(dt)
if self.triggerAnim > 0 then
self.triggerAnim = self.triggerAnim - dt * 2
end
if self.triggerAnim < 0 then
self.triggerAnim = 0
end
end
---
-- Trigger:impact
-- Gets called when something collides with the Trigger.
--
-- @param ent Entity collided with
-- @param contact Contact object of the collision
--
function Trigger:impact(ent, contact)
self.triggerAnim = 1
event.call("trigger", {
trigger = self
})
end
---
-- Trigger:draw
-- Draws an outlined polygon.
--
function Trigger:draw()
if self.solid then
love.graphics.setLineWidth(1 + self.triggerAnim * 3)
love.graphics.setColor(100 + self.triggerAnim * 155, 180, 255 - self.triggerAnim * 155)
love.graphics.polygon("line", self.vertices)
else
love.graphics.setColor(90, 90, 90, 90)
love.graphics.polygon("fill", self.vertices)
end
end