From 072fe22e43e64a816c4254467be5fb85a0df905d Mon Sep 17 00:00:00 2001 From: Chris Petkau Date: Thu, 11 Jul 2019 07:28:59 -0700 Subject: [PATCH 1/4] - Removed PausedState and implemented pause directly in main_game.rs. This allows the user to interact with the game while it is paused, which is desirable. - Correctly initialize and reset time scale changes in on_start and on_stop respectively so that exiting and re-entering MainGameState maintains program integrity. - Restored deletion of all organisms in MainGameState::on_stop(). This important line was deleted when it was last integrated. - Changed text color of ui buttons to have higher contrast. --- resources/prefabs/ui/main_game.ron | 8 ++-- resources/prefabs/ui/menu.ron | 4 +- src/main.rs | 3 ++ src/states/main_game.rs | 67 +++++++++++++++++++++++------- src/states/mod.rs | 1 - src/states/paused.rs | 31 -------------- src/systems/swarm_behavior.rs | 5 +++ 7 files changed, 65 insertions(+), 54 deletions(-) delete mode 100644 src/states/paused.rs diff --git a/resources/prefabs/ui/main_game.ron b/resources/prefabs/ui/main_game.ron index 48e4335..48ea6d9 100644 --- a/resources/prefabs/ui/main_game.ron +++ b/resources/prefabs/ui/main_game.ron @@ -25,7 +25,7 @@ Container( normal_image: SolidColor(0.5, 0.5, 0.5, 1.), hover_image: SolidColor(0.5, 0.5, 0.5, 1.), press_image: SolidColor(0.5, 0.5, 0.5, 1.), - normal_text_color: (0.4, 0.4, 0.4, 1.0), + normal_text_color: (0.2, 0.2, 0.2, 1.0), hover_text_color: (0.7, 0.7, 0.7, 1.0), press_text_color: (1.0, 1.0, 1.0, 1.0), ) @@ -47,7 +47,7 @@ Container( normal_image: SolidColor(0.5, 0.5, 0.5, 1.), hover_image: SolidColor(0.5, 0.5, 0.5, 1.), press_image: SolidColor(0.5, 0.5, 0.5, 1.), - normal_text_color: (0.4, 0.4, 0.4, 1.0), + normal_text_color: (0.2, 0.2, 0.2, 1.0), hover_text_color: (0.7, 0.7, 0.7, 1.0), press_text_color: (1.0, 1.0, 1.0, 1.0), ) @@ -69,7 +69,7 @@ Container( normal_image: SolidColor(0.5, 0.5, 0.5, 1.), hover_image: SolidColor(0.5, 0.5, 0.5, 1.), press_image: SolidColor(0.5, 0.5, 0.5, 1.), - normal_text_color: (0.4, 0.4, 0.4, 1.0), + normal_text_color: (0.2, 0.2, 0.2, 1.0), hover_text_color: (0.7, 0.7, 0.7, 1.0), press_text_color: (1.0, 1.0, 1.0, 1.0), ) @@ -91,7 +91,7 @@ Container( normal_image: SolidColor(0.5, 0.5, 0.5, 1.), hover_image: SolidColor(0.5, 0.5, 0.5, 1.), press_image: SolidColor(0.5, 0.5, 0.5, 1.), - normal_text_color: (0.4, 0.4, 0.4, 1.0), + normal_text_color: (0.2, 0.2, 0.2, 1.0), hover_text_color: (0.7, 0.7, 0.7, 1.0), press_text_color: (1.0, 1.0, 1.0, 1.0), ) diff --git a/resources/prefabs/ui/menu.ron b/resources/prefabs/ui/menu.ron index 1969382..e169a87 100644 --- a/resources/prefabs/ui/menu.ron +++ b/resources/prefabs/ui/menu.ron @@ -25,7 +25,7 @@ Container( normal_image: SolidColor(0.5, 0.5, 0.5, 1.), hover_image: SolidColor(0.5, 0.5, 0.5, 1.), press_image: SolidColor(0.5, 0.5, 0.5, 1.), - normal_text_color: (0.4, 0.4, 0.4, 1.0), + normal_text_color: (0.2, 0.2, 0.2, 1.0), hover_text_color: (0.7, 0.7, 0.7, 1.0), press_text_color: (1.0, 1.0, 1.0, 1.0), ) @@ -47,7 +47,7 @@ Container( normal_image: SolidColor(0.5, 0.5, 0.5, 1.), hover_image: SolidColor(0.5, 0.5, 0.5, 1.), press_image: SolidColor(0.5, 0.5, 0.5, 1.), - normal_text_color: (0.4, 0.4, 0.4, 1.0), + normal_text_color: (0.2, 0.2, 0.2, 1.0), hover_text_color: (0.7, 0.7, 0.7, 1.0), press_text_color: (1.0, 1.0, 1.0, 1.0), ) diff --git a/src/main.rs b/src/main.rs index 63c3c2a..c6b3df7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,6 @@ +#[macro_use] +extern crate log; + use amethyst::assets::PrefabLoaderSystem; use amethyst::{ assets::Processor, diff --git a/src/states/main_game.rs b/src/states/main_game.rs index c166b97..b9e6fa4 100644 --- a/src/states/main_game.rs +++ b/src/states/main_game.rs @@ -1,7 +1,7 @@ use amethyst; use amethyst::{ - core::math::{Rotation3, Vector3}, + core::math::{clamp, Rotation3, Vector3}, core::{transform::Transform, ArcThreadPool, Time}, ecs::*, input::InputEvent, @@ -20,18 +20,23 @@ use crate::{ debug::DebugConfig, prefabs::UiPrefabRegistry, spatial_grid::SpatialGrid, world_bounds::WorldBounds, }, - states::{menu::MenuState, paused::PausedState}, + states::menu::MenuState, systems::*, }; use rand::{thread_rng, Rng}; use std::f32::consts::PI; +const TIME_SCALE_FACTOR: f32 = 2.0; +const TIME_SCALE_RANGE: (f32, f32) = (1.0 / 4.0, 1.0 * 4.0); + pub struct MainGameState { dispatcher: Dispatcher<'static, 'static>, debug_dispatcher: Dispatcher<'static, 'static>, ui_dispatcher: Dispatcher<'static, 'static>, ui: Option, camera: Option, + paused: bool, + desired_time_scale: f32, } impl MainGameState { @@ -193,8 +198,6 @@ impl MainGameState { &[], ) .build(), - // The ui dispatcher will also run when this game state is paused. This is necessary so that - // the user can interact with the UI even if the game is in the `Paused` game state. ui_dispatcher: DispatcherBuilder::new() .with( main_game_ui::MainGameUiSystem::default(), @@ -204,25 +207,46 @@ impl MainGameState { .build(), ui: None, camera: None, + paused: false, + desired_time_scale: 1.0, } } - fn handle_action(&self, action: &str, world: &mut World) -> SimpleTrans { + // push desired_time_scale into effect + fn update_time_scale(&self, world: &mut World) { + world + .write_resource::