From 042e7357fa7c8f04ee4b8091014b80c358b1544f Mon Sep 17 00:00:00 2001 From: Jordan Orelli Date: Sun, 1 Oct 2023 12:34:05 -0500 Subject: [PATCH] adding some gamestate timers --- src/events.rs | 2 +- src/game.rs | 14 +-- src/main.rs | 1 + src/play.rs | 241 +++++++++++++++++++++++++++++++--------------- src/start_menu.rs | 37 ++----- src/ui.rs | 60 ++++++++++++ 6 files changed, 241 insertions(+), 114 deletions(-) create mode 100644 src/ui.rs diff --git a/src/events.rs b/src/events.rs index 0e413ec..9a8bec0 100644 --- a/src/events.rs +++ b/src/events.rs @@ -1,7 +1,7 @@ use crate::game::Throw; use bevy::prelude::*; -#[derive(Event, Default)] +#[derive(Event, Default, Debug)] pub(crate) struct Play; #[derive(Event)] diff --git a/src/game.rs b/src/game.rs index 5cc9241..0efcf5f 100644 --- a/src/game.rs +++ b/src/game.rs @@ -6,13 +6,6 @@ use crate::{events::Events, play::Play, start_menu::StartMenu}; /// The top-level structure of our game, which is a bevy plugin pub struct Game {} -#[derive(Debug)] -pub(crate) enum Throw { - Rock, - Paper, - Scissors, -} - impl Plugin for Game { fn build(&self, app: &mut App) { info!("Building rps Plugin"); @@ -25,3 +18,10 @@ impl Default for Game { Self {} } } + +#[derive(Debug, Clone)] +pub(crate) enum Throw { + Rock, + Paper, + Scissors, +} diff --git a/src/main.rs b/src/main.rs index 4ed8a0a..351a035 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,6 +2,7 @@ mod events; mod game; mod play; mod start_menu; +mod ui; use bevy::prelude::*; diff --git a/src/play.rs b/src/play.rs index cb4538a..9a38a8f 100644 --- a/src/play.rs +++ b/src/play.rs @@ -1,19 +1,80 @@ -use crate::{events, game::Throw}; +use crate::{events, game::Throw, ui}; use bevy::ecs::system::EntityCommand; use bevy::prelude::*; use bevy::text::DEFAULT_FONT_HANDLE; +use bevy::time::Stopwatch; +use std::time::Duration; + +#[derive(Debug)] +pub enum Phase { + BeforePlay, + Countdown(Timer), + Reveal(Timer), + AfterPlay, +} + +#[derive(Resource, Debug)] +pub struct Board { + phase: Phase, + p1_throw: Option, + p2_throw: Option, +} + +impl Board { + fn new() -> Self { + Self { + phase: Phase::BeforePlay, + p1_throw: None, + p2_throw: None, + } + } +} pub struct Play {} +pub(crate) enum GameEvent { + RoundBegin, + RoundEnd, +} + #[derive(Component, Debug)] struct Action { throw: Throw, } -fn handle_actions(actions: Query<(&Interaction, &Action), (Changed, With)>) { +fn advance_game_state(time: Res