12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- 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<ColorMaterial>,
- pub segment_material: Handle<ColorMaterial>,
- pub food_material: Handle<ColorMaterial>,
- }
- // 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<Entity>,
- }
- #[derive(Default)]
- pub struct LastTailPosition {
- pub pos: Option<Position>,
- }
- // snake phase labels
- #[derive(SystemLabel, Debug, Hash, PartialEq, Eq, Clone)]
- pub enum SnakeMovement {
- Input,
- Movement,
- Eating,
- Growth,
- }
- // events
- pub struct GrowthEvent;
- pub struct GameOverEvent;
|