Checkboard background

This commit is contained in:
2026-09-16 18:00:51 +02:00
parent eb8dd7841f
commit 833ef769b1
2 changed files with 42 additions and 3 deletions
+38
View File
@@ -1 +1,39 @@
use bevy::prelude::*; 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);
}
}
+4 -3
View File
@@ -1,6 +1,7 @@
use bevy::{prelude::*, window::PresentMode}; use bevy::{prelude::*, window::PresentMode};
use crate::camera::CameraPlugin as OtherCameraPlugin; use crate::background::BackgroundPlugin;
use crate::camera::CameraPlugin;
use crate::player::PlayerPlugin; use crate::player::PlayerPlugin;
mod background; mod background;
@@ -18,8 +19,8 @@ fn main() {
}), }),
..default() ..default()
})) }))
.insert_resource(ClearColor(Color::srgb(0.0, 0.0, 0.0))) .add_plugins(BackgroundPlugin) // Checkerboard background
.add_plugins(PlayerPlugin) // Player .add_plugins(PlayerPlugin) // Player
.add_plugins(OtherCameraPlugin) // Camera .add_plugins(CameraPlugin) // Camera
.run(); .run();
} }