-
Notifications
You must be signed in to change notification settings - Fork 0
/
trap.lua
65 lines (57 loc) · 1.44 KB
/
trap.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
local Entity = require("entity")
local Trap = Entity:extend()
--- Instance a new Trap
-- @param sp SpriteSheet object
-- @param map_object Object from STI
function Trap:new(sp, map_object)
Trap.super.new(self, sp, map_object)
self.name = "trap"
self.an:set_cycle_time(0.15)
self.an:set_states({
default = { { 1, 1 } },
calm = {
{ 1, 1 },
},
triggered = {
{ 3, 1 },
},
triggering = {
{ 1, 1 },
{ 2, 1 },
{ 3, 1 },
},
calming = {
{ 3, 1 },
{ 2, 1 },
{ 1, 1 },
},
})
if self.map_object.properties.open then
self.an:set_state_cur("calm")
else
self.an:set_state_cur("closed")
end
end
--- Update
-- @param dt DeltaTime
function Trap:update(dt)
Trap.super.update(self, dt)
if self.an.state_cur == "calming"
and self.an:get_state_progress() == 1 then
self.an:set_state_cur("calmed")
elseif self.an.state_cur == "triggering"
and self.an:get_state_progress() == 1 then
self.an:set_state_cur("triggered")
end
end
--- Trigger the trap
function Trap:trigger()
if self.map_object.properties.open then
self.map_object.properties.open = false
self.an:set_state_cur("triggering")
else
self.map_object.properties.open = true
self.an:set_state_cur("opening")
end
end
return Trap