This commit is contained in:
Fabien Freling 2025-02-26 14:53:32 +01:00
parent 61b773ac6d
commit c402593a34
6 changed files with 77 additions and 53 deletions

View file

@ -2,11 +2,11 @@
"nodes": {
"nixpkgs": {
"locked": {
"lastModified": 1740126099,
"narHash": "sha256-ozoOtE2hGsqh4XkTJFsrTkNxkRgShxpQxDynaPZUGxk=",
"lastModified": 1740367490,
"narHash": "sha256-WGaHVAjcrv+Cun7zPlI41SerRtfknGQap281+AakSAw=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "32fb99ba93fea2798be0e997ea331dd78167f814",
"rev": "0196c0175e9191c474c26ab5548db27ef5d34b05",
"type": "github"
},
"original": {

View file

@ -12,14 +12,14 @@
outputs = { self, nixpkgs, playdate-sdk }:
let system = "x86_64-linux";
pkgs = nixpkgs.legacyPackages.${system};
stdenv = pkgs.stdenv;
playdate-sdk-pkg = playdate-sdk.packages.${system}.default;
in {
devShell.${system} = with stdenv; with pkgs;
devShell.${system} = with pkgs;
mkShell {
nativeBuildInputs = [
just
lua-language-server
nushell
playdate-sdk-pkg
];
};

View file

@ -1,9 +1,14 @@
bin := "Rush.pdx"
playdate_sdk_version := "2.6.2"
export PLAYDATE_SDK_PATH := x"~/.local/bin/PlaydateSDK-" + playdate_sdk_version
alias b := build
build:
pdc src {{ bin }}
$PLAYDATE_SDK_PATH/bin/pdc src {{ bin }}
alias s := simu
simu: build
PlaydateSimulator {{ bin }}
setup:
tools/download-sdk.nu {{ playdate_sdk_version }}

BIN
src/img/player.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.2 KiB

View file

@ -24,34 +24,32 @@ local playerSprite = nil
-- A function to set up our game environment.
function myGameSetUp()
-- Set up the player sprite.
-- Set up the player sprite.
local playerImage = gfx.image.new("img/player.png")
assert(playerImage) -- make sure the image was where we thought
local playerImage = gfx.image.new("Images/playerImage")
assert( playerImage ) -- make sure the image was where we thought
playerSprite = gfx.sprite.new(playerImage)
playerSprite:moveTo(200, 120) -- this is where the center of the sprite is placed; (200,120) is the center of the Playdate screen
playerSprite:add() -- This is critical!
playerSprite = gfx.sprite.new( playerImage )
playerSprite:moveTo( 200, 120 ) -- this is where the center of the sprite is placed; (200,120) is the center of the Playdate screen
playerSprite:add() -- This is critical!
-- We want an environment displayed behind our sprite.
-- There are generally two ways to do this:
-- 1) Use setBackgroundDrawingCallback() to draw a background image. (This is what we're doing below.)
-- 2) Use a tilemap, assign it to a sprite with sprite:setTilemap(tilemap),
-- and call :setZIndex() with some low number so the background stays behind
-- your other sprites.
-- We want an environment displayed behind our sprite.
-- There are generally two ways to do this:
-- 1) Use setBackgroundDrawingCallback() to draw a background image. (This is what we're doing below.)
-- 2) Use a tilemap, assign it to a sprite with sprite:setTilemap(tilemap),
-- and call :setZIndex() with some low number so the background stays behind
-- your other sprites.
local backgroundImage = gfx.image.new( "Images/background" )
assert( backgroundImage )
gfx.sprite.setBackgroundDrawingCallback(
function( x, y, width, height )
-- x,y,width,height is the updated area in sprite-local coordinates
-- The clip rect is already set to this area, so we don't need to set it ourselves
backgroundImage:draw( 0, 0 )
end
)
-- local backgroundImage = gfx.image.new("Images/background")
-- assert(backgroundImage)
-- gfx.sprite.setBackgroundDrawingCallback(
-- function(x, y, width, height)
-- -- x,y,width,height is the updated area in sprite-local coordinates
-- -- The clip rect is already set to this area, so we don't need to set it ourselves
-- backgroundImage:draw(0, 0)
-- end
-- )
end
-- Now we'll call the function above to configure our game.
@ -65,31 +63,28 @@ myGameSetUp()
-- Use this function to poll input, run game logic, and move sprites.
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.
-- 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
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()
-- 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()
end

24
tools/download-sdk.nu Executable file
View file

@ -0,0 +1,24 @@
#!/usr/bin/env nu
def main [version: string] {
let sdk_path = $"~/.local/bin/PlaydateSDK-($version)" | path expand
if ($sdk_path | path exists) {
print $"SDK already installed at ($sdk_path)"
return
}
let sdk_url = $"https://download.panic.com/playdate_sdk/Linux/PlaydateSDK-($version).tar.gz"
let out_path = mktemp --tmpdir $"PlaydateSDK-($version)-XXX.tar.gz"
http get $sdk_url | save --raw --progress --force $out_path
let parent_dir = $sdk_path | path dirname
mkdir $parent_dir
let uncompress = tar xf $out_path --directory $parent_dir | complete
if $uncompress.exit_code != 0 {
print --stderr $uncompress.stderr
exit 1
}
run-external sudo $"($sdk_path)/setup.sh"
}