forked from Stabyourself/orthorobot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
levelbutton.lua
205 lines (172 loc) · 7.28 KB
/
levelbutton.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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
levelbutton = class:new()
function levelbutton:init(x, y, text, i, unlocked)
self.x = x
self.y = y
self.text = text
self.i = i
self.unlocked = unlocked
self.value = 0
self.textwidth = levelselectfont:getWidth(self.text)
self.coinwidth = coinsfont:getWidth(#filetable[self.i].collectedcoins .. "/" .. filetable[self.i].coins)
self.active = true
self.xt = x
self.xmargin = 20
self.textyplus = -5
self.height = 80
self.width = 190
end
function levelbutton:update(dt)
if self.x < self.xt then
self.x = self.x + (self.xt-self.x)/3*dt*15+10*dt
if self.x > self.xt then
self.x = self.xt
end
elseif self.x > self.xt then
self.x = self.x - (self.x-self.xt)/3*dt*15-10*dt
if self.x < self.xt then
self.x = self.xt
end
end
if self.unlocked then
local x, y = mymousegetPosition()
y = y - menuoffset
x = x - menuoffsetx
if self:gethighlight(x, y) then
self.value = self.value + ((1-self.value)*10*dt+0.01*dt)
if self.value > 1 then
self.value = 1
end
else
self.value = self.value - (self.value*4*dt+0.1*dt)
if self.value < 0 then
self.value = 0
end
end
end
end
function levelbutton:draw()
if self.x < -self.width/2-32 or self.x > screenwidth+self.width/2 then
return
end
if self.unlocked then
if (not filetable[self.i].goaltime or (filetable[self.i].hightime and filetable[self.i].hightime <= filetable[self.i].goaltime)) and
(not filetable[self.i].goalsteps or (filetable[self.i].highsteps and filetable[self.i].highsteps <= filetable[self.i].goalsteps)) and
(not filetable[self.i].goalwarps or (filetable[self.i].highwarps and filetable[self.i].highwarps <= filetable[self.i].goalwarps)) and
(#filetable[self.i].collectedcoins >= filetable[self.i].coins) then
lg_setColor(255, 255, 255, 150*fadecolor)
love.graphics.draw(yayimg, self.x-self.width/2+.5, self.y+1)
end
local r, g, b = 190, 206, 248
local tr, tg, tb = unpack(getrainbowcolor(math.fmod(rainbowi+.5+self.value*0.5, 1)))
r = r + (tr-r)*(self.value*.7+.3)
g = g + (tg-g)*(self.value*.7+.3)
b = b + (tb-b)*(self.value*.7+.3)
lg_setColor(r, g, b, 200*fadecolor)
love.graphics.rectangle("fill", self.x-self.width/2, self.y+self.height-(self.height-30)*self.value, self.width, (self.height-30)*self.value)
love.graphics.setFont(levelselectfont)
mygraphicssetScissor(self.x-self.width/2+menuoffsetx+self.width/2*self.value, self.y+menuoffset, round(self.width-self.width*self.value), self.height*0.6)
lg_setColor(r, g, b, 100*fadecolor)
love.graphics.rectangle("fill", self.x-self.width/2, self.y, self.width, 30)
lg_setColor(0, 0, 0, 255*fadecolor)
if self.text then
love.graphics.print(self.text, self.x - self.textwidth/2+6, self.y-2)
end
mygraphicssetScissor()
lg_setColor(r, g, b, 255*fadecolor)
mygraphicssetScissor(round(self.x-self.width/2+menuoffsetx), self.y+menuoffset, round(self.width/2*self.value), self.height*0.6)
if self.text then
love.graphics.print(self.text, round(self.x - self.textwidth/2+6), self.y-2)
end
mygraphicssetScissor(round(self.x+menuoffsetx+self.width/2-(self.width/2*self.value)), self.y+menuoffset, round(self.width/2), self.height*0.6)
if self.text then
love.graphics.print(self.text, round(self.x - self.textwidth/2+6), self.y-2)
end
mygraphicssetScissor()
love.graphics.setFont(winwindowfont)
lg_setColor(255, 255, 255, 255*fadecolor)
love.graphics.draw(clockimg, self.x-self.width/2+6, self.y+34, 0, 2, 2)
love.graphics.draw(stepsimg, self.x-self.width/2+70, self.y+34, 0, 2, 2)
love.graphics.draw(warpsimg, self.x-self.width/2+134, self.y+34, 0, 2, 2)
if not filetable[self.i].hightime then
lg_setColor(255, 255, 255, 255*fadecolor)
elseif (not filetable[self.i].goaltime and filetable[self.i].hightime) or filetable[self.i].hightime <= filetable[self.i].goaltime then
lg_setColor(0, 255, 0, 255*fadecolor)
else
lg_setColor(255, 0, 0, 255*fadecolor)
end
love.graphics.print(filetable[self.i].hightime or "-", self.x-self.width/2+30, self.y+50)
if not filetable[self.i].highsteps then
lg_setColor(255, 255, 255, 255*fadecolor)
elseif (not filetable[self.i].goalsteps and filetable[self.i].highsteps) or filetable[self.i].highsteps <= filetable[self.i].goalsteps then
lg_setColor(0, 255, 0, 255*fadecolor)
else
lg_setColor(255, 0, 0, 255*fadecolor)
end
love.graphics.print(filetable[self.i].highsteps or "-", self.x-self.width/2+94, self.y+50)
if not filetable[self.i].highwarps then
lg_setColor(255, 255, 255, 255*fadecolor)
elseif (not filetable[self.i].goalwarps and filetable[self.i].highwarps) or filetable[self.i].highwarps <= filetable[self.i].goalwarps then
lg_setColor(0, 255, 0, 255*fadecolor)
else
lg_setColor(255, 0, 0, 255*fadecolor)
end
love.graphics.print(filetable[self.i].highwarps or "-", self.x-self.width/2+158, self.y+50)
lg_setColor(255, 255, 255, 255*fadecolor)
love.graphics.print(filetable[self.i].goaltime or "-", self.x-self.width/2+30, self.y+30)
lg_setColor(255, 255, 255, 255*fadecolor)
love.graphics.print(filetable[self.i].goalsteps or "-", self.x-self.width/2+94, self.y+30)
lg_setColor(255, 255, 255, 255*fadecolor)
love.graphics.print(filetable[self.i].goalwarps or "-", self.x-self.width/2+158, self.y+30)
lg_setColor(100+self.value*150, 100+self.value*150, 100+self.value*150, 200*fadecolor)
love.graphics.draw(coinsbackimg, self.x+self.width/2, self.y)
lg_setColor(255, 255, 255, 255*fadecolor)
if #filetable[self.i].collectedcoins >= filetable[self.i].coins then
lg_setColor(255, 255, 255, 255*fadecolor)
else
lg_setColor(50, 50, 50, 255*fadecolor)
end
love.graphics.draw(coinimg, self.x+self.width/2-14, self.y-2+creditsr*30, 0, 3, 3)
if #filetable[self.i].collectedcoins >= filetable[self.i].coins then
lg_setColor(0, 255, 0, 255*fadecolor)
else
lg_setColor(255, 0, 0, 255*fadecolor)
end
love.graphics.setFont(coinsfont)
love.graphics.print(#filetable[self.i].collectedcoins .. "/" .. filetable[self.i].coins, self.x+self.width/2+17-self.coinwidth/2, self.y+50)
local r, g, b = unpack(getrainbowcolor(math.fmod(rainbowi+0.5+self.value*0.5, 1)))
lg_setColor(r, g, b, 255*fadecolor)
love.graphics.rectangle("line", round(self.x-self.width/2)-1, round(self.y)-1, self.width+2, self.height+2)
else
local r, g, b = 200, 200, 200
love.graphics.setFont(levelselectfont)
lg_setColor(r, g, b, 100*fadecolor)
love.graphics.rectangle("fill", self.x-self.width/2, self.y, self.width, 30)
lg_setColor(0, 0, 0, 255*fadecolor)
if self.text then
love.graphics.print(self.text, self.x - self.textwidth/2+6, self.y-2)
end
lg_setColor(100, 100, 100, 100*fadecolor)
love.graphics.draw(coinsbackimg, self.x+self.width/2, self.y)
lg_setColor(r, g, b, 100*fadecolor)
love.graphics.rectangle("line", round(self.x-self.width/2)-1, round(self.y)-1, self.width+2, self.height+2)
end
end
function levelbutton:mousepressed(x, y, button)
if self.unlocked and self.active and button == lbutton then
if self:gethighlight(x, y) then
for i, v in pairs(levelbuttons) do
v.active = false
end
menubuttons[5].active = false
startlevel(self.i)
return true
end
end
end
function levelbutton:gethighlight(x, y)
if x >= self.x-self.width/2-1 and x < self.x+self.width/2+2+30 and
y >= self.y-1 and y < self.y+self.height+2 then
return true
end
return false
end