rush/src/main.lua
Fabien Freling 4a6437c323 cook assets
2025-03-10 14:05:40 +01:00

52 lines
1.4 KiB
Lua

import "CoreLibs/object"
import "CoreLibs/graphics"
import "CoreLibs/sprites"
import "CoreLibs/timer"
local gfx <const> = playdate.graphics
local playerSprite = nil
local atlas = nil
function gameInit()
local playerImage = gfx.image.new("img/player")
assert(playerImage)
playerSprite = gfx.sprite.new(playerImage)
playerSprite:moveTo(200, 120) -- (200,120) is the center of the Playdate screen
playerSprite:add()
atlas = gfx.imagetable.new("img/level_01")
end
gameInit()
function playdate.update()
-- 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.
local speed = 5
if playdate.buttonIsPressed(playdate.kButtonUp) then
playerSprite:moveBy(0, -2)
end
if playdate.buttonIsPressed(playdate.kButtonRight) then
playerSprite:moveBy(speed, 0)
end
if playdate.buttonIsPressed(playdate.kButtonDown) then
playerSprite:moveBy(0, 2)
end
if playdate.buttonIsPressed(playdate.kButtonLeft) then
playerSprite:moveBy(-speed, 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()
atlas:drawImage(2, 32, 32)
end