refactor, add simulation controls and board resetting
This commit is contained in:
parent
a9eefcd836
commit
880993762e
4 changed files with 193 additions and 83 deletions
|
@ -1,3 +1,6 @@
|
|||
use std::collections::HashMap;
|
||||
|
||||
use raylib::prelude::*;
|
||||
use super::tile::*;
|
||||
|
||||
#[derive(Debug, Default, Clone, Copy, PartialEq)]
|
||||
|
@ -15,7 +18,7 @@ impl From<(usize, usize)> for Pos {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Board {
|
||||
rows: Vec<Vec<Tile>>,
|
||||
width: usize,
|
||||
|
@ -84,4 +87,23 @@ impl Board {
|
|||
pub fn height(&self) -> usize {
|
||||
self.height
|
||||
}
|
||||
|
||||
pub fn draw(
|
||||
&self,
|
||||
d: &mut RaylibDrawHandle,
|
||||
textures: &HashMap<String, Texture2D>,
|
||||
offset: Vector2,
|
||||
zoom: i32,
|
||||
){
|
||||
let tile_size = 16 << zoom;
|
||||
for x in 0..self.width {
|
||||
for y in 0..self.height {
|
||||
if let Some(tile) = self.get((x, y).into()) {
|
||||
let px = x as i32 * tile_size + offset.x as i32 + tile_size / 2;
|
||||
let py = y as i32 * tile_size + offset.y as i32 + tile_size / 2;
|
||||
tile.draw(d, textures, px, py, tile_size, zoom);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue