This commit is contained in:
Crispy 2024-10-07 00:08:06 +02:00
parent b13d7aaf6d
commit 098dc9517d
2 changed files with 13 additions and 12 deletions

View file

@ -215,23 +215,24 @@ impl Board {
pub fn draw(&self, d: &mut RaylibDrawHandle, textures: &Textures, offset: Vector2, zoom: i32) { pub fn draw(&self, d: &mut RaylibDrawHandle, textures: &Textures, offset: Vector2, zoom: i32) {
let tile_size = 16 << zoom; 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 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; let tile_height = d.get_screen_height() / tile_size + 2;
for x in start_x..(start_x + tile_width) { for x in start_x..(start_x + tile_width) {
for y in start_y..(start_y + tile_height) { for y in start_y..(start_y + tile_height) {
if self.in_bounds(Pos { let tx = (x as isize + self.offset_x) as usize;
x: x as isize, let ty = (y as isize + self.offset_y) as usize;
y: y as isize, if self.in_bounds((tx, ty).into()) {
}) {
let tx = x as usize;
let ty = y as usize;
let tile = self.rows[ty][tx]; let tile = self.rows[ty][tx];
let px = (x - self.offset_x as i32) * tile_size + offset.x as i32; let texname = tile.texture();
let py = (y - self.offset_y as i32) * tile_size + offset.y as i32; if texname == "" {
let texture = textures.get(&tile.texture()); 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( d.draw_texture_ex(
texture, texture,
Vector2::new(px as f32, py as f32), Vector2::new(px as f32, py as f32),

View file

@ -162,7 +162,7 @@ impl Tile {
pub fn texture(&self) -> String { pub fn texture(&self) -> String {
match self { match self {
Tile::Blank => "transparent", Tile::Blank => "",
Tile::Block => "block", Tile::Block => "block",
Tile::Marble { value: _, dir: _ } => "marble", Tile::Marble { value: _, dir: _ } => "marble",
Tile::Digit(n) => return format!("digit_{n}"), Tile::Digit(n) => return format!("digit_{n}"),