2025-02-24 13:15:12 +01:00
|
|
|
import "CoreLibs/object"
|
|
|
|
import "CoreLibs/graphics"
|
|
|
|
import "CoreLibs/sprites"
|
|
|
|
import "CoreLibs/timer"
|
|
|
|
|
|
|
|
local gfx <const> = playdate.graphics
|
|
|
|
|
|
|
|
local playerSprite = nil
|
2025-03-04 13:57:34 +01:00
|
|
|
local atlas = nil
|
2025-02-24 13:15:12 +01:00
|
|
|
|
2025-03-04 13:57:34 +01:00
|
|
|
function gameInit()
|
|
|
|
local playerImage = gfx.image.new("img/player")
|
2025-02-28 14:05:37 +01:00
|
|
|
assert(playerImage)
|
2025-02-26 14:53:32 +01:00
|
|
|
|
|
|
|
playerSprite = gfx.sprite.new(playerImage)
|
2025-02-28 14:05:37 +01:00
|
|
|
playerSprite:moveTo(200, 120) -- (200,120) is the center of the Playdate screen
|
|
|
|
playerSprite:add()
|
2025-02-26 14:53:32 +01:00
|
|
|
|
2025-03-04 13:57:34 +01:00
|
|
|
atlas = gfx.imagetable.new("img/bg_atlas")
|
2025-02-24 13:15:12 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
-- Now we'll call the function above to configure our game.
|
|
|
|
-- After this runs (it just runs once), nearly everything will be
|
|
|
|
-- controlled by the OS calling `playdate.update()` 30 times a second.
|
|
|
|
|
2025-03-04 13:57:34 +01:00
|
|
|
gameInit()
|
2025-02-24 13:15:12 +01:00
|
|
|
|
|
|
|
function playdate.update()
|
2025-02-26 14:53:32 +01:00
|
|
|
-- Poll the d-pad and move our player accordingly.
|
|
|
|
-- (There are multiple ways to read the d-pad; this is the simplest.)
|
|
|
|
-- Note that it is possible for more than one of these directions
|
|
|
|
-- to be pressed at once, if the user is pressing diagonally.
|
|
|
|
|
|
|
|
if playdate.buttonIsPressed(playdate.kButtonUp) then
|
|
|
|
playerSprite:moveBy(0, -2)
|
|
|
|
end
|
|
|
|
if playdate.buttonIsPressed(playdate.kButtonRight) then
|
|
|
|
playerSprite:moveBy(2, 0)
|
|
|
|
end
|
|
|
|
if playdate.buttonIsPressed(playdate.kButtonDown) then
|
|
|
|
playerSprite:moveBy(0, 2)
|
|
|
|
end
|
|
|
|
if playdate.buttonIsPressed(playdate.kButtonLeft) then
|
|
|
|
playerSprite:moveBy(-2, 0)
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Call the functions below in playdate.update() to draw sprites and keep
|
|
|
|
-- timers updated. (We aren't using timers in this example, but in most
|
|
|
|
-- average-complexity games, you will.)
|
|
|
|
|
|
|
|
gfx.sprite.update()
|
|
|
|
playdate.timer.updateTimers()
|
2025-03-04 13:57:34 +01:00
|
|
|
atlas:drawImage(1, 32, 32)
|
2025-02-24 13:15:12 +01:00
|
|
|
end
|