35 lines
1.0 KiB
Rust
35 lines
1.0 KiB
Rust
use bevy::prelude::*;
|
|
|
|
use crate::world::Chunk;
|
|
|
|
// Test checkboard background
|
|
|
|
const COLOR_A: Color = Color::srgb(0.0, 0.0, 0.0);
|
|
const COLOR_B: Color = Color::srgb(0.6, 0.2, 0.8);
|
|
const ROWS_PER_CHUNK: i64 = 2;
|
|
const CELL_SIZE: f32 = crate::world::CHUNK_HEIGHT / ROWS_PER_CHUNK as f32;
|
|
const BOARD_WIDTH: f32 = 1920.0;
|
|
const COLS: i64 = (BOARD_WIDTH / CELL_SIZE).ceil() as i64;
|
|
|
|
pub fn spawn_background_chunk(commands: &mut Commands, id: i64) {
|
|
for row in (id * ROWS_PER_CHUNK)..(id * ROWS_PER_CHUNK + ROWS_PER_CHUNK) {
|
|
for col in 0..COLS {
|
|
let color = if (row + col) % 2 == 0 {
|
|
COLOR_A
|
|
} else {
|
|
COLOR_B
|
|
};
|
|
|
|
commands.spawn((
|
|
Chunk { id },
|
|
Sprite::from_color(color, Vec2::new(CELL_SIZE, CELL_SIZE)),
|
|
Transform::from_xyz(
|
|
(col as f32 + 0.5 - COLS as f32 / 2.0) * CELL_SIZE,
|
|
(row as f32 + 0.5) * CELL_SIZE,
|
|
0.0,
|
|
),
|
|
));
|
|
}
|
|
}
|
|
}
|