-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathTitle.lua
85 lines (74 loc) · 2.04 KB
/
Title.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
local pd <const> = playdate
local gfx <const> = Graphics
Title = {}
class("Title").extends(BaseScene)
-- This can be initialized at boot
local logo_image <const> = gfx.image.new("/assets/images/logo")
local logo <const> = gfx.sprite.new(logo_image)
logo:moveTo(200, 90)
local playerSlot
local menu
local crankTick = 0
-- Add menu controls to the scene's input handler
Title.inputHandler = {
upButtonDown = function()
menu:selectPrevious()
end,
downButtonDown = function()
menu:selectNext()
end,
cranked = function(change, _)
crankTick = crankTick + change
if crankTick > 30 then
crankTick = 0
menu:selectNext()
elseif crankTick < -30 then
crankTick = 0
menu:selectPrevious()
end
end,
AButtonDown = function()
menu:click()
end
}
-- This runs when your scene's object is created, which is the
-- first thing that happens when transitioning away from another scene.
function Title:init()
Title.super.init(self)
Noble.Text.setFont(Noble.Text.FONT_NEWSLEAK) -- Menus use the Noble font
menu = Noble.Menu.new(
true, -- Activate
Noble.Text.ALIGN_CENTER,
false, -- No localization
nil, -- Use default color
4, 6 -- Adjust padding
)
menu:addItem("Play", function() Noble.transition(Play) end)
menu:addItem("Stats", function() Noble.transition(Stats) end)
menu:select("Play")
end
-- When transitioning from another scene, this runs as soon as this
-- scene needs to be visible (this moment depends on which transition type is used).
function Title:enter()
Title.super.enter(self)
self:addSprite(logo)
end
function Title:start()
Title.super.start(self)
-- Add menu item to change the save slot
playerSlot = tonumber(Noble.Settings.get("playerSlot"))
self.menu:addOptionsMenuItem(
"Save",
{ 1, 2, 3, 4 },
playerSlot,
function(value)
Noble.Settings.set("playerSlot", value)
Noble.GameData.save(tonumber(value))
end
)
end
-- This runs once per frame.
function Title:update()
Title.super.update(self)
menu:draw(200, 160)
end