diff --git a/assets/digits/digit_0.png b/assets/digits/digit_0.png new file mode 100644 index 0000000..7e82ea3 Binary files /dev/null and b/assets/digits/digit_0.png differ diff --git a/assets/digits/digit_1.png b/assets/digits/digit_1.png new file mode 100644 index 0000000..fb46b47 Binary files /dev/null and b/assets/digits/digit_1.png differ diff --git a/assets/digits/digit_2.png b/assets/digits/digit_2.png new file mode 100644 index 0000000..f85cbb0 Binary files /dev/null and b/assets/digits/digit_2.png differ diff --git a/assets/digits/digit_3.png b/assets/digits/digit_3.png new file mode 100644 index 0000000..d2a8bb8 Binary files /dev/null and b/assets/digits/digit_3.png differ diff --git a/assets/digits/digit_4.png b/assets/digits/digit_4.png new file mode 100644 index 0000000..b329613 Binary files /dev/null and b/assets/digits/digit_4.png differ diff --git a/assets/digits/digit_5.png b/assets/digits/digit_5.png new file mode 100644 index 0000000..58af1ae Binary files /dev/null and b/assets/digits/digit_5.png differ diff --git a/assets/digits/digit_6.png b/assets/digits/digit_6.png new file mode 100644 index 0000000..f664c5f Binary files /dev/null and b/assets/digits/digit_6.png differ diff --git a/assets/digits/digit_7.png b/assets/digits/digit_7.png new file mode 100644 index 0000000..183672e Binary files /dev/null and b/assets/digits/digit_7.png differ diff --git a/assets/digits/digit_8.png b/assets/digits/digit_8.png new file mode 100644 index 0000000..a952a71 Binary files /dev/null and b/assets/digits/digit_8.png differ diff --git a/assets/digits/digit_9.png b/assets/digits/digit_9.png new file mode 100644 index 0000000..d44e102 Binary files /dev/null and b/assets/digits/digit_9.png differ diff --git a/assets/tiles/digit_0.png b/assets/tiles/tile_digit_0.png similarity index 100% rename from assets/tiles/digit_0.png rename to assets/tiles/tile_digit_0.png diff --git a/assets/tiles/digit_1.png b/assets/tiles/tile_digit_1.png similarity index 100% rename from assets/tiles/digit_1.png rename to assets/tiles/tile_digit_1.png diff --git a/assets/tiles/digit_2.png b/assets/tiles/tile_digit_2.png similarity index 100% rename from assets/tiles/digit_2.png rename to assets/tiles/tile_digit_2.png diff --git a/assets/tiles/digit_3.png b/assets/tiles/tile_digit_3.png similarity index 100% rename from assets/tiles/digit_3.png rename to assets/tiles/tile_digit_3.png diff --git a/assets/tiles/digit_4.png b/assets/tiles/tile_digit_4.png similarity index 100% rename from assets/tiles/digit_4.png rename to assets/tiles/tile_digit_4.png diff --git a/assets/tiles/digit_5.png b/assets/tiles/tile_digit_5.png similarity index 100% rename from assets/tiles/digit_5.png rename to assets/tiles/tile_digit_5.png diff --git a/assets/tiles/digit_6.png b/assets/tiles/tile_digit_6.png similarity index 100% rename from assets/tiles/digit_6.png rename to assets/tiles/tile_digit_6.png diff --git a/assets/tiles/digit_7.png b/assets/tiles/tile_digit_7.png similarity index 100% rename from assets/tiles/digit_7.png rename to assets/tiles/tile_digit_7.png diff --git a/assets/tiles/digit_8.png b/assets/tiles/tile_digit_8.png similarity index 100% rename from assets/tiles/digit_8.png rename to assets/tiles/tile_digit_8.png diff --git a/assets/tiles/digit_9.png b/assets/tiles/tile_digit_9.png similarity index 100% rename from assets/tiles/digit_9.png rename to assets/tiles/tile_digit_9.png diff --git a/src/editor.rs b/src/editor.rs index 84f05b7..7664e9b 100644 --- a/src/editor.rs +++ b/src/editor.rs @@ -3,7 +3,7 @@ use std::{mem::transmute, ops::Rem}; use raylib::prelude::*; use crate::{ - draw_scaled_texture, + draw_scaled_texture, draw_usize, level::Level, marble_engine::{ board::{Board, Pos}, @@ -128,7 +128,7 @@ impl Editor { self.machine.set_board(self.source_board.clone()); } - fn step_pressed(&mut self){ + fn step_pressed(&mut self) { match self.sim_state { SimState::Editing => { self.start_sim(); @@ -419,6 +419,8 @@ impl Editor { } draw_scaled_texture(d, textures.get("step"), 332, 4, 2.); + draw_usize(d, textures, self.machine.step_count(), 372, 4, 5, 2); + let mut input_text = String::from_utf8_lossy(self.machine.input()).to_string(); let width = d.get_screen_width(); d.draw_text("input:", width - 260, 10, 20, Color::WHITE); diff --git a/src/main.rs b/src/main.rs index 6c312bc..6a41bdb 100644 --- a/src/main.rs +++ b/src/main.rs @@ -46,6 +46,7 @@ impl Game { let mut textures = Textures::default(); textures.load_dir("assets", rl, thread); textures.load_dir("assets/tiles", rl, thread); + textures.load_dir("assets/digits", rl, thread); Self { levels: get_levels(), @@ -237,7 +238,7 @@ fn get_levels() -> Vec { levels.push(level); } } - levels.sort_by(|a, b| a.sort_order().cmp(&b.sort_order())); + levels.sort_by_key(Level::sort_order); levels } diff --git a/src/marble_engine/tile.rs b/src/marble_engine/tile.rs index c2c3e89..0d793ef 100644 --- a/src/marble_engine/tile.rs +++ b/src/marble_engine/tile.rs @@ -165,7 +165,7 @@ impl Tile { Tile::Blank => "", Tile::Block => "block", Tile::Marble { value: _, dir: _ } => "marble", - Tile::Digit(n) => return format!("digit_{n}"), + Tile::Digit(n) => return format!("tile_digit_{n}"), Tile::Mirror(mirror) => mirror.texture_name(), Tile::Arrow(dir) => dir.arrow_texture_name(), Tile::Powerable(tile, state) => { diff --git a/src/util.rs b/src/util.rs index db83739..5e2f1aa 100644 --- a/src/util.rs +++ b/src/util.rs @@ -121,7 +121,8 @@ pub fn text_input( Color::WHITE, ); let mouse_pos = d.get_mouse_position(); - if editable && d.is_mouse_button_pressed(MouseButton::MOUSE_BUTTON_LEFT) + if editable + && d.is_mouse_button_pressed(MouseButton::MOUSE_BUTTON_LEFT) && (bounds.check_collision_point_rec(mouse_pos) || *is_selected) { *is_selected = !*is_selected; @@ -189,6 +190,31 @@ pub fn texture_option_button( } } +pub fn draw_usize( + d: &mut RaylibDrawHandle, + textures: &Textures, + number: usize, + x: i32, + y: i32, + digits: u8, + scale: u8, +) { + let digits = digits as i32; + let scale = scale as i32; + for i in 0..digits { + d.draw_rectangle(x + 10 * i * scale, y, 8 * scale, 16 * scale, Color::DIMGRAY); + } + let mut num = number; + let mut i = 0; + while (num != 0 || i == 0) && i < digits { + let texture = textures.get(&format!("digit_{}", num % 10)); + let x = x + (digits - i - 1) * 10 * scale; + draw_scaled_texture(d, texture, x, y, scale as f32); + num /= 10; + i += 1; + } +} + pub fn userdata_dir() -> PathBuf { PathBuf::from("user") }