Проектная работа - WIP
This commit is contained in:
@@ -15,6 +15,7 @@ pub use position::Position;
|
||||
pub const GRID_SIZE: u8 = 48;
|
||||
pub const HEAD_SIZE: u8 = (GRID_SIZE as f32 * 1.1) as u8;
|
||||
pub const SNAKE_VELOCITY: u8 = (GRID_SIZE as f32 / 1.0) as u8;
|
||||
pub const FIELD_SIZE: u8 = 20;
|
||||
|
||||
/// Голова змеи
|
||||
#[derive(Component)]
|
||||
|
||||
@@ -18,3 +18,9 @@ impl GridBarier {
|
||||
|
||||
#[derive(Event)]
|
||||
pub struct GrowUp;
|
||||
|
||||
#[derive(Event)]
|
||||
pub enum Collision {
|
||||
Bounds,
|
||||
Entity(Entity),
|
||||
}
|
||||
|
||||
+47
-10
@@ -1,27 +1,64 @@
|
||||
use bevy::prelude::*;
|
||||
use bevy::{color::palettes::tailwind::*, prelude::*};
|
||||
|
||||
use crate::{
|
||||
domain::{End, SnakePath, Tail},
|
||||
domain::{End, FIELD_SIZE, GRID_SIZE, SnakePath, Tail},
|
||||
observers::schedule_set_velocity,
|
||||
};
|
||||
|
||||
/// Инициализация игрового мира
|
||||
pub fn startup(mut commands: Commands, mut time: ResMut<Time<Fixed>>) {
|
||||
time.set_timestep_hz(32.0);
|
||||
spawn_snake(&mut commands);
|
||||
crate::debug::spawn_grid(&mut commands);
|
||||
commands.spawn(Camera2d);
|
||||
}
|
||||
|
||||
/// Создать голову змеи
|
||||
fn spawn_snake(commands: &mut Commands) {
|
||||
use crate::domain::{Direction, HEAD_SIZE, Head, SNAKE_VELOCITY, Velocity};
|
||||
|
||||
commands.insert_resource(SnakePath::default());
|
||||
|
||||
commands.spawn(Observer::new(crate::observers::clean_snake_path));
|
||||
commands.spawn(Observer::new(crate::observers::grow_up_snake));
|
||||
|
||||
spawn_bounds(&mut commands);
|
||||
|
||||
spawn_snake(&mut commands);
|
||||
|
||||
crate::debug::spawn_grid(&mut commands);
|
||||
|
||||
commands.spawn(Camera2d);
|
||||
}
|
||||
|
||||
/// Создать границу игрового поля
|
||||
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()
|
||||
},
|
||||
));
|
||||
}
|
||||
|
||||
/// Создать голову змеи
|
||||
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));
|
||||
|
||||
let head = commands
|
||||
|
||||
Reference in New Issue
Block a user