noble engine migration
This commit is contained in:
32
source/scenes/BaseScene.lua
Normal file
32
source/scenes/BaseScene.lua
Normal file
@@ -0,0 +1,32 @@
|
||||
local pd <const> = playdate
|
||||
local gfx <const> = Graphics
|
||||
|
||||
BaseScene = {}
|
||||
class("BaseScene").extends(NobleScene)
|
||||
|
||||
function BaseScene:init()
|
||||
BaseScene.super.init(self)
|
||||
|
||||
pd.resetElapsedTime() -- Reset time so each scene starts at 0
|
||||
self.optionsMenu = pd.getSystemMenu() -- Store this so we have access to it in all scenes
|
||||
end
|
||||
|
||||
function BaseScene:update()
|
||||
BaseScene.super.update(self)
|
||||
|
||||
Particles:update() -- Update our particle library
|
||||
end
|
||||
|
||||
function BaseScene:exit()
|
||||
BaseScene.super.exit(self)
|
||||
self.optionsMenu:removeAllMenuItems() -- Remove all custom menu items and reset menu image
|
||||
pd.setMenuImage(nil)
|
||||
end
|
||||
|
||||
function BaseScene:drawBackground()
|
||||
BaseScene.super.drawBackground(self)
|
||||
|
||||
if self.background ~= nil then -- Helper so you can set a scene's background to an image
|
||||
self.background:draw(0, 0)
|
||||
end
|
||||
end
|
150
source/scenes/Game.lua
Normal file
150
source/scenes/Game.lua
Normal file
@@ -0,0 +1,150 @@
|
||||
Game = {}
|
||||
class("Game").extends(BaseScene)
|
||||
local scene = Game
|
||||
|
||||
local font = Graphics.font.new('assets/fonts/Mini Sans 2X')
|
||||
|
||||
local function screenShake(shakeTime, shakeMagnitude)
|
||||
local shakeTimer = playdate.timer.new(shakeTime, shakeMagnitude, 0)
|
||||
shakeTimer.updateCallback = function(timer)
|
||||
local magnitude = math.floor(timer.value)
|
||||
local shakeX = math.random(-magnitude, magnitude)
|
||||
local shakeY = math.random(-magnitude, magnitude)
|
||||
playdate.display.setOffset(shakeX, shakeY)
|
||||
end
|
||||
shakeTimer.timerEndedCallback = function()
|
||||
playdate.display.setOffset(0, 0)
|
||||
end
|
||||
end
|
||||
|
||||
function scene:setValues()
|
||||
scene.background = Graphics.image.new("assets/sprites/bg")
|
||||
|
||||
scene.telemLostSound = playdate.sound.fileplayer.new( "assets/audio/telemko" )
|
||||
scene.telemLostSoundPlayed = false
|
||||
|
||||
scene.balebas = {}
|
||||
|
||||
scene.t = playdate.timer.new(10000)
|
||||
scene.t.repeats = true
|
||||
|
||||
scene.fp = playdate.sound.fileplayer.new( "assets/audio/war" )
|
||||
scene.fp:setVolume(0.7)
|
||||
scene.hello = playdate.sound.fileplayer.new( "assets/audio/hello" )
|
||||
|
||||
end
|
||||
|
||||
function scene:init()
|
||||
scene.super.init(self)
|
||||
scene:setValues()
|
||||
end
|
||||
|
||||
function scene:start()
|
||||
scene.super.start(self)
|
||||
|
||||
self.optionsMenu:addMenuItem("Main Menu", function() Noble.transition(Menu) end)
|
||||
Noble.showFPS = true
|
||||
end
|
||||
|
||||
function scene:spawnBaleba()
|
||||
local baleba = Baleba(math.random(410, 900), math.random(10, 210), scene.player, true)
|
||||
baleba:add()
|
||||
|
||||
return baleba
|
||||
end
|
||||
|
||||
function scene:enter()
|
||||
scene.super.enter(self)
|
||||
|
||||
scene.player = Player(30, 30)
|
||||
scene.player:add()
|
||||
|
||||
scene.ground = Ground(400, 225, scene.player)
|
||||
scene.ground:add()
|
||||
|
||||
scene.t.timerEndedCallback = function()
|
||||
if #scene.balebas >= 6 then
|
||||
return
|
||||
end
|
||||
|
||||
local k = #scene.balebas+1
|
||||
scene.balebas[k] = scene:spawnBaleba()
|
||||
end
|
||||
|
||||
for i=1, 3 do
|
||||
scene.balebas[i] = scene:spawnBaleba()
|
||||
end
|
||||
|
||||
local musicEnabled = Noble.Settings.get("music")
|
||||
scene.hello:play(1)
|
||||
if musicEnabled then
|
||||
scene.fp:play(0)
|
||||
end
|
||||
end
|
||||
|
||||
function scene:update()
|
||||
scene.super.update(self)
|
||||
|
||||
if scene.player == nil then
|
||||
Noble.Text.draw("Telemetry Lost", 200, 110, Noble.Text.ALIGN_CENTER, false, font)
|
||||
return
|
||||
end
|
||||
|
||||
if scene.player.isDead() then
|
||||
if not scene.telemLostSoundPlayed then
|
||||
scene.telemLostSound:play(1)
|
||||
scene.telemLostSoundPlayed = true
|
||||
screenShake(500, 5)
|
||||
end
|
||||
|
||||
scene:destroyPlayer()
|
||||
local et = playdate.timer.new(2000)
|
||||
et.timerEndedCallback = function()
|
||||
Noble.transition(Menu)
|
||||
end
|
||||
return
|
||||
end
|
||||
|
||||
local bat = scene.player.getBat()
|
||||
bat = math.floor(bat/100)
|
||||
Noble.Text.draw("Bat: " .. bat, 10, 215, Noble.Text.ALIGN_LEFT, false, font)
|
||||
|
||||
end
|
||||
|
||||
function scene:destroyPlayer()
|
||||
if scene.player ~= nil then
|
||||
scene.player:remove()
|
||||
scene.player = nil
|
||||
end
|
||||
end
|
||||
|
||||
function scene:exit()
|
||||
scene.super.exit(self)
|
||||
|
||||
scene:destroyPlayer()
|
||||
|
||||
scene.ground:remove()
|
||||
scene.ground = nil
|
||||
|
||||
for i=1, #scene.balebas do
|
||||
scene.balebas[i]:destroy()
|
||||
scene.balebas[i] = nil
|
||||
end
|
||||
|
||||
scene.telemLostSound:stop()
|
||||
scene.telemLostSoundPlayed = false
|
||||
|
||||
scene.fp:stop()
|
||||
|
||||
scene.t:remove()
|
||||
scene.t = nil
|
||||
|
||||
|
||||
Noble.showFPS = false
|
||||
end
|
||||
|
||||
|
||||
function scene:finish()
|
||||
scene.super.finish(self)
|
||||
playdate.display.setScale(1)
|
||||
end
|
109
source/scenes/Menu.lua
Normal file
109
source/scenes/Menu.lua
Normal file
@@ -0,0 +1,109 @@
|
||||
Menu = {}
|
||||
class("Menu").extends(BaseScene)
|
||||
local scene = Menu
|
||||
|
||||
|
||||
|
||||
function scene:setValues()
|
||||
self.background = Graphics.image.new("assets/images/background2")
|
||||
|
||||
self.color1 = Graphics.kColorBlack
|
||||
self.color2 = Graphics.kColorWhite
|
||||
|
||||
self.menu = nil
|
||||
self.sequence = nil
|
||||
|
||||
self.menuX = 15
|
||||
|
||||
self.menuYFrom = -50
|
||||
self.menuY = 15
|
||||
self.menuYTo = 240
|
||||
end
|
||||
|
||||
function scene:init()
|
||||
scene.super.init(self)
|
||||
|
||||
local menuSelSound = playdate.sound.fileplayer.new("assets/audio/menu_select")
|
||||
menuSelSound:setVolume(0.5)
|
||||
|
||||
self:setValues()
|
||||
|
||||
self.menu = Noble.Menu.new(false, Noble.Text.ALIGN_CENTER, false, self.color2, 4,6,0, Noble.Text.FONT_SMALL)
|
||||
|
||||
self:setupMenu(self.menu)
|
||||
|
||||
local crankTick = 0
|
||||
|
||||
self.inputHandler = {
|
||||
upButtonDown = function()
|
||||
self.menu:selectPrevious()
|
||||
menuSelSound:play(1)
|
||||
end,
|
||||
downButtonDown = function()
|
||||
self.menu:selectNext()
|
||||
menuSelSound:play(1)
|
||||
end,
|
||||
cranked = function(change, acceleratedChange)
|
||||
crankTick = crankTick + change
|
||||
if (crankTick > 30) then
|
||||
crankTick = 0
|
||||
self.menu:selectNext()
|
||||
menuSelSound:play(1)
|
||||
elseif (crankTick < -30) then
|
||||
crankTick = 0
|
||||
self.menu:selectPrevious()
|
||||
menuSelSound:play(1)
|
||||
end
|
||||
end,
|
||||
AButtonDown = function()
|
||||
self.menu:click()
|
||||
end
|
||||
}
|
||||
|
||||
end
|
||||
|
||||
function scene:enter()
|
||||
scene.super.enter(self)
|
||||
self.sequence = Sequence.new():from(self.menuYFrom):to(self.menuY, 1.5, Ease.outBounce):start()
|
||||
end
|
||||
|
||||
function scene:start()
|
||||
scene.super.start(self)
|
||||
|
||||
self.menu:activate()
|
||||
end
|
||||
|
||||
function scene:drawBackground()
|
||||
scene.super.drawBackground(self)
|
||||
|
||||
self.background:draw(0, 0)
|
||||
end
|
||||
|
||||
local logo_image <const> = Graphics.image.new("assets/images/logo")
|
||||
|
||||
function scene:update()
|
||||
scene.super.update(self)
|
||||
|
||||
Graphics.setColor(self.color1)
|
||||
Graphics.setDitherPattern(0.2, Graphics.image.kDitherTypeScreen)
|
||||
Graphics.fillRoundRect(200-38, 160-8, 75, 60, 15)
|
||||
self.menu:draw(200, 160)
|
||||
|
||||
logo_image:draw(120, 55)
|
||||
|
||||
Graphics.setColor(Graphics.kColorBlack)
|
||||
|
||||
end
|
||||
|
||||
function scene:exit()
|
||||
scene.super.exit(self)
|
||||
self.sequence = Sequence.new():from(self.menuY):to(self.menuYTo, 0.5, Ease.inSine)
|
||||
self.sequence:start();
|
||||
end
|
||||
|
||||
function scene:setupMenu(__menu)
|
||||
__menu:addItem("Start", function() Noble.transition(Game, nil, Noble.Transition.DipToWhite) end)
|
||||
__menu:addItem("Tutorial", function() return end)
|
||||
__menu:addItem("Credits", function() return end)
|
||||
__menu:select("Start")
|
||||
end
|
Reference in New Issue
Block a user