diff --git a/src/marble_engine/board.rs b/src/marble_engine/board.rs index f764751..bf7aa4d 100644 --- a/src/marble_engine/board.rs +++ b/src/marble_engine/board.rs @@ -215,23 +215,24 @@ impl Board { pub fn draw(&self, d: &mut RaylibDrawHandle, textures: &Textures, offset: Vector2, zoom: i32) { let tile_size = 16 << zoom; - let start_x = (-offset.x as i32) / tile_size + self.offset_x as i32 - 1; + let start_x = (-offset.x as i32) / tile_size - 1; let tile_width = d.get_screen_width() / tile_size + 2; - let start_y = (-offset.y as i32) / tile_size + self.offset_y as i32 - 1; + let start_y = (-offset.y as i32) / tile_size - 1; let tile_height = d.get_screen_height() / tile_size + 2; for x in start_x..(start_x + tile_width) { for y in start_y..(start_y + tile_height) { - if self.in_bounds(Pos { - x: x as isize, - y: y as isize, - }) { - let tx = x as usize; - let ty = y as usize; + let tx = (x as isize + self.offset_x) as usize; + let ty = (y as isize + self.offset_y) as usize; + if self.in_bounds((tx, ty).into()) { let tile = self.rows[ty][tx]; - let px = (x - self.offset_x as i32) * tile_size + offset.x as i32; - let py = (y - self.offset_y as i32) * tile_size + offset.y as i32; - let texture = textures.get(&tile.texture()); + let texname = tile.texture(); + if texname == "" { + continue; + } + let texture = textures.get(&texname); + let px = x * tile_size + offset.x as i32; + let py = y * tile_size + offset.y as i32; d.draw_texture_ex( texture, Vector2::new(px as f32, py as f32), diff --git a/src/marble_engine/tile.rs b/src/marble_engine/tile.rs index 7b5c7f3..c2c3e89 100644 --- a/src/marble_engine/tile.rs +++ b/src/marble_engine/tile.rs @@ -162,7 +162,7 @@ impl Tile { pub fn texture(&self) -> String { match self { - Tile::Blank => "transparent", + Tile::Blank => "", Tile::Block => "block", Tile::Marble { value: _, dir: _ } => "marble", Tile::Digit(n) => return format!("digit_{n}"),