wrap texture hashmap in a struct for convenience
This commit is contained in:
parent
bf82d1455f
commit
cf920d7a63
3 changed files with 49 additions and 56 deletions
|
@ -1,4 +1,4 @@
|
|||
use std::collections::HashMap;
|
||||
use crate::Textures;
|
||||
|
||||
use super::tile::*;
|
||||
use raylib::prelude::*;
|
||||
|
@ -97,22 +97,14 @@ impl Board {
|
|||
self.height
|
||||
}
|
||||
|
||||
pub fn draw(
|
||||
&self,
|
||||
d: &mut RaylibDrawHandle,
|
||||
textures: &HashMap<String, Texture2D>,
|
||||
offset: Vector2,
|
||||
zoom: i32,
|
||||
) {
|
||||
pub fn draw(&self, d: &mut RaylibDrawHandle, textures: &Textures, 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;
|
||||
let texture = textures
|
||||
.get(&tile.texture())
|
||||
.unwrap_or_else(|| textures.get("missing").unwrap());
|
||||
let texture = textures.get(&tile.texture());
|
||||
d.draw_texture_ex(
|
||||
texture,
|
||||
Vector2::new((px - tile_size / 2) as f32, (py - tile_size / 2) as f32),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue