forked from alesan99/mari0_ae
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlevelball.lua
205 lines (178 loc) · 3.92 KB
/
levelball.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
levelball = class:new()
function levelball:init(x, y)
--PHYSICS STUFF
self.x = x-6/16
self.y = y-11/16
self.speedy = 0
self.speedx = 0
self.width = 12/16
self.height = 12/16
self.static = false
self.active = true
self.category = 6
self.mask = { true,
false, false, true, true, true,
false, true, false, true, true,
false, true, true, false, true,
true, true, false, true, true,
false, true, true, false, false,
true, false, true, true, true,
true}
self.destroy = false
self.autodelete = true
--IMAGE STUFF
self.drawable = true
self.graphic = levelballimg
self.quad = levelballquad[1]
self.offsetX = 6
self.offsetY = 3
self.quadcenterX = 8
self.quadcenterY = 8
self.rotation = 0 --for portals
self.uptimer = 0
self.falling = false
self.finish = false
self.finishwait = false
end
function levelball:update(dt)
if self.finishwait then
self.finishwait = self.finishwait - dt
if self.finishwait < 0 then
--next level
nextlevel()
subrtactscore = false
subtracttimer = 0
levelballfinish = false
end
return
elseif self.finish then
self.finish = self.finish + dt
if levelballfinishback[math.floor(self.finish*10)] then
love.graphics.setBackgroundColor(levelballfinishback[math.floor(self.finish*10)])
else
love.graphics.setBackgroundColor(backgroundcolor[background])
end
if (not self.sound and self.finish > 6.9) or (self.sound and not self.sound:isPlaying()) then
--subtract score but it takes too long
if mariotime > 0 then
if subtractscore then
subtracttimer = subtracttimer + dt
while subtracttimer > scoresubtractspeed do
subtracttimer = subtracttimer - scoresubtractspeed
if mariotime > 0 then
mariotime = math.max(0, math.ceil(mariotime - 4))
marioscore = marioscore + 50
end
if mariotime <= 0 then
scoreringsound:stop()
subtractscore = false
subtracttimer = 0
mariotime = 0
end
end
else
playsound(scoreringsound)
subtractscore = true
subtracttimer = 0
end
else
scoreringsound:stop()
self.finishwait = 0.2
end
end
return
end
--rotate back to 0 (portals)
self.rotation = math.fmod(self.rotation, math.pi*2)
if self.rotation > 0 then
self.rotation = self.rotation - portalrotationalignmentspeed*dt
if self.rotation < 0 then
self.rotation = 0
end
elseif self.rotation < 0 then
self.rotation = self.rotation + portalrotationalignmentspeed*dt
if self.rotation > 0 then
self.rotation = 0
end
end
if self.speedx > 0 then
self.speedx = self.speedx - friction*dt
if self.speedx < 0 then
self.speedx = 0
end
else
self.speedx = self.speedx + friction*dt
if self.speedx > 0 then
self.speedx = 0
end
end
--check if offscreen
if self.x < xscroll - width+3 or self.y > mapheight+3 then
return true
end
if self.destroy then
return true
else
return false
end
end
function levelball:get()
self.static = true
self.active = false
self.drawable = false
if levelfinished then
return
end
levelfinished = true
stopmusic()
love.audio.stop()
if self.sound then
playsound(self.sound)
else
playsound(castleendsound)
end
self.finish = 0
for i = 1, players do
local p = objects["player"][i]
p.controlsenabled = false
p.invincible = true
p.speedx = 0
end
end
function levelball:leftcollide(a, b)
self.speedx = 0
if a == "player" then
self:get()
end
return false
end
function levelball:rightcollide(a, b)
self.speedx = 0
if a == "player" then
self:get()
end
return false
end
function levelball:floorcollide(a, b)
if a == "player" then
self:get()
end
if self.activatey then
if self.y > self.activatey then
self.activatey = false
else
return false
end
end
end
function levelball:ceilcollide(a, b)
if a == "player" then
self:get()
end
end
function levelball:passivecollide(a, b)
if a == "player" then
self:get()
return false
end
end