use bevy::prelude::{ColorMaterial, Entity, Handle, SystemLabel}; // constants pub const ARENA_WIDTH: u32 = 10; pub const ARENA_HEIGHT: u32 = 10; // basic game components #[derive(Default, Copy, Clone, Eq, PartialEq, Hash)] pub struct Position { pub x: i32, pub y: i32, } pub struct GridSize { pub width: f32, pub height: f32, } impl GridSize { pub fn square(x: f32) -> GridSize { Self { width: x, height: x, } } } #[derive(PartialEq, Copy, Clone, Debug)] pub enum Direction { Left, Up, Right, Down, } impl Direction { pub fn opposite(self) -> Self { match self { Self::Left => Self::Right, Self::Right => Self::Left, Self::Up => Self::Down, Self::Down => Self::Up, } } } // material resource pub struct Materials { pub head_material: Handle, pub segment_material: Handle, pub food_material: Handle, } // food! pub struct Food; // snake-related components #[derive(Debug)] pub struct SnakeHead { pub intention: Direction, pub direction: Direction, } pub struct SnakeSegment; // snake-related resources #[derive(Default)] pub struct SnakeSegments { pub segments: Vec, } #[derive(Default)] pub struct LastTailPosition { pub pos: Option, } // snake phase labels #[derive(SystemLabel, Debug, Hash, PartialEq, Eq, Clone)] pub enum SnakeMovement { Input, Movement, Eating, Growth, } // events pub struct GrowthEvent; pub struct GameOverEvent;