Проектная работа - WIP

This commit is contained in:
8 changed files with 171 additions and 139 deletions
+5 -41
View File
@@ -2,8 +2,8 @@ use bevy::{prelude::*, winit::WinitSettings};
use std::time::Duration;
use crate::{
domain::{End, Grid, SnakePath, Tail},
tools::{end_observer, schedule_set_velocity},
domain::{End, SnakePath, Tail},
observers::{cleanup_snake_path, schedule_set_velocity, tail_observer},
};
/// Настройка частоты кадров
@@ -19,7 +19,7 @@ pub fn setup_frame_rate(mut winit: ResMut<WinitSettings>) {
/// Инициализация игрового мира
pub fn startup(mut commands: Commands) {
spawn_snake(&mut commands);
spawn_grid(&mut commands);
crate::debug::spawn_grid(&mut commands);
commands.spawn(Camera2d);
}
@@ -28,6 +28,7 @@ fn spawn_snake(commands: &mut Commands) {
use crate::domain::{Direction, HEAD_SIZE, Head, Inert, SNAKE_VELOCITY, Velocity};
commands.insert_resource(SnakePath::default());
commands.spawn(Observer::new(cleanup_snake_path));
let head = commands
.spawn((
@@ -83,45 +84,8 @@ fn spawn_snake(commands: &mut Commands) {
translation: vec3(0.0, 0.0, 0.0),
..Default::default()
},
Observer::new(tail_observer),
))
.id();
commands.entity(head).observe(schedule_set_velocity(tail));
commands.entity(tail).observe(end_observer);
}
/// Создать координатную сетку
fn spawn_grid(commands: &mut Commands) {
use crate::domain::GRID_SIZE;
let grid = commands
.spawn((Grid, Transform::default(), Visibility::default()))
.id();
for x in -20..=20 {
commands.spawn((
Sprite::from_color(Color::srgb(1.0, 1.0, 0.5), vec2(0.5, 2000.0)),
Transform {
translation: vec3(x as f32 * GRID_SIZE as f32, 0.0, -1.0),
..Default::default()
},
ChildOf(grid),
));
}
for y in -20..=20 {
commands.spawn((
Sprite::from_color(Color::srgb(1.0, 1.0, 0.5), vec2(2000.0, 0.5)),
Transform {
translation: vec3(0.0, y as f32 * GRID_SIZE as f32, -1.0),
..Default::default()
},
ChildOf(grid),
));
}
}
/// ДЛЯ ОТЛАДКИ - вывод всех сущностей мира
pub fn print_all_entities(mut commands: Commands, query: Query<Entity>) {
for entity in query {
commands.entity(entity).log_components();
}
}