Проектная работа - WIP
This commit is contained in:
@@ -10,7 +10,7 @@ pub const SNAKE_VELOCITY: u8 = (GRID_SIZE as f32 / 1.0) as u8;
|
||||
pub struct Head;
|
||||
|
||||
/// Направление движения
|
||||
#[derive(Component)]
|
||||
#[derive(Component, PartialEq)]
|
||||
pub enum Direction {
|
||||
Up,
|
||||
Left,
|
||||
@@ -18,10 +18,6 @@ pub enum Direction {
|
||||
Right,
|
||||
}
|
||||
|
||||
/// Скорость движения
|
||||
#[derive(Component)]
|
||||
pub struct Velocity(f32);
|
||||
|
||||
impl Direction {
|
||||
pub fn rotate_left(&mut self) {
|
||||
*self = match self {
|
||||
@@ -40,6 +36,15 @@ impl Direction {
|
||||
Direction::Left => Direction::Up,
|
||||
};
|
||||
}
|
||||
|
||||
pub fn vector(&self) -> Vec2 {
|
||||
match self {
|
||||
Direction::Up => vec2(0., 1.),
|
||||
Direction::Right => vec2(-1., 0.),
|
||||
Direction::Down => vec2(0., -1.),
|
||||
Direction::Left => vec2(1., 0.),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for Direction {
|
||||
@@ -47,3 +52,11 @@ impl Default for Direction {
|
||||
Direction::Up
|
||||
}
|
||||
}
|
||||
|
||||
/// Скорость движения
|
||||
#[derive(Component)]
|
||||
pub struct Velocity(pub f32);
|
||||
|
||||
/// Инерция
|
||||
#[derive(Component, Default)]
|
||||
pub struct Inert(pub Direction);
|
||||
|
||||
Reference in New Issue
Block a user