Проектная работа - WIP
This commit is contained in:
+25
-6
@@ -1,13 +1,17 @@
|
||||
//! модуль с инструментами отладки
|
||||
|
||||
use bevy::prelude::*;
|
||||
|
||||
/// ДЛЯ ОТЛАДКИ - вывод всех сущностей мира
|
||||
use crate::domain::GridBarier;
|
||||
|
||||
/// вывод всех сущностей мира
|
||||
pub fn print_all_entities(mut commands: Commands, query: Query<Entity>) {
|
||||
for entity in query {
|
||||
commands.entity(entity).log_components();
|
||||
}
|
||||
}
|
||||
|
||||
/// ДЛЯ ОТЛАДКИ - вывод всех сущностей мира по нажатию Enter
|
||||
/// вывод всех сущностей мира по нажатию Enter
|
||||
pub fn print_all_entities_by_press_enter(input: Res<ButtonInput<KeyCode>>, mut commands: Commands, query: Query<Entity>) {
|
||||
if input.just_pressed(KeyCode::Enter) {
|
||||
for entity in query {
|
||||
@@ -16,7 +20,7 @@ pub fn print_all_entities_by_press_enter(input: Res<ButtonInput<KeyCode>>, mut c
|
||||
}
|
||||
}
|
||||
|
||||
/// ДЛЯ ОТЛАДКИ - регулировка скорости игры
|
||||
/// регулировка скорости игры
|
||||
pub fn time_speed(input: Res<ButtonInput<KeyCode>>, mut time: ResMut<Time<Virtual>>) {
|
||||
if input.just_pressed(KeyCode::Equal) {
|
||||
let mut speed = time.relative_speed();
|
||||
@@ -28,10 +32,10 @@ pub fn time_speed(input: Res<ButtonInput<KeyCode>>, mut time: ResMut<Time<Virtua
|
||||
speed *= 0.5;
|
||||
time.set_relative_speed(speed);
|
||||
trace!("time speed set x0.5");
|
||||
} else if input.just_pressed(KeyCode::Home) {
|
||||
} else if input.just_pressed(KeyCode::Backspace) {
|
||||
time.set_relative_speed(1.0);
|
||||
trace!("time speed reset");
|
||||
} else if input.just_pressed(KeyCode::Pause) {
|
||||
} else if input.just_pressed(KeyCode::Space) {
|
||||
if time.is_paused() {
|
||||
time.unpause();
|
||||
trace!("unpause game");
|
||||
@@ -42,7 +46,14 @@ pub fn time_speed(input: Res<ButtonInput<KeyCode>>, mut time: ResMut<Time<Virtua
|
||||
}
|
||||
}
|
||||
|
||||
fn _split_by_grid_tracing(src: f32, dst: f32, grid: f32) -> Vec<(f32, f32)> {
|
||||
/// Замедлить время и поставить на паузу
|
||||
pub fn set_initial_time_speed_to_slow_and_pause(mut time: ResMut<Time<Virtual>>) {
|
||||
time.set_relative_speed(1.0 / 8.0);
|
||||
time.pause();
|
||||
}
|
||||
|
||||
/// обертка над функцией [crate::tools::split_by_grid] для ее отладки
|
||||
pub fn _split_by_grid_tracing(src: f32, dst: f32, grid: f32) -> Vec<(f32, f32)> {
|
||||
let result = crate::tools::split_by_grid(src, dst, grid);
|
||||
trace!("\tsplit_by_grid({:?}, {:?}, {:?}) -> {:?}", src, dst, grid, result);
|
||||
result
|
||||
@@ -81,3 +92,11 @@ pub fn spawn_grid(commands: &mut Commands) {
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
/// трассировка движения змеи
|
||||
pub fn trace_snake_moving(e: On<GridBarier>) {
|
||||
let entity = e.entity;
|
||||
let position = e.position;
|
||||
let direction = e.direction;
|
||||
trace!("...<{entity:?}> is moving on {position} {direction:?}");
|
||||
}
|
||||
|
||||
+16
-3
@@ -17,14 +17,27 @@ fn main() {
|
||||
}),
|
||||
)
|
||||
.insert_resource(ClearColor(Color::srgb(0.3, 0.6, 0.8)))
|
||||
.add_systems(Startup, (startup,))
|
||||
// .add_systems(PostStartup, snake_game::debug::print_all_entities)
|
||||
.add_systems(
|
||||
Startup,
|
||||
(
|
||||
|| {}, //
|
||||
startup,
|
||||
snake_game::debug::set_initial_time_speed_to_slow_and_pause,
|
||||
),
|
||||
)
|
||||
.add_systems(
|
||||
PostStartup,
|
||||
(
|
||||
|| {},
|
||||
// snake_game::debug::print_all_entities,
|
||||
),
|
||||
)
|
||||
.add_systems(Update, (head_rotation,))
|
||||
.add_systems(FixedUpdate, (snake_moving,))
|
||||
.add_systems(
|
||||
PostUpdate,
|
||||
(
|
||||
//
|
||||
|| {}, //
|
||||
snake_game::debug::print_all_entities_by_press_enter,
|
||||
snake_game::debug::time_speed,
|
||||
),
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use bevy::prelude::*;
|
||||
|
||||
use crate::{
|
||||
domain::{End, GridBarier, SnakePath, Tail},
|
||||
domain::{End, SnakePath, Tail},
|
||||
observers::schedule_set_velocity,
|
||||
};
|
||||
|
||||
@@ -19,12 +19,7 @@ fn spawn_snake(commands: &mut Commands) {
|
||||
|
||||
commands.insert_resource(SnakePath::default());
|
||||
|
||||
commands.spawn(Observer::new(|e: On<GridBarier>| {
|
||||
let entity = e.entity;
|
||||
let position = e.position;
|
||||
let direction = e.direction;
|
||||
trace!("...<{entity:?}> is moving on {position} {direction:?}");
|
||||
}));
|
||||
commands.spawn(Observer::new(crate::debug::trace_snake_moving));
|
||||
|
||||
let head = commands
|
||||
.spawn((
|
||||
|
||||
Reference in New Issue
Block a user