diff --git a/src/background.rs b/src/background.rs index 26a6fc8..1f9cecc 100644 --- a/src/background.rs +++ b/src/background.rs @@ -1 +1,39 @@ use bevy::prelude::*; + +// 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); + +fn spawn_board(mut commands: Commands) { + for row in 0..ROWS { + for col in 0..COLS { + // Altern colors + let color = if (row + col) % 2 == 0 { + COLOR_A + } else { + COLOR_B + }; + + commands.spawn(( + 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, + 0.0, + ), + )); + } + } +} + +pub struct BackgroundPlugin; + +impl Plugin for BackgroundPlugin { + fn build(&self, app: &mut App) { + app.add_systems(Startup, spawn_board); + } +} diff --git a/src/main.rs b/src/main.rs index 5944ed6..4d89156 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,7 @@ use bevy::{prelude::*, window::PresentMode}; -use crate::camera::CameraPlugin as OtherCameraPlugin; +use crate::background::BackgroundPlugin; +use crate::camera::CameraPlugin; use crate::player::PlayerPlugin; mod background; @@ -18,8 +19,8 @@ fn main() { }), ..default() })) - .insert_resource(ClearColor(Color::srgb(0.0, 0.0, 0.0))) + .add_plugins(BackgroundPlugin) // Checkerboard background .add_plugins(PlayerPlugin) // Player - .add_plugins(OtherCameraPlugin) // Camera + .add_plugins(CameraPlugin) // Camera .run(); }