From 65db708e6105c281ba18662670cac3200470886f Mon Sep 17 00:00:00 2001 From: ZennDev1337 Date: Wed, 20 Sep 2023 14:05:43 +0200 Subject: [PATCH] added demo9 --- Cargo.lock | 7 + Cargo.toml | 1 + Examples/Arduboy-Tutorials/demo9/Cargo.toml | 11 + .../Arduboy-Tutorials/demo9/assets/GRASS.png | Bin 0 -> 118 bytes .../Arduboy-Tutorials/demo9/assets/STONE.png | Bin 0 -> 134 bytes .../Arduboy-Tutorials/demo9/assets/TREES.png | Bin 0 -> 131 bytes .../Arduboy-Tutorials/demo9/assets/WATER.png | Bin 0 -> 108 bytes Examples/Arduboy-Tutorials/demo9/src/lib.rs | 207 ++++++++++++++++++ README.md | 4 +- run | 49 +---- run.bat | 37 +--- 11 files changed, 243 insertions(+), 73 deletions(-) create mode 100644 Examples/Arduboy-Tutorials/demo9/Cargo.toml create mode 100644 Examples/Arduboy-Tutorials/demo9/assets/GRASS.png create mode 100644 Examples/Arduboy-Tutorials/demo9/assets/STONE.png create mode 100644 Examples/Arduboy-Tutorials/demo9/assets/TREES.png create mode 100644 Examples/Arduboy-Tutorials/demo9/assets/WATER.png create mode 100644 Examples/Arduboy-Tutorials/demo9/src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index 22907c5..67e6e0f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -86,6 +86,13 @@ dependencies = [ "arduboy-rust", ] +[[package]] +name = "demo9" +version = "0.1.0" +dependencies = [ + "arduboy-rust", +] + [[package]] name = "drboy" version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml index 6ece195..9aa17d1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,6 +11,7 @@ members = [ "Examples/Arduboy-Tutorials/demo5", "Examples/Arduboy-Tutorials/demo6", "Examples/Arduboy-Tutorials/demo7", + "Examples/Arduboy-Tutorials/demo9", "Examples/drboy", "Examples/ardvoice", "Examples/rustacean", diff --git a/Examples/Arduboy-Tutorials/demo9/Cargo.toml b/Examples/Arduboy-Tutorials/demo9/Cargo.toml new file mode 100644 index 0000000..2071360 --- /dev/null +++ b/Examples/Arduboy-Tutorials/demo9/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "demo9" +version = "0.1.0" +authors = ["ZennDev "] +edition = "2021" + +[lib] +crate-type = ["staticlib"] + +[dependencies] +arduboy-rust = { path = "../../../arduboy-rust" } diff --git a/Examples/Arduboy-Tutorials/demo9/assets/GRASS.png b/Examples/Arduboy-Tutorials/demo9/assets/GRASS.png new file mode 100644 index 0000000000000000000000000000000000000000..6634a1a3123db0458f08c6969690f587155274a6 GIT binary patch literal 118 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!D3?x-;bCrM;TYyi9E0F&G|NqjP^X~##+MX_s zAsn)-2Mq-eC@?T={C<}))5Fopovn}CGiB?O?iU&N&b+uk@uI-n-wY>;WJ~*+SPOyL O7(8A5T-G@yGywp-&LmF& literal 0 HcmV?d00001 diff --git a/Examples/Arduboy-Tutorials/demo9/assets/STONE.png b/Examples/Arduboy-Tutorials/demo9/assets/STONE.png new file mode 100644 index 0000000000000000000000000000000000000000..01028e52397cb764a7cf0e202f6a6669c622fd18 GIT binary patch literal 134 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!D3?x-;bCrM;TYyi9E0F&G|NqjP^X~##)}Aho zAsn)d1`Ox_1BDs>-)Fd2&+vCQ!>{`c+xZ!ueP=lNn&HlChIz9Y*5xv+`^vEOCqwsV eh7bG<|NmyMkYqP)Iu!{thQZU-&t;ucLK6V`3N5Pu literal 0 HcmV?d00001 diff --git a/Examples/Arduboy-Tutorials/demo9/assets/TREES.png b/Examples/Arduboy-Tutorials/demo9/assets/TREES.png new file mode 100644 index 0000000000000000000000000000000000000000..62a85cdee4ae532d932b3d0e7382e9429ecf7099 GIT binary patch literal 131 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!D3?x-;bCrM;TYyi9E0F&G|NqjP^X~##7M?DS zAsn)-2M_Wx2ne_yyuOJmL?OCCDrK?MaovNSGA;RRox(jwqTl%0Rvc4PoELC#PFjS3 b(|6|TA}RIX?-Q;9&0z3!^>bP0l+XkKT*@b9 literal 0 HcmV?d00001 diff --git a/Examples/Arduboy-Tutorials/demo9/assets/WATER.png b/Examples/Arduboy-Tutorials/demo9/assets/WATER.png new file mode 100644 index 0000000000000000000000000000000000000000..db486e205cfa8ce2b0d2d626a27c76af6ad276a1 GIT binary patch literal 108 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!D3?x-;bCrM;TYyi9E0F&G|NqjP^X~##ik>cx zAsp9}6B-&d`FL*f7RWK57GZnF!&1(~?aX96fsG+*CiAZ4!ur>MiWxjz{an^LB{Ts5 D= 0 + && tilesy >= 0 + && tilesx < WORLD_WIDTH as i16 + && tilesy < WORLD_HEIGHT as i16 + { + sprites::draw_override( + x * TILE_SIZE as i16 + mapx % TILE_SIZE as i16, + y * TILE_SIZE as i16 + mapy % TILE_SIZE as i16, + get_sprite_addr!(tiles), + world[tilesy as usize][tilesx as usize], + ) + } + } + } + arduboy.fill_rect(0, 0, 48, 8, Color::Black); + arduboy.set_cursor(0, 0); + arduboy.print(0 - mapx / TILE_SIZE as i16); + arduboy.print(f!(b",\0")); + arduboy.print(0 - mapy / TILE_SIZE as i16) +} +fn titlescreen() { + arduboy.set_cursor(0, 0); + arduboy.print(f!(b"Title Screen\n\0")); + if arduboy.just_pressed(A_BUTTON) { + unsafe { gamestate.update(Gamestate::GamePlay) } + } +} +unsafe fn player_input() { + if arduboy.pressed(UP) { + if mapy < PLAYER_Y_OFFSET { + mapy += 1 + } + } + if arduboy.pressed(DOWN) { + if PLAYER_Y_OFFSET + PLAYER_SIZE < mapy + TILE_SIZE as i16 * WORLD_HEIGHT as i16 { + mapy -= 1 + } + } + if arduboy.pressed(LEFT) { + if mapx < PLAYER_X_OFFSET { + mapx += 1 + } + } + if arduboy.pressed(RIGHT) { + if PLAYER_X_OFFSET + PLAYER_SIZE < mapx + TILE_SIZE as i16 * WORLD_WIDTH as i16 { + mapx -= 1 + } + } +} +unsafe fn gameplay() { + player_input(); + draw_world(); + draw_player(); + if arduboy.just_pressed(A_BUTTON) { + unsafe { gamestate.update(Gamestate::GameOver) } + } +} +fn gameover_screen() { + arduboy.set_cursor(0, 0); + arduboy.print(f!(b"Game Over Screen\n\0")); + if arduboy.just_pressed(A_BUTTON) { + unsafe { gamestate.update(Gamestate::GameHigh) } + } +} +fn highscore_screen() { + arduboy.set_cursor(0, 0); + arduboy.print(f!(b"High Score Screen\n\0")); + if arduboy.just_pressed(A_BUTTON) { + unsafe { gamestate.update(Gamestate::GameTitle) } + } +} + +unsafe fn gameloop() { + match unsafe { gamestate } { + Gamestate::GameTitle => titlescreen(), + Gamestate::GamePlay => gameplay(), + Gamestate::GameOver => gameover_screen(), + Gamestate::GameHigh => highscore_screen(), + } +} diff --git a/README.md b/README.md index a92b745..6d2668b 100644 --- a/README.md +++ b/README.md @@ -146,7 +146,8 @@ Windows: - [demo6] [Make Your Own Arduboy Game: Part 6 - Graphics!](https://community.arduboy.com/t/make-your-own-arduboy-game-part-6-graphics/7929) Link for the [ZennDev1337 Tile Converter](https://zenndev1337.github.io/Rust-for-Arduboy/tile-converter.html) - [demo7] [Make Your Own Arduboy Game: Part 7 - Make Pong From Scratch!](https://community.arduboy.com/t/make-your-own-arduboy-game-part-7-make-pong-from-scratch/7930) -- not done [demo8] [Make Your Own Arduboy Game: Part 8 - Starting DinoSmasher](https://community.arduboy.com/t/make-your-own-arduboy-game-part-8-starting-dinosmasher/7932) +- Prepare for demo9 [Make Your Own Arduboy Game: Part 8 - Starting DinoSmasher](https://community.arduboy.com/t/make-your-own-arduboy-game-part-8-starting-dinosmasher/7932) +- [demo9] [Make Your Own Arduboy Game: Part 9 - Mapping DinoSmasher](https://community.arduboy.com/t/make-your-own-arduboy-game-part-9-mapping-dinosmasher/7931) - [eeprom] [Help, I’m struggling with EEPROM!](https://community.arduboy.com/t/help-im-struggling-with-eeprom/7178) - [progmem] Usage of the big 28'000 Bytes flash memory for Bitmaps Sound sequeces and Text. - [tone] [ArduboyTonesTest](https://github.com/MLXXXp/ArduboyTones/blob/master/examples/ArduboyTonesTest/ArduboyTonesTest.ino) @@ -162,6 +163,7 @@ Linux: ./run demo5 ./run demo6 ./run demo7 +./run demo9 ./run eeprom ./run eeprom-byte ./run progmem diff --git a/run b/run index dc8a191..a1c2d54 100755 --- a/run +++ b/run @@ -5,6 +5,14 @@ option=$1 upload(){ cargo build -p $option --release && cp ./target/arduboy/release/lib$option.a ./arduboy-rust/Wrapper-Project/lib/libgame.a && cd arduboy-rust/Wrapper-Project/ && pio run -v -t upload && cp ./.pio/build/arduboy/firmware.hex ./build/$option.hex && pio run -t clean && rm lib/libgame.a && cd ../../ } +start(){ + if upload ; then + echo "all fine" + else + echo Usage: for uploading your game \|./run.sh + echo Usage: for uploading an example game \| ./run.sh \ + fi +} if [ -z "$option" ] then @@ -12,50 +20,11 @@ then elif [ "$option" = "doc" ] then cargo doc -p arduboy-rust && rm -r ./docs/doc/ && cp -r ./target/arduboy/doc ./docs/ -elif [ "$option" = "snake" ] -then - upload -elif [ "$option" = "drboy" ] -then - upload -elif [ "$option" = "ardvoice" ] -then - upload -elif [ "$option" = "rustacean" ] -then - upload -elif [ "$option" = "tone" ] -then - upload -elif [ "$option" = "eeprom" ] -then - upload elif [ "$option" = "eeprom-byte" ] then cargo build -p eeprom-byte --release && cp ./target/arduboy/release/libeeprom_byte.a ./arduboy-rust/Wrapper-Project/lib/libgame.a && cd arduboy-rust/Wrapper-Project/ && pio run -v -t upload && cp ./.pio/build/arduboy/firmware.hex ./build/eeprom-byte.hex && pio run -t clean && rm lib/libgame.a && cd ../../ -elif [ "$option" = "progmem" ] -then - upload -elif [ "$option" = "demo2" ] -then - upload -elif [ "$option" = "demo3" ] -then - upload -elif [ "$option" = "demo4" ] -then - upload -elif [ "$option" = "demo5" ] -then - upload -elif [ "$option" = "demo6" ] -then - upload -elif [ "$option" = "demo7" ] -then - upload else - upload + start # echo Usage: for uploading your game \|./run.sh # echo Usage: for uploading an example game \| ./run.sh \ fi diff --git a/run.bat b/run.bat index f80675b..62e2677 100644 --- a/run.bat +++ b/run.bat @@ -5,48 +5,21 @@ set option=%1 if [%option%]==[] ( powershell -Command "cargo build -p game --release; cp ./target/arduboy/release/libgame.a ./arduboy-rust/Wrapper-Project/lib/libgame.a; cd arduboy-rust/Wrapper-Project/; pio run -v -t upload; cp ./.pio/build/arduboy/firmware.hex ./build/game.hex; pio run -t clean; rm lib/libgame.a; cd ../../" goto :eof -) - -if %option%==snake ( - goto :run ) else if %option%==doc ( powershell -Command "cargo doc -p arduboy-rust; rm -r ./docs/doc/; cp -r ./target/arduboy/doc ./docs/" goto :eof -) else if %option%==pong ( - goto :run -) else if %option%==drboy ( - goto :run -) else if %option%==ardvoice ( - goto :run -) else if %option%==rustacean ( - goto :run -) else if %option%==tone ( - goto :run -) else if %option%==eeprom ( - goto :run ) else if %option%==eeprom-byte ( powershell -Command "cargo build -p %option% --release; cp ./target/arduboy/release/libeeprom_byte.a ./arduboy-rust/Wrapper-Project/lib/libgame.a; cd arduboy-rust/Wrapper-Project/; pio run -v -t upload; cp ./.pio/build/arduboy/firmware.hex ./build/%option%.hex; pio run -t clean; rm lib/libgame.a; cd ../../" -goto :eof -) else if %option%==progmem ( - goto :run -) else if %option%==demo2 ( - goto :run -) else if %option%==demo3 ( - goto :run -) else if %option%==demo4 ( - goto :run -) else if %option%==demo5 ( - goto :run -) else if %option%==demo6 ( - goto :run -) else if %option%==demo7 ( - goto :run + goto :eof ) else ( goto :run ) :run -powershell -Command "cargo build -p %option% --release; cp ./target/arduboy/release/lib%option%.a ./arduboy-rust/Wrapper-Project/lib/libgame.a; cd arduboy-rust/Wrapper-Project/; pio run -v -t upload; cp ./.pio/build/arduboy/firmware.hex ./build/%option%.hex; pio run -t clean; rm lib/libgame.a; cd ../../" +powershell -Command "$ErrorActionPreference='Stop'; cargo build -p %option% --release; cp ./target/arduboy/release/lib%option%.a ./arduboy-rust/Wrapper-Project/lib/libgame.a; cd arduboy-rust/Wrapper-Project/; pio run -v -t upload; cp ./.pio/build/arduboy/firmware.hex ./build/%option%.hex; pio run -t clean; rm lib/libgame.a; cd ../../" +if ERRORLEVEL 1 ( + goto :help +) goto :eof :help