Breakout
This commit is contained in:
parent
f83c7c0781
commit
9910fd5799
4 changed files with 572 additions and 20 deletions
49
src/debug.rs
Normal file
49
src/debug.rs
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
use bevy::prelude::*;
|
||||
|
||||
use crate::{Brick, GameState, WORLD_SIZE};
|
||||
|
||||
pub(crate) struct DebugPlugin;
|
||||
|
||||
impl Plugin for DebugPlugin {
|
||||
fn build(&self, app: &mut App) {
|
||||
if !cfg!(feature = "debug") {
|
||||
return;
|
||||
}
|
||||
|
||||
app.add_systems(
|
||||
Update,
|
||||
(
|
||||
draw_world_bounds,
|
||||
log_state_transitions.run_if(state_changed::<GameState>),
|
||||
cheat_codes,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
fn draw_world_bounds(mut gizmos: Gizmos) {
|
||||
gizmos.rect_2d(
|
||||
Isometry2d::from_translation(WORLD_SIZE / 2.),
|
||||
WORLD_SIZE,
|
||||
LinearRgba::RED,
|
||||
);
|
||||
}
|
||||
|
||||
fn log_state_transitions(state: Res<State<GameState>>) {
|
||||
info!({ ?state }, "State changed");
|
||||
}
|
||||
|
||||
fn cheat_codes(
|
||||
mut commands: Commands,
|
||||
input: Res<ButtonInput<KeyCode>>,
|
||||
bricks: Query<Entity, With<Brick>>,
|
||||
) {
|
||||
if input.pressed(KeyCode::Digit1) {
|
||||
let mut iter = bricks.iter();
|
||||
_ = iter.next();
|
||||
|
||||
for entity in iter {
|
||||
commands.entity(entity).despawn();
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue