-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathmain.lua
66 lines (59 loc) · 1.56 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
import '../../../AnimatedSprite.lua'
local gfx <const> = playdate.graphics
local imagetable = gfx.imagetable.new("assets/mushroom")
local sprites = {}
local i = 1
local animate = true
local states = AnimatedSprite.loadStates("assets/config.json")
math.randomseed(playdate.getSecondsSinceEpoch())
playdate.display.setRefreshRate(50)
local function ManualLoopAnimation(s)
s:changeState("idle")
end
local menu = playdate.getSystemMenu()
menu:addMenuItem("Reset", function()
for i,v in ipairs(sprites) do v:remove() end
sprites = {}
i = 1
gfx.clear()
end)
local function SpawnNewSprite()
local sprite = AnimatedSprite.new(imagetable, states, true)
sprite.states.fall.onAnimationEndEvent = ManualLoopAnimation
sprite:setZIndex(i)
sprite:moveTo(math.random(0,390), math.random(0,230))
sprites[i] = sprite
print(i)
i = i + 1
end
local function DeleteLastSprite()
if (i > 1) then
i = i - 1
sprites[i]:remove()
sprites[i] = nil
print(i)
end
end
function playdate.update()
if (animate) then
gfx.sprite.update()
end
local crank = math.floor(playdate.getCrankChange())
if (crank > 0) then
for i = 1, crank, 1 do
SpawnNewSprite()
end
end
if (crank < 0) then
for i = 1, -crank, 1 do
DeleteLastSprite()
end
end
if (playdate.buttonJustPressed(playdate.kButtonUp)) then
SpawnNewSprite()
end
if (playdate.buttonJustPressed(playdate.kButtonDown)) then
DeleteLastSprite()
end
playdate.drawFPS(0,0)
end