feat!: dynamic map rendering from tiles

This commit is contained in:
2025-08-13 00:25:34 -05:00
parent c1e421bbbb
commit 09e3d85821
89 changed files with 1072 additions and 1024 deletions

View File

@@ -1,5 +1,7 @@
//! Map rendering functionality.
use crate::constants::{BOARD_CELL_OFFSET, CELL_SIZE};
use crate::map::layout::TILE_MAP;
use crate::texture::sprite::{AtlasTile, SpriteAtlas};
use crate::texture::text::TextTexture;
use glam::Vec2;
@@ -17,15 +19,22 @@ impl MapRenderer {
///
/// This function draws the static map texture to the screen at the correct
/// position and scale.
pub fn render_map<T: RenderTarget>(canvas: &mut Canvas<T>, atlas: &mut SpriteAtlas, map_texture: &mut AtlasTile) {
let dest = Rect::new(
crate::constants::BOARD_PIXEL_OFFSET.x as i32,
crate::constants::BOARD_PIXEL_OFFSET.y as i32,
crate::constants::BOARD_PIXEL_SIZE.x,
crate::constants::BOARD_PIXEL_SIZE.y,
);
if let Err(e) = map_texture.render(canvas, atlas, dest) {
tracing::error!("Failed to render map: {}", e);
pub fn render_map<T: RenderTarget>(canvas: &mut Canvas<T>, atlas: &mut SpriteAtlas, map_tiles: &mut [AtlasTile]) {
for (y, row) in TILE_MAP.iter().enumerate() {
for (x, &tile_index) in row.iter().enumerate() {
let mut tile = map_tiles[tile_index];
tile.color = Some(Color::RGB(0x20, 0x20, 0xf9));
let dest = Rect::new(
(BOARD_CELL_OFFSET.x as usize * CELL_SIZE as usize + x * CELL_SIZE as usize) as i32,
(BOARD_CELL_OFFSET.y as usize * CELL_SIZE as usize + y * CELL_SIZE as usize) as i32,
CELL_SIZE,
CELL_SIZE,
);
if let Err(e) = tile.render(canvas, atlas, dest) {
tracing::error!("Failed to render map tile: {}", e);
}
}
}
}