From 5c54d2d48c06703786b277dc1f2493d36e5710c9 Mon Sep 17 00:00:00 2001 From: Sofia Date: Sat, 13 Sep 2025 19:20:30 +0300 Subject: [PATCH] Create a proto-game --- src/font.rs | 7 ++++++- src/main.rs | 44 +++++++++++++++++++++++++++----------------- 2 files changed, 33 insertions(+), 18 deletions(-) diff --git a/src/font.rs b/src/font.rs index 771f251..88afc59 100644 --- a/src/font.rs +++ b/src/font.rs @@ -124,6 +124,10 @@ pub static COMMA: [u8; 8] = [ 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b01000000, 0b10000000, ]; #[unsafe(link_section = ".progmem.data")] +pub static COLON: [u8; 8] = [ + 0b01100000, 0b01100000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b01100000, 0b01100000, +]; +#[unsafe(link_section = ".progmem.data")] pub static EMPTY: [u8; 8] = [ 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, ]; @@ -208,6 +212,7 @@ fn letter(character: char) -> *const [u8; 8] { '9' => addr_of!(NUM_9), '!' => addr_of!(EXCLAMATION), ',' => addr_of!(COMMA), + ':' => addr_of!(COLON), _ => addr_of!(EMPTY), } } @@ -275,7 +280,7 @@ pub fn draw_number( position: &mut Vec2, scale: u16, ) { - if number > 10 { + if number >= 10 { draw_number(display, number / 10, fg, bg, position, scale); } let character = match number % 10 { diff --git a/src/main.rs b/src/main.rs index 956b104..110cb69 100644 --- a/src/main.rs +++ b/src/main.rs @@ -85,43 +85,53 @@ fn main() -> ! { let mut position = Vec2 { x: 10, y: 10 }; draw_text( &mut display, - "hi,my name is adafruit!nice to meet you!\n", + "how many times can you press the button:\n", Rgb565::white(), Rgb565::black(), &mut position, 3, ); + let mut counter = 0; draw_number( &mut display, - 1234, + counter, Rgb565::white(), Rgb565::black(), - &mut position, + &mut position.clone(), 3, ); loop { if button.poll() { - match draw_image( - &mut serial, - &mut images[idx].iter(), + counter += 1; + draw_number( &mut display, - Vec2 { x: 0, y: 0 }, - ) { - Ok(_) => ufmt::uwriteln!(serial, "Successfully read QOI").unwrap(), - Err(e) => ufmt::uwriteln!(serial, "Error: {:?}", e).unwrap(), - } - - draw_text( - &mut display, - "you just lost the game!", + counter, Rgb565::white(), Rgb565::black(), - &mut Vec2 { x: 10, y: 10 }, + &mut position.clone(), 3, ); + // match draw_image( + // &mut serial, + // &mut images[idx].iter(), + // &mut display, + // Vec2 { x: 0, y: 0 }, + // ) { + // Ok(_) => ufmt::uwriteln!(serial, "Successfully read QOI").unwrap(), + // Err(e) => ufmt::uwriteln!(serial, "Error: {:?}", e).unwrap(), + // } - idx = (idx + 1) % len; + // draw_text( + // &mut display, + // "you just lost the game!", + // Rgb565::white(), + // Rgb565::black(), + // &mut Vec2 { x: 10, y: 10 }, + // 3, + // ); + + // idx = (idx + 1) % len; } } }