-
Notifications
You must be signed in to change notification settings - Fork 15
/
eventTextState.lua
92 lines (75 loc) · 1.88 KB
/
eventTextState.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
82
83
84
85
86
87
88
89
90
91
92
local State = require("state")
local EventTextState = {}
EventTextState.__index = EventTextState
setmetatable(EventTextState, State)
EventTextState.EVENT_SLOWDOWN = 8
EventTextState.EVENT_TIMEUP = 32
local eventName = {
"DUCK RUSH",
"PREDATOR RUSH",
"FREEZE TIME",
"SWITCH",
"PREDATORS",
"VACUUM",
"SPEED UP",
"SLOW DOWN",
"DUCK DASH",
"ESCAPE",
"DUCK BEAT"
}
function EventTextState.create(event)
local self = setmetatable(State.create(), EventTextState)
if event == EventTextState.EVENT_TIMEUP then
self.text = "TIME UP"
self.imgBox = ResMgr.getImage("timeup_box.png")
self.offset = 160
elseif event <= EventTextState.EVENT_SLOWDOWN then
self.text = eventName[event]
self.imgBox = ResMgr.getImage("event_box.png")
self.offset = 35
else
self.text = eventName[event]
self.imgBox = ResMgr.getImage("minigame_box.png")
self.offset = 35
end
self.font = ResMgr.getFont("joystix40")
self.y = -106
self.speed = 400
self.gravity = 500
self.hits = 0
self.time = 0
return self
end
function EventTextState:update(dt)
self.time = self.time + dt
self.speed = self.speed + self.gravity*dt
self.y = self.y + self.speed*dt
if self.y > 168 then
self.y = 168
if self.hits < 2 then
playSound("slam")
self.speed = self.speed * -0.20
else
self.speed = 0
end
self.hits = self.hits + 1
end
if self.time >= 1.5 then
popState()
end
end
function EventTextState:draw()
love.graphics.setColor(0, 0, 0, 128)
love.graphics.rectangle("fill", 0, 0, WIDTH, HEIGHT)
love.graphics.setColor(255, 255, 255, 255)
love.graphics.draw(self.imgBox, 0, self.y)
love.graphics.setFont(self.font)
love.graphics.setColor(0, 0, 0, 128)
love.graphics.print(self.text, self.offset, self.y+30+4)
love.graphics.setColor(255, 255, 255, 255)
love.graphics.print(self.text, self.offset, self.y+30)
end
function EventTextState:isTransparent()
return true
end
return EventTextState