background changed

This commit is contained in:
2026-09-20 17:21:48 +02:00
parent 9ed562735e
commit d8799c1f58
+51 -20
View File
@@ -1,36 +1,67 @@
use bevy::prelude::*;
use crate::{
config::{CHUNK_ROWS, TERRAIN_COLS},
world::{
Chunk,
grid::{GridRect, grid_to_world},
config::{
CELL_SIZE, CHUNK_HEIGHT, CHUNK_ROWS, HALF_TERRAIN_WIDTH, TERRAIN_COLS, TERRAIN_WIDTH,
},
world::Chunk,
};
// Test checkboard background
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 COLOR_A: Color = Color::srgb(0.0, 0.0, 0.0);
const COLOR_B: Color = Color::srgb(0.6, 0.2, 0.8);
pub fn spawn_background_chunk(commands: &mut Commands, id: i64) {
for row in 0..CHUNK_ROWS {
for col in 0..TERRAIN_COLS {
let global_row = id * CHUNK_ROWS as i64 + row as i64;
let color = if (global_row + col as i64) % 2 == 0 {
COLOR_A
} else {
COLOR_B
};
let (center, size) = grid_to_world(id, GridRect::cell(col, row));
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 },
);
}
}