use bevy::prelude::*; use crate::{ config::{ CELL_SIZE, CHUNK_HEIGHT, CHUNK_ROWS, HALF_TERRAIN_WIDTH, TERRAIN_COLS, TERRAIN_WIDTH, }, world::Chunk, }; const GRID_COLOR: Color = Color::srgb(0.22, 0.25, 0.30); const EDGE_COLOR: Color = Color::srgb(0.40, 0.45, 0.55); const LINE_THICKNESS: f32 = 1.0; const CHUNK_BORDER_THICKNESS: f32 = 3.0; // Thin line sprite fn spawn_line(commands: &mut Commands, id: i64, center: Vec2, size: Vec2, color: Color) { commands.spawn(( Chunk { id }, Sprite::from_color(color, size), Transform::from_xyz(center.x, center.y, 0.0), )); } // Grid lines background pub fn spawn_background_chunk(commands: &mut Commands, id: i64) { let y0 = CHUNK_HEIGHT * id as f32; let x0 = -HALF_TERRAIN_WIDTH; // Horizontal lines for row in 0..=CHUNK_ROWS { let is_edge = row == 0 || row == CHUNK_ROWS; spawn_line( commands, id, Vec2::new(0.0, y0 + row as f32 * CELL_SIZE), Vec2::new( TERRAIN_WIDTH, if is_edge { CHUNK_BORDER_THICKNESS } else { LINE_THICKNESS }, ), if is_edge { EDGE_COLOR } else { GRID_COLOR }, ); } // Vertical lines for col in 0..=TERRAIN_COLS { let is_edge = col == 0 || col == TERRAIN_COLS; spawn_line( commands, id, Vec2::new(x0 + col as f32 * CELL_SIZE, y0 + CHUNK_HEIGHT / 2.0), Vec2::new( if is_edge { CHUNK_BORDER_THICKNESS } else { LINE_THICKNESS }, CHUNK_HEIGHT, ), if is_edge { EDGE_COLOR } else { GRID_COLOR }, ); } }