Проектная работа - WIP
This commit is contained in:
@@ -2,7 +2,6 @@ use std::collections::HashMap;
|
||||
|
||||
use bevy::prelude::*;
|
||||
|
||||
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;
|
||||
@@ -104,14 +103,15 @@ impl SnakePath {
|
||||
)
|
||||
}
|
||||
|
||||
pub fn push(&mut self, transform: &Transform, direction: Direction) {
|
||||
pub fn push(&mut self, transform: &Transform, direction: Direction) -> (i16, i16, Direction) {
|
||||
let key = SnakePath::to_key(transform);
|
||||
self.0.insert(key, direction.clone());
|
||||
(key.0, key.1, direction.clone())
|
||||
}
|
||||
|
||||
pub fn pick(&self, transform: &Transform) -> Option<Direction> {
|
||||
pub fn pick(&self, transform: &Transform) -> Option<(i16, i16, Direction)> {
|
||||
let key = SnakePath::to_key(transform);
|
||||
self.0.get(&key).cloned()
|
||||
self.0.get(&key).cloned().map(|d| (key.0, key.1, d))
|
||||
}
|
||||
|
||||
pub fn drop(&mut self, transform: &Transform) -> Option<(i16, i16, Direction)> {
|
||||
@@ -132,7 +132,7 @@ mod test {
|
||||
snake_path.push(&Transform::default(), Direction::default());
|
||||
assert_eq!(snake_path.0.len(), 1);
|
||||
|
||||
assert!(snake_path.pick(&Transform::default()) == Some(Direction::default()));
|
||||
assert!(snake_path.pick(&Transform::default()) == Some((0, 0, Direction::default())));
|
||||
assert_eq!(snake_path.0.len(), 1);
|
||||
|
||||
assert!(snake_path.drop(&Transform::default()) == Some((0, 0, Direction::default())));
|
||||
|
||||
Reference in New Issue
Block a user