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

This commit is contained in:
-90
View File
@@ -1,90 +0,0 @@
use bevy::{color::palettes::tailwind::*, prelude::*};
use crate::{
domain::{End, FIELD_SIZE, GRID_SIZE, Tail},
observers::schedule_set_velocity,
};
/// Создать границу игрового поля
pub fn spawn_bounds(commands: &mut Commands) {
commands.spawn((
Sprite::from_color(AMBER_500, vec2((FIELD_SIZE as f32 + 1.0) * GRID_SIZE as f32, 5.0)), //
Transform {
translation: vec3(0.0, (FIELD_SIZE as f32 + 1.0) * GRID_SIZE as f32 / 2.0, 0.0),
..Default::default()
},
));
commands.spawn((
Sprite::from_color(AMBER_500, vec2((FIELD_SIZE as f32 + 1.0) * GRID_SIZE as f32, 5.0)), //
Transform {
translation: vec3(0.0, -(FIELD_SIZE as f32 + 1.0) * GRID_SIZE as f32 / 2.0, 0.0),
..Default::default()
},
));
commands.spawn((
Sprite::from_color(AMBER_500, vec2(5.0, (FIELD_SIZE as f32 + 1.0) * GRID_SIZE as f32)), //
Transform {
translation: vec3((FIELD_SIZE as f32 + 1.0) * GRID_SIZE as f32 / 2.0, 0.0, 0.0),
..Default::default()
},
));
commands.spawn((
Sprite::from_color(AMBER_500, vec2(5.0, (FIELD_SIZE as f32 + 1.0) * GRID_SIZE as f32)), //
Transform {
translation: vec3(-(FIELD_SIZE as f32 + 1.0) * GRID_SIZE as f32 / 2.0, 0.0, 0.0),
..Default::default()
},
));
}
/// Создать змейку
pub fn spawn_snake(commands: &mut Commands) {
use crate::domain::{Direction, HEAD_SIZE, Head, SNAKE_VELOCITY, Velocity};
commands.spawn(Observer::new(crate::debug::trace_snake_moving));
commands.spawn(Observer::new(crate::observers::handle_collisions));
let head = commands
.spawn((
Head(Direction::default()),
Direction::default(),
Velocity(SNAKE_VELOCITY as f32),
Sprite::from_color(Color::srgb(1., 1., 1.), vec2(HEAD_SIZE as f32, HEAD_SIZE as f32)),
Transform {
translation: vec3(0.0, 0.0, 1.0),
..Default::default()
},
))
.id();
commands.spawn((
Sprite::from_color(Color::srgb(1., 0., 0.), vec2(HEAD_SIZE as f32 * 0.3, HEAD_SIZE as f32 * 0.3)),
Transform {
translation: vec3(HEAD_SIZE as f32 * -0.25, HEAD_SIZE as f32 * 0.25, 1.0),
..Default::default()
},
ChildOf(head),
));
commands.spawn((
Sprite::from_color(Color::srgb(0., 0., 1.), vec2(HEAD_SIZE as f32 * 0.2, HEAD_SIZE as f32 * 0.2)),
Transform {
translation: vec3(HEAD_SIZE as f32 * 0.25, HEAD_SIZE as f32 * 0.25, 1.0),
..Default::default()
},
ChildOf(head),
));
let tail = commands
.spawn((
Tail(head),
End,
Direction::default(),
Velocity(0.0),
Sprite::from_color(Color::srgb(0.7, 0.7, 0.7), vec2(HEAD_SIZE as f32 * 0.8, HEAD_SIZE as f32 * 0.8)),
Transform {
translation: vec3(0.0, 0.0, 0.0),
..Default::default()
},
))
.id();
commands.entity(head).observe(schedule_set_velocity(tail));
}