diff --git a/assets/digits_small.png b/assets/digits_small.png index a603378..bf31aa0 100644 Binary files a/assets/digits_small.png and b/assets/digits_small.png differ diff --git a/src/marble_engine.rs b/src/marble_engine.rs index c5ad829..9c7fa3e 100644 --- a/src/marble_engine.rs +++ b/src/marble_engine.rs @@ -76,6 +76,7 @@ impl Machine { zoom: i32, ) { let tile_size = 16 << zoom; + let scale = (1 << zoom) as f32; for marble in &self.marbles { let x = marble.x; let y = marble.y; @@ -83,11 +84,10 @@ impl Machine { let px = x as i32 * tile_size + offset.x as i32; let py = y as i32 * tile_size + offset.y as i32; if let Tile::Marble { value, dir } = tile { - let scale = 1 << zoom; let texture = textures.get(dir.arrow_texture_name()); let pos = Vector2::new(px as f32, py as f32); - let faded = Color::new(255, 255, 255, 100); - d.draw_texture_ex(texture, pos, 0., scale as f32, faded); + let faded_white = Color::new(255, 255, 255, 100); + d.draw_texture_ex(texture, pos, 0., scale, faded_white); draw_usize_small(d, textures, value as usize, px, py, scale); } } diff --git a/src/marble_engine/board.rs b/src/marble_engine/board.rs index ae2b8f9..9f69ceb 100644 --- a/src/marble_engine/board.rs +++ b/src/marble_engine/board.rs @@ -232,6 +232,7 @@ impl Board { pub fn draw(&self, d: &mut RaylibDrawHandle, textures: &Textures, offset: Vector2, zoom: i32) { let tile_size = 16 << zoom; + let scale = (1 << zoom) as f32; let start_x = (-offset.x as i32) / tile_size - 1; let tile_width = d.get_screen_width() / tile_size + 2; @@ -240,18 +241,15 @@ impl Board { for x in start_x..(start_x + tile_width) { for y in start_y..(start_y + tile_height) { - let tx = x as usize; - let ty = y as usize; let px = x * tile_size + offset.x as i32; let py = y * tile_size + offset.y as i32; - if self.in_bounds((tx, ty).into()) { - let tile = self.rows[ty][tx]; + if let Some(tile) = self.get((x, y).into()) { let texname = tile.texture(); if texname.is_empty() { continue; } let texture = textures.get(&texname); - draw_scaled_texture(d, texture, px, py, (1 << zoom) as f32); + draw_scaled_texture(d, texture, px, py, scale); } else { d.draw_rectangle(px, py, tile_size, tile_size, Color::new(0, 0, 0, 80)); } diff --git a/src/marble_engine/pos.rs b/src/marble_engine/pos.rs index 35c945b..3979b3a 100644 --- a/src/marble_engine/pos.rs +++ b/src/marble_engine/pos.rs @@ -40,6 +40,15 @@ impl From<(usize, usize)> for Pos { } } +impl From<(i32, i32)> for Pos { + fn from(value: (i32, i32)) -> Self { + Self { + x: value.0 as isize, + y: value.1 as isize, + } + } +} + impl From for Pos { fn from(vec: Vector2) -> Self { Self { diff --git a/src/util.rs b/src/util.rs index 1c05fe5..0f07167 100644 --- a/src/util.rs +++ b/src/util.rs @@ -224,26 +224,21 @@ pub fn draw_usize_small( mut num: usize, mut x: i32, y: i32, - scale: u8, + scale: f32, ) { const MAX_DIGITS: usize = 8; - let mut digits = [0u8; MAX_DIGITS]; + let mut digits = [0; MAX_DIGITS]; let mut i = 0; while (num != 0 || i == 0) && i < MAX_DIGITS { - digits[MAX_DIGITS - i - 1] = (num % 10) as u8; + digits[MAX_DIGITS - i - 1] = num % 10; num /= 10; i += 1; } let texture = textures.get("digits_small"); - for digit in (MAX_DIGITS - i)..MAX_DIGITS { - d.draw_texture_pro( - texture, - Rectangle::new(4. * digits[digit] as f32, 0., 4., 6.), - Rectangle::new(x as f32, y as f32, 4. * scale as f32, 6. * scale as f32), - Vector2::zero(), - 0., - Color::RED, - ); + for &digit in &digits[(MAX_DIGITS - i)..] { + let source = Rectangle::new(4. * digit as f32, 0., 4., 6.); + let dest = Rectangle::new(x as f32, y as f32, 4. * scale, 6. * scale); + d.draw_texture_pro(texture, source, dest, Vector2::zero(), 0., Color::RED); x += 4 * scale as i32; } }