-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy patheventScoreState.lua
109 lines (91 loc) · 2.83 KB
/
eventScoreState.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
local State = require("state")
local EventScoreState = {}
EventScoreState.__index = EventScoreState
setmetatable(EventScoreState, State)
EventScoreState.STATE_TRANSITION = 0
EventScoreState.STATE_POPIN = 1
EventScoreState.STATE_DISPLAY = 2
function EventScoreState.create(parent, scores, deltas)
local self = setmetatable(State.create(), EventScoreState)
for i=1,4 do
scores[i] = scores[i] + deltas[i]
end
self.deltas = deltas
self.state = EventScoreState.STATE_TRANSITION
self.time = 0
self.slidex = 0
self.slidespeed = 200
self.slideacc = 400
self.hits = 0
self.sliderleft = ResMgr.getImage("score_slide_left.png")
self.sliderright = ResMgr.getImage("score_slide_right.png")
self.duck_dolls = ResMgr.getImage("duck_dolls.png")
self.plusminus = ResMgr.getImage("scorescreen_plusminus.png")
self.quad_plus = love.graphics.newQuad(0,0,34,34,34,68)
self.quad_minus = love.graphics.newQuad(0,34,34,34,34,68)
self.duck_quads = {}
for i=0,3 do
self.duck_quads[i] = love.graphics.newQuad(0,i*51, 56, 51, 56, 204)
end
return self
end
function EventScoreState:enter()
playSound("slide")
end
function EventScoreState:update(dt)
if self.state == EventScoreState.STATE_TRANSITION then
self.slidespeed = self.slidespeed + self.slideacc*dt
self.slidex = self.slidex + self.slidespeed*dt
if self.slidex > 287 then
self.slidex = 287
self.slidespeed = self.slidespeed * -0.2
self.hits = self.hits+1
if self.hits == 1 then
playSound("slam")
elseif self.hits == 3 then
self.state = EventScoreState.STATE_POPIN
end
end
elseif self.state == EventScoreState.STATE_POPIN then
self.time = self.time + dt
for i=0,3 do
if self.time > i*0.2+0.2 and self.time-dt <= i*0.2+0.2 then
playSound("slam")
end
end
if self.time > 2 then
popState()
popState()
end
end
end
function EventScoreState:draw()
setScissor(63, 54, 573, 333)
love.graphics.draw(self.sliderleft, 63-287+self.slidex, 54)
love.graphics.draw(self.sliderright, 636-self.slidex, 54)
love.graphics.setFont(ResMgr.getFont("joystix40"))
if self.state == EventScoreState.STATE_POPIN then
for i=0,3 do
if self.time > i*0.2 then
local val = math.max(0, 0.25-(self.time-i*0.2))
love.graphics.draw(self.duck_dolls, self.duck_quads[i], 274, 97+83*i, val*2, 1+val*8, 1+val*8, 28, 25)
end
if self.time > i*0.2+0.25 then
love.graphics.setColor(0, 0, 0, 128)
love.graphics.print(math.abs(self.deltas[i+1]), 364, 79+83*i)
love.graphics.setColor(255, 255,255,255)
love.graphics.print(math.abs(self.deltas[i+1]), 364, 75+83*i)
if self.deltas[i+1] >= 0 then
love.graphics.draw(self.plusminus, self.quad_plus, 320, 80+83*i)
else
love.graphics.draw(self.plusminus, self.quad_minus, 320, 80+83*i)
end
end
end
end
setScissor()
end
function EventScoreState:isTransparent()
return true
end
return EventScoreState