Проектная работа - WIP
This commit is contained in:
+37
-2
@@ -1,8 +1,8 @@
|
||||
//! модуль с инструментами отладки
|
||||
|
||||
use bevy::prelude::*;
|
||||
use bevy::{color::palettes::tailwind::*, prelude::*};
|
||||
|
||||
use crate::domain::{Collision, GridBarier, GrowUp};
|
||||
use crate::domain::{Collision, GridBarier, GrowUp, Meal, Position};
|
||||
|
||||
/// вывод всех сущностей мира
|
||||
pub fn print_all_entities(mut commands: Commands, query: Query<Entity>) {
|
||||
@@ -114,3 +114,38 @@ pub fn grow_up_on_tab(input: Res<ButtonInput<KeyCode>>, mut commands: Commands)
|
||||
pub fn trace_collisions(event: On<Collision>) {
|
||||
trace!("collision detected: {event:?}")
|
||||
}
|
||||
|
||||
pub fn spawn_some_meal(commands: &mut Commands) {
|
||||
commands.spawn((
|
||||
Meal,
|
||||
Sprite::from_color(YELLOW_200, vec2(40.0, 40.0)), //
|
||||
Transform {
|
||||
translation: Position::new(5, 7).translation().extend(0.0),
|
||||
..Default::default()
|
||||
},
|
||||
));
|
||||
commands.spawn((
|
||||
Meal,
|
||||
Sprite::from_color(YELLOW_200, vec2(40.0, 40.0)), //
|
||||
Transform {
|
||||
translation: Position::new(-3, -5).translation().extend(0.0),
|
||||
..Default::default()
|
||||
},
|
||||
));
|
||||
commands.spawn((
|
||||
Meal,
|
||||
Sprite::from_color(YELLOW_200, vec2(40.0, 40.0)), //
|
||||
Transform {
|
||||
translation: Position::new(4, -5).translation().extend(0.0),
|
||||
..Default::default()
|
||||
},
|
||||
));
|
||||
commands.spawn((
|
||||
Meal,
|
||||
Sprite::from_color(YELLOW_200, vec2(40.0, 40.0)), //
|
||||
Transform {
|
||||
translation: Position::new(-5, 6).translation().extend(0.0),
|
||||
..Default::default()
|
||||
},
|
||||
));
|
||||
}
|
||||
|
||||
@@ -47,10 +47,12 @@ pub fn grow_up_snake(_: On<GrowUp>, mut commands: Commands, query: Single<(Entit
|
||||
pub fn handle_collisions(
|
||||
event: On<Collision>, //
|
||||
query: Query<(&mut Velocity, &mut Sprite), Or<(With<Head>, With<Tail>, With<End>)>>,
|
||||
mut commands: Commands,
|
||||
) {
|
||||
match event.event() {
|
||||
Collision::Meal(entity) => {
|
||||
todo!()
|
||||
commands.entity(*entity).despawn();
|
||||
commands.trigger(GrowUp);
|
||||
}
|
||||
Collision::Bounds | Collision::Tail => {
|
||||
for (mut velocity, mut sprite) in query.into_iter() {
|
||||
|
||||
@@ -27,6 +27,7 @@ pub fn startup(mut commands: Commands, mut time: ResMut<Time<Fixed>>) {
|
||||
spawn_snake(&mut commands);
|
||||
|
||||
crate::debug::spawn_grid(&mut commands);
|
||||
crate::debug::spawn_some_meal(&mut commands);
|
||||
|
||||
commands.spawn(Camera2d);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user