use bevy::prelude::*; use bevy::render::pass::ClearColor; use std::time::Duration; const ARENA_WIDTH: u32 = 40; const ARENA_HEIGHT: u32 = 40; #[derive(Default, Copy, Clone, Debug, Eq, PartialEq, Hash)] struct Position { x: i32, y: i32, } struct Size { width: f32, height: f32, } impl Size { pub fn square(x: f32) -> Self { Self { width: x, height: x, } } } #[derive(PartialEq, Copy, Clone, Debug)] enum Direction { Left, Up, Right, Down, } impl Direction { fn opposite(self: &Self) -> Self { match self { Self::Left => Self::Right, Self::Right => Self::Left, Self::Up => Self::Down, Self::Down => Self::Up, } } } #[derive(Default)] struct SnakeSegment { next_segment: Option } struct SnakeHead { direction: Direction, next_segment: Entity, } struct SnakeMoveTimer(Timer); struct HeadMaterial(Handle); fn snake_movement( time: Res