chunk logic
This commit is contained in:
+11
-16
@@ -1,39 +1,34 @@
|
||||
use bevy::prelude::*;
|
||||
|
||||
use crate::world::Chunk;
|
||||
|
||||
// Test checkboard background
|
||||
|
||||
const COLS: usize = 35;
|
||||
const ROWS: usize = 500;
|
||||
const CELL_SIZE: f32 = 60.0;
|
||||
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;
|
||||
|
||||
fn spawn_board(mut commands: Commands) {
|
||||
for row in 0..ROWS {
|
||||
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 {
|
||||
// Altern colors
|
||||
let color = if (row + col) % 2 == 0 {
|
||||
let color = if (row + col as i64) % 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 - ROWS as f32 / 2.0) * CELL_SIZE,
|
||||
(row as f32 + 0.5) * CELL_SIZE,
|
||||
0.0,
|
||||
),
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct BackgroundPlugin;
|
||||
|
||||
impl Plugin for BackgroundPlugin {
|
||||
fn build(&self, app: &mut App) {
|
||||
app.add_systems(Startup, spawn_board);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user