From a33a57bd494c427bdc7dbed71173a1a51adab493 Mon Sep 17 00:00:00 2001 From: Zenn Date: Sat, 19 Aug 2023 18:21:14 +0200 Subject: [PATCH] adding drboy --- .gitignore | 2 +- Examples/drboy/src/enemies.rs | 6 ---- Examples/drboy/src/lib.rs | 53 +++++++++++++++++++++++++---- Examples/drboy/src/utils.rs | 21 ------------ arduboy-rust/src/library/progmem.rs | 12 +++++++ run | 1 - 6 files changed, 59 insertions(+), 36 deletions(-) delete mode 100644 Examples/drboy/src/enemies.rs delete mode 100644 Examples/drboy/src/utils.rs diff --git a/.gitignore b/.gitignore index 8d077ce..876a054 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,6 @@ /target /.vscode - +localcommands.txt arduboy-rust/Wrapper-Project/.pio arduboy-rust/Wrapper-Project/lib/*.a arduboy-rust/Wrapper-Project/build/*.hex diff --git a/Examples/drboy/src/enemies.rs b/Examples/drboy/src/enemies.rs deleted file mode 100644 index f5d4199..0000000 --- a/Examples/drboy/src/enemies.rs +++ /dev/null @@ -1,6 +0,0 @@ -use crate::utils::Position; -pub struct Enemy { - counter: u8, - pos: Position, - bitmap: u8, -} diff --git a/Examples/drboy/src/lib.rs b/Examples/drboy/src/lib.rs index 72cf018..de4cf67 100644 --- a/Examples/drboy/src/lib.rs +++ b/Examples/drboy/src/lib.rs @@ -4,19 +4,21 @@ //Include the Arduboy Library #[allow(unused_imports)] use arduboy_rust::prelude::*; + #[allow(dead_code)] const arduboy: Arduboy2 = Arduboy2::new(); -mod enemies; -mod utils; + // Progmem data +// 8x16 + progmem!( - static pills: [u8; _] = [ + pub static pills: [u8; _] = [ // width, height, 8, 8, 0x7e, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x7e, // TILE 00 0x7e, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7e, // TILE 01 0x7e, 0xd5, 0xab, 0xd5, 0xab, 0xd5, 0xab, 0x7e, // TILE 02 ]; - static enemies: [u8; _] = [ + pub static enemies: [u8; _] = [ 8, 8, // width, height, 0xa3, 0x51, 0xa6, 0x51, 0xa1, 0x56, 0xa1, 0x53, // TILE 00 0x7e, 0xdf, 0xb3, 0xdf, 0xbf, 0xd3, 0xbf, 0x7e, // TILE 01 @@ -24,15 +26,26 @@ progmem!( ]; ); // dynamic ram variables +struct Player { + bitmap: *const u8, + bitmap_frame: u8, + x: i16, + y: i16, +} +#[link_section = ".progmem.data"] +static mut p: Player = Player { + bitmap: get_sprite_addr!(enemies), + bitmap_frame: 0, + x: 0, + y: 0, +}; // The setup() function runs once when you turn your Arduboy on #[no_mangle] pub unsafe extern "C" fn setup() { // put your setup code here, to run once: arduboy.begin(); - arduboy.set_frame_rate(20); - arduboy.clear(); - arduboy.display(); + arduboy.set_frame_rate(30); } // The loop() function repeats forever after setup() is done @@ -40,4 +53,30 @@ pub unsafe extern "C" fn setup() { #[export_name = "loop"] pub unsafe extern "C" fn loop_() { // put your main code here, to run repeatedly: + if !arduboy.next_frame() { + return; + } + arduboy.clear(); + sprites::draw_override(p.x, p.y, p.bitmap, p.bitmap_frame); + arduboy.poll_buttons(); + if arduboy.pressed(UP) { + p.y -= 1; + } + if arduboy.pressed(DOWN) { + p.y += 1; + } + if arduboy.pressed(LEFT) { + p.x -= 1; + } + if arduboy.pressed(RIGHT) { + p.x += 1; + } + if arduboy.just_pressed(A) { + p.bitmap_frame += 1; + if p.bitmap_frame > 2 { + p.bitmap_frame = 0 + } + } + + arduboy.display(); } diff --git a/Examples/drboy/src/utils.rs b/Examples/drboy/src/utils.rs deleted file mode 100644 index 3d5834d..0000000 --- a/Examples/drboy/src/utils.rs +++ /dev/null @@ -1,21 +0,0 @@ -pub struct Position { - x: u8, - y: u8, -} - -pub enum Color { - Black(Position), - White(Position), - Gray(Position), -} -pub enum Direction { - Up, - Right, - Down, - Left, -} -pub struct Pills { - pub first_field: Color, - pub second_field: Color, - pub direction: Direction, -} diff --git a/arduboy-rust/src/library/progmem.rs b/arduboy-rust/src/library/progmem.rs index 963cd78..61436d9 100644 --- a/arduboy-rust/src/library/progmem.rs +++ b/arduboy-rust/src/library/progmem.rs @@ -31,6 +31,18 @@ macro_rules! progmem { $($rest)* } }; + ( + $( #[$attr:meta] )* + $v:vis $id:ident mut $name:ident: [$ty:ty; _] = $value:expr; + $($rest:tt)* + ) => { + $( #[$attr] )* + #[link_section = ".progmem.data"] + $v $id mut $name: [$ty; $value.len()] = $value; + $crate::progmem!{ + $($rest)* + } + }; () => () } diff --git a/run b/run index b6597fa..7742601 100755 --- a/run +++ b/run @@ -55,4 +55,3 @@ else echo Usage: for uploading your game \|./run.sh echo Usage: for uploading an example game \| ./run.sh \ fi -