From c402593a349f746f3d5ccacbc4b0730e408b7c54 Mon Sep 17 00:00:00 2001 From: Fabien Freling Date: Wed, 26 Feb 2025 14:53:32 +0100 Subject: [PATCH] mvp --- flake.lock | 6 +-- flake.nix | 4 +- justfile | 7 +++- src/img/player.png | Bin 0 -> 5368 bytes src/main.lua | 89 ++++++++++++++++++++---------------------- tools/download-sdk.nu | 24 ++++++++++++ 6 files changed, 77 insertions(+), 53 deletions(-) create mode 100644 src/img/player.png create mode 100755 tools/download-sdk.nu diff --git a/flake.lock b/flake.lock index cf6ecea..3af5933 100644 --- a/flake.lock +++ b/flake.lock @@ -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": { diff --git a/flake.nix b/flake.nix index 3a198f9..a1a0df4 100644 --- a/flake.nix +++ b/flake.nix @@ -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 ]; }; diff --git a/justfile b/justfile index 3ece306..e778a6e 100644 --- a/justfile +++ b/justfile @@ -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 }} diff --git a/src/img/player.png b/src/img/player.png new file mode 100644 index 0000000000000000000000000000000000000000..c4722bd1da62c08589aa6b4e87d026aff74095c6 GIT binary patch literal 5368 zcmeHKX;f3!77i+kOf7?ofOrj{fM&WGNFrenkOT-*u;S3ly*D=y$wU$$SfLI$fQpDX zQ~?DMOH~95Pk~a4;7~=2R=S{~^(i=jRXV&OYbt{q23e zv(F|cJ1Qc?%G}YML?T&$YV^#k_fBypxFYM&>@!#acw!(Bg4=l|{LbKD=cGwF zQ8TWYALZ{}`odJ~m~THNq^b7St#fF5)0ssJCoBy3@D(X}N}>J7Wi5m5>n2ybI6uF0 zqw(C0x&DcNjjXmc}S<|Fdf! z7IkTf<&*4|WZ7;`|M>paa;4_xEbHq0BewhOB6sTpZiiIPb~%+yt)KIxHScrL_jVgL zo|yntQwbls72UiT=M7au&k_<1+Y^6u|D@X8;YgKam(tr=%yzTD%$ z7$?T!l$beXa=$BQrYHYtTW7D`(R99gl^5%L<@8q{WTqueDxcX{7C+{GMsnd+22^Fi z>dXB#<01Ew-M535OCKmdt2JrO%>P84bj3B^;B@k&D(QlYrfzK3KFiL6kH3qQc-XIc z&U{hsOxIdi9!YPkeU|)!B>m#>H7kwAZ1WV)Pa7{byySoS@_G2-Q`486(-uvV-l+pA zXpqOo>Ep!Vd`zvRB2qPqQw>TDab6@JKZ6Frl5jnQ;t6t}WnF8D*-Wt5rpe7tz4s*t5pzziJ(J}?lp3*k1YV^Z zW&!X)GawoogG#3#9ou4 zRT#G;#b~$!R{~WX@XC10C2`?KEC>n`+j1B~tkKn$g z{d(_4WuPS%^Mlk_3K5SL@J#gQDHa%1;D9tfWwnw-Z%$ADKLs56c(_gpa@$=VX$Bf<4QS*jO{%N zB2p^{S&1k{M@2wM0Tc$KG7jo3qcFXhG71ZWc@(Y;fhjl>!8s@kW^U!+WFj5w6vNOe8RkrPH`V919<81`vx7c?tlG^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E2ELsik@|!Xtl5->Ix;KaL=^GH`==z z-2&VZRz>EuN2KNCrZurobIPtwtJ-#T@zI}q@eenZ-n()2UrPh*CjK%uer%<*$vTh! z=cEhA%I`nApmNzn?Gd c@zz1p9<$Xv*9Wl|K&c^#f+K<|=f$u2H>KCT?*IS* literal 0 HcmV?d00001 diff --git a/src/main.lua b/src/main.lua index b06ea55..fd08daa 100644 --- a/src/main.lua +++ b/src/main.lua @@ -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 - diff --git a/tools/download-sdk.nu b/tools/download-sdk.nu new file mode 100755 index 0000000..abb9047 --- /dev/null +++ b/tools/download-sdk.nu @@ -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" +}