From 8b37eeaddf48ea2efc2dfc1c607abea9abb1e7ee Mon Sep 17 00:00:00 2001 From: Stephen Seo Date: Sat, 29 Apr 2023 12:20:04 +0900 Subject: [PATCH] Add car sprites --- src/helpers.rs | 19 ++++++++++++++++ src/lib.rs | 21 ++++++++++++++++++ src/sprites.rs | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 100 insertions(+) create mode 100644 src/sprites.rs diff --git a/src/helpers.rs b/src/helpers.rs index 3047e78..9b448d0 100644 --- a/src/helpers.rs +++ b/src/helpers.rs @@ -1,3 +1,7 @@ +static mut car_state: u8 = 0; +static mut car_state_frames: u8 = 0; +const CAR_FRAMES: u8 = 10; + pub fn fill(color: u8) { if color > 3 { crate::trace("ERROR: Invalid value passed to helper \"fill\""); @@ -22,3 +26,18 @@ pub fn draw_mouse() -> Option<(i16, i16)> { None } } + +pub fn toggle_car_state() -> bool { + unsafe { + car_state_frames += 1; + if car_state_frames >= CAR_FRAMES { + car_state_frames = 0; + if car_state == 0 { + car_state = 1; + } else { + car_state = 0; + } + } + car_state != 0 + } +} diff --git a/src/lib.rs b/src/lib.rs index 86c1fd6..6c038d6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -4,6 +4,7 @@ mod wasm4; use wasm4::*; mod helpers; +mod sprites; #[rustfmt::skip] const SMILEY: [u8; 8] = [ @@ -32,5 +33,25 @@ fn update() { blit(&SMILEY, 76, 76, 8, 8, BLIT_1BPP); text("Press X to blink", 16, 90); + unsafe { *DRAW_COLORS = 0x312 } + if helpers::toggle_car_state() { + blit( + &sprites::CAR0, + 50, + 40, + sprites::CAR0_WIDTH, + sprites::CAR0_HEIGHT, + sprites::CAR0_FLAGS, + ); + } else { + blit( + &sprites::CAR1, + 50, + 40, + sprites::CAR1_WIDTH, + sprites::CAR1_HEIGHT, + sprites::CAR1_FLAGS, + ); + } if let Some((x, y)) = helpers::draw_mouse() {} } diff --git a/src/sprites.rs b/src/sprites.rs new file mode 100644 index 0000000..551ef18 --- /dev/null +++ b/src/sprites.rs @@ -0,0 +1,60 @@ +// car0 +pub const CAR0_WIDTH: u32 = 48; +pub const CAR0_HEIGHT: u32 = 32; +pub const CAR0_FLAGS: u32 = 1; // BLIT_2BPP +pub const CAR0: [u8; 384] = [ + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x3f, 0xff, 0xff, 0xfc, 0xa8, 0x0a, 0xaa, 0xaa, 0x00, 0x00, 0xaa, 0xaa, 0x1f, 0xff, 0xff, + 0xf0, 0x00, 0x0a, 0xaa, 0xaa, 0x80, 0x02, 0xaa, 0xaa, 0x1f, 0xff, 0xff, 0xf2, 0xa8, 0x0a, 0xaa, + 0xaa, 0x80, 0x02, 0xaa, 0xaa, 0x17, 0xff, 0xff, 0xc0, 0x00, 0x0a, 0xaa, 0xaa, 0xa0, 0x0a, 0xaa, + 0xaa, 0x15, 0xff, 0xff, 0xca, 0xa8, 0x0a, 0xaa, 0xaa, 0xa0, 0x0a, 0xaa, 0xaa, 0x15, 0xff, 0xff, + 0xc0, 0x00, 0x0a, 0xaa, 0xaa, 0xa0, 0x0a, 0xaa, 0xaa, 0x15, 0x7f, 0xff, 0xca, 0xa8, 0x0a, 0xaa, + 0xaa, 0xa0, 0x0a, 0xaa, 0xaa, 0x15, 0x5f, 0xff, 0xc0, 0x00, 0x0a, 0xaa, 0xaa, 0xa0, 0x0a, 0xaa, + 0xaa, 0x15, 0x5f, 0xff, 0xca, 0xa8, 0x0a, 0xaa, 0xaa, 0xa0, 0x0a, 0xaa, 0xaa, 0x15, 0x57, 0xff, + 0xc0, 0x00, 0x0a, 0xaa, 0xaa, 0xa0, 0x0a, 0xaa, 0xaa, 0x15, 0x55, 0xff, 0xca, 0xa8, 0x0a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, 0x00, 0x13, 0x80, 0x00, 0x00, 0x2c, 0x40, 0x04, 0xe2, 0xa3, 0xc0, 0xb1, 0x00, 0x13, + 0x80, 0x00, 0x00, 0x2c, 0x40, 0x04, 0xe0, 0x03, 0xff, 0xfc, 0x40, 0x4f, 0xff, 0xff, 0xff, 0xff, + 0x10, 0x13, 0xff, 0xff, 0xff, 0xff, 0x00, 0x3f, 0xff, 0xff, 0xff, 0xff, 0xc0, 0x0f, 0xff, 0xff, +]; +// car1 +pub const CAR1_WIDTH: u32 = 48; +pub const CAR1_HEIGHT: u32 = 32; +pub const CAR1_FLAGS: u32 = 1; // BLIT_2BPP +pub const CAR1: [u8; 384] = [ + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0xff, 0xff, 0xfc, 0xa8, 0x0a, 0xaa, 0xaa, 0x00, 0x00, 0xaa, + 0xaa, 0x1f, 0xff, 0xff, 0xf0, 0x00, 0x0a, 0xaa, 0xaa, 0x80, 0x02, 0xaa, 0xaa, 0x1f, 0xff, 0xff, + 0xf2, 0xa8, 0x0a, 0xaa, 0xaa, 0x80, 0x02, 0xaa, 0xaa, 0x17, 0xff, 0xff, 0xc0, 0x00, 0x0a, 0xaa, + 0xaa, 0xa0, 0x0a, 0xaa, 0xaa, 0x15, 0xff, 0xff, 0xca, 0xa8, 0x0a, 0xaa, 0xaa, 0xa0, 0x0a, 0xaa, + 0xaa, 0x15, 0xff, 0xff, 0xc0, 0x00, 0x0a, 0xaa, 0xaa, 0xa0, 0x0a, 0xaa, 0xaa, 0x15, 0x7f, 0xff, + 0xca, 0xa8, 0x0a, 0xaa, 0xaa, 0xa0, 0x0a, 0xaa, 0xaa, 0x15, 0x5f, 0xff, 0xc0, 0x00, 0x0a, 0xaa, + 0xaa, 0xa0, 0x0a, 0xaa, 0xaa, 0x15, 0x5f, 0xff, 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