Checkboard background
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
+4
-3
@@ -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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user