Проектная работа - WIP
This commit is contained in:
@@ -1,12 +1,49 @@
|
||||
use bevy::ecs::component::Component;
|
||||
use bevy::prelude::*;
|
||||
|
||||
pub mod constants {
|
||||
pub const FRAMES_PER_SECOND: u8 = 24;
|
||||
|
||||
pub const GRID_SIZE: u8 = 48;
|
||||
|
||||
pub const HEAD_SIZE: u8 = (GRID_SIZE as f32 * 1.1) as u8;
|
||||
}
|
||||
pub const FRAMES_PER_SECOND: u8 = 24;
|
||||
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;
|
||||
|
||||
/// Голова змеи
|
||||
#[derive(Component)]
|
||||
pub struct Head;
|
||||
|
||||
/// Направление движения
|
||||
#[derive(Component)]
|
||||
pub enum Direction {
|
||||
Up,
|
||||
Left,
|
||||
Down,
|
||||
Right,
|
||||
}
|
||||
|
||||
/// Скорость движения
|
||||
#[derive(Component)]
|
||||
pub struct Velocity(f32);
|
||||
|
||||
impl Direction {
|
||||
pub fn rotate_left(&mut self) {
|
||||
*self = match self {
|
||||
Direction::Up => Direction::Left,
|
||||
Direction::Left => Direction::Down,
|
||||
Direction::Down => Direction::Right,
|
||||
Direction::Right => Direction::Up,
|
||||
};
|
||||
}
|
||||
|
||||
pub fn rotate_right(&mut self) {
|
||||
*self = match self {
|
||||
Direction::Up => Direction::Right,
|
||||
Direction::Right => Direction::Down,
|
||||
Direction::Down => Direction::Left,
|
||||
Direction::Left => Direction::Up,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for Direction {
|
||||
fn default() -> Self {
|
||||
Direction::Up
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user