diff --git a/src/main.rs b/src/main.rs index ca1b869..d153b1e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,7 @@ use bevy::prelude::*; use bevy::render::pass::ClearColor; +use rand::prelude::random; +use std::time::Duration; const ARENA_WIDTH: u32 = 10; const ARENA_HEIGHT: u32 = 10; @@ -26,12 +28,23 @@ impl Size { struct SnakeHead; struct Materials { head_material: Handle, + food_material: Handle, +} + +struct Food; + +struct FoodSpawnTimer(Timer); +impl Default for FoodSpawnTimer { + fn default() -> Self { + Self(Timer::new(Duration::from_millis(1000), true)) + } } fn setup(commands: &mut Commands, mut materials: ResMut>) { commands.spawn(Camera2dBundle::default()); commands.insert_resource(Materials { head_material: materials.add(Color::rgb(0.7, 0.7, 0.7).into()), + food_material: materials.add(Color::rgb(1.0, 0.0, 1.0).into()), }); } @@ -93,6 +106,27 @@ fn position_translation(windows: Res, mut q: Query<(&Position, &mut Tra } } +fn food_spawner( + commands: &mut Commands, + materials: Res, + time: Res