forked from PossiblyAxolotl/PD-lights-out
/
main.lua
219 lines (189 loc) · 6.92 KB
/
main.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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
import "CoreLibs/graphics"
import "CoreLibs/math"
import "CoreLibs/sprites"
import "CoreLibs/object"
import "CoreLibs/timer"
import "CoreLibs/animator"
import "fireflies.lua"
import "hanglights.lua"
import "levels.lua"
import "pdParticles.lua"
import "transition.lua"
local gfx <const> = playdate.graphics
playdate.display.setScale(2)
--playdate.display.setRefreshRate(25)
local imgOverlay = gfx.image.new(240,160,gfx.kColorBlack)
-- 1,2,3,4 yawn 5,6 dance 7,8,9,10 walk 11,12 flying
local tabPlayer = gfx.imagetable.new("gfx/player/goober")
local tabPlayerFace = gfx.imagetable.new("gfx/player/gooberFace")
local playing = true
sprPlayer = gfx.sprite.new(tabPlayer[5])
sprPlayer.frame = 5
sprPlayer.counter = 0
sprPlayer.velocity = {x=0,y=0}
sprPlayer.onFloor = false
sprPlayer.lastFloor = false
sprPlayer.flipped = gfx.kImageUnflipped
sprPlayer:moveTo(100,50)
sprPlayer:add()
sprPlayer:setCollideRect(1,4,10,10)
gfx.sprite.addEmptyCollisionSprite(-10,-10,10,130)
local sJump = playdate.sound.sampleplayer.new("sfx/jump")
local sHurt = playdate.sound.sampleplayer.new("sfx/hurt")
local imgGN = gfx.image.new("gfx/gn")
local mus = playdate.sound.fileplayer.new("sfx/eepy")
mus:play(0)
local sEnd = playdate.sound.sampleplayer.new("sfx/end")
local pHurt = ParticleCircle(200,120)
pHurt:setSize(5,7)
pHurt:setMode(Particles.modes.DECAY)
pHurt:setSpeed(1,4)
debug = false
playdate.getSystemMenu():addCheckmarkMenuItem("Show FPS", debug, function(value) debug = value end)
playdate.getSystemMenu():addOptionsMenuItem("FPS", { "30", "50" }, "30", function(fps) playdate.display.setRefreshRate(tonumber(fps)) end)
playdate.getSystemMenu():addMenuItem("By PossiblyAx", function() print("https://possiblyaxolotl.itch.io") end)
--createFireflies()
sgn = false
transitionTo(nextLevel, 60, 30)
-- Load all lights once in the simulator to pre-bake the without having to play all levels.
-- Run `copy-baked-lights.bat` from the root directory after running the game once
-- in the simulator to copy the baked lights into the source folder
if not playdate.isSimulator then
preloadAllLights()
end
function playdate.update()
sprPlayer.counter = sprPlayer.counter + 1
sprPlayer.velocity.y = sprPlayer.velocity.y + 0.4
if not sprPlayer.onFloor and playing then
if sprPlayer.counter <= 4 and sprPlayer.frame ~= 11 then
sprPlayer:setImage(tabPlayer[11])
elseif sprPlayer.counter <= 8 and sprPlayer.frame ~= 12 then
sprPlayer:setImage(tabPlayer[12])
else
sprPlayer.counter = 1
sprPlayer:setImage(tabPlayer[11])
end
end
sprPlayer:moveBy(0,sprPlayer.velocity.y)
sprPlayer.onFloor = false
if #sprPlayer:overlappingSprites() > 0 then
while #sprPlayer:overlappingSprites() > 0 do
local by = -sign(sprPlayer.velocity.y)
sprPlayer:moveBy(0,by)
sprPlayer.onFloor = true
end
sprPlayer.velocity.y = 2
end
if playdate.buttonJustPressed(playdate.kButtonA) and sprPlayer.onFloor and playing then
sprPlayer.velocity.y = -4
sprPlayer.lastFloor = false
sprPlayer.onFloor = false
sJump:play()
elseif sprPlayer.lastFloor ~= sprPlayer.onFloor then sprPlayer.velocity.y = 0 end
if playdate.buttonIsPressed(playdate.kButtonLeft) and playing then
sprPlayer.velocity.x = -1
sprPlayer.flipped = gfx.kImageFlippedX
elseif playdate.buttonIsPressed(playdate.kButtonRight) and playing then
sprPlayer.velocity.x = 1
sprPlayer.flipped = gfx.kImageUnflipped
else
sprPlayer.velocity.x = playdate.math.lerp(sprPlayer.velocity.x,0,0.2)
end
if sprPlayer.x > 204 then
transitionTo(nextLevel)
sprPlayer:moveTo(-10,-1000)
elseif sprPlayer.y > 120 then
transitionTo(reLevel)
pHurt:moveTo(sprPlayer.x,120)
sprPlayer:moveTo(-10,-1000)
sHurt:play()
pHurt:add(25)
end
if sprPlayer.onFloor then
sprPlayer:moveBy(sprPlayer.velocity.x,0)
else
sprPlayer:moveBy(sprPlayer.velocity.x * 1.25,0)
end
if #sprPlayer:overlappingSprites() > 0 then
while #sprPlayer:overlappingSprites() > 0 do
local by = -sign(sprPlayer.velocity.x)
sprPlayer:moveBy(by,0)
sprPlayer.onFloor = true
end
end
if sprPlayer.onFloor and playing then
if sprPlayer.velocity.x < 0.5 and sprPlayer.velocity.x > -0.5 then
if sprPlayer.counter <= 10 then
sprPlayer:setImage(tabPlayer[5])
elseif sprPlayer.counter <= 20 then
sprPlayer:setImage(tabPlayer[6])
else
sprPlayer.counter = 1
end
else
if sprPlayer.counter <= 4 then
sprPlayer:setImage(tabPlayer[7])
elseif sprPlayer.counter <= 8 then
sprPlayer:setImage(tabPlayer[8])
elseif sprPlayer.counter <= 12 then
sprPlayer:setImage(tabPlayer[9])
elseif sprPlayer.counter <= 16 then
sprPlayer:setImage(tabPlayer[10])
else
sprPlayer.counter = 1
end
end
end
if level > 4 and sprPlayer.x > 165 and playing == true then
playing = false
mus:stop()
sprPlayer:setImage(tabPlayer[1])
playdate.timer.new(1000, function()
sprPlayer:setImage(tabPlayer[2])
playdate.timer.new(1000, function()
sprPlayer:setImage(tabPlayer[3])
playdate.timer.new(1000, function()
sprPlayer:setImage(tabPlayer[2])
playdate.timer.new(1000, function()
sprPlayer:setImage(tabPlayer[1])
playdate.timer.new(3000, function()
sprPlayer:setVisible(false)
killAll()
sgn = true
createFireflies(7,10)
sEnd:play()
end)
end)
end)
end)
end)
end
gfx.clear()
gfx.pushContext(imgOverlay)
gfx.setColor(gfx.kColorBlack)
gfx.fillRect(0,0,240,160)
gfx.setColor(gfx.kColorWhite)
--gfx.fillRect(5,5,50,50)
updateFireflies()
updateBeams()
gfx.setColor(gfx.kColorBlack)
updateTransition()
gfx.popContext()
sprPlayer.lastFloor = sprPlayer.onFloor
sprPlayer:setImageFlip(sprPlayer.flipped)
gfx.sprite.update()
gfx.setImageDrawMode(gfx.kDrawModeWhiteTransparent)
--imgOverlay:drawBlurred(-20,-20,3,2,gfx.image.kDitherTypeBayer2x2)
imgOverlay:draw(-20,-20)
gfx.setImageDrawMode(gfx.kDrawModeCopy)
--updateLights()
if sgn then
imgGN:drawCentered(100,60)
end
if debug then
playdate.drawFPS(0,0)
end
playdate.timer.updateTimers()
pHurt:update()
--tabPlayerFace[sprPlayer.frame]:drawCentered(sprPlayer.x,sprPlayer.y-1)
end