From bd1ae248f50ae6ac431d03bbc0aa88653f55a7b4 Mon Sep 17 00:00:00 2001 From: Marcelo Geldres Date: Sat, 2 Oct 2021 16:53:08 -0400 Subject: [PATCH 1/3] Pause Button Pause button and screen work --- .vscode/tasks.json | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 8e6e932..d7ce173 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -45,6 +45,15 @@ "env": { "RUST_LOG": "trace" } + }, + { + "type": "cargo", + "subcommand": "build", + "problemMatcher": [ + "$rustc" + ], + "group": "build", + "label": "Rust: cargo build - ludum-dare-49" } ] } From 3e027f025984b940d6602e4e99a043296aeb1c69 Mon Sep 17 00:00:00 2001 From: Marcelo Geldres Date: Sat, 2 Oct 2021 16:56:26 -0400 Subject: [PATCH 2/3] Pause Menu Pause Menu with the features of Resuming the game and going back to the main menu. --- game/src/character/mod.rs | 1 + game/src/scenes/ingame_scene/mod.rs | 8 +- game/src/scenes/ingame_scene/update.rs | 12 ++ game/src/scenes/mod.rs | 6 +- game/src/scenes/pause_screen.rs | 194 +++++++++++++++++++++++++ 5 files changed, 219 insertions(+), 2 deletions(-) create mode 100644 game/src/scenes/pause_screen.rs diff --git a/game/src/character/mod.rs b/game/src/character/mod.rs index d79b4eb..7589cea 100644 --- a/game/src/character/mod.rs +++ b/game/src/character/mod.rs @@ -14,6 +14,7 @@ pub enum CharacterState { Running, Jumping, Dashing, + Halt, } #[derive(Debug)] diff --git a/game/src/scenes/ingame_scene/mod.rs b/game/src/scenes/ingame_scene/mod.rs index dc5ee72..f8af389 100644 --- a/game/src/scenes/ingame_scene/mod.rs +++ b/game/src/scenes/ingame_scene/mod.rs @@ -75,7 +75,13 @@ impl Action for InGameScreen { // Render the HUD self.render_screen_space(&mut renderer, &context.config); - Ok(ActionFlag::Continue) + if renderer.is_key_pressed(KeyboardKey::KEY_ESCAPE) { + Ok(ActionFlag::SwitchState(Scenes::PauseScreen)) + } else { + Ok(ActionFlag::Continue) + } + + } fn on_finish(&mut self, _interrupted: bool) -> Result<(), ScreenError> { diff --git a/game/src/scenes/ingame_scene/update.rs b/game/src/scenes/ingame_scene/update.rs index 268bd7a..2af94d9 100644 --- a/game/src/scenes/ingame_scene/update.rs +++ b/game/src/scenes/ingame_scene/update.rs @@ -25,6 +25,17 @@ impl FrameUpdate for InGameScreen { let is_jump = raylib.is_key_pressed(KeyboardKey::KEY_SPACE); let is_dash = raylib.is_key_pressed(KeyboardKey::KEY_LEFT_SHIFT); let is_pause = raylib.is_key_pressed(KeyboardKey::KEY_ESCAPE); + //let is_left_click = raylib.is_mouse_button_down(MouseButton::MOUSE_LEFT_BUTTON); + //let mouse_position: Vector2 = raylib.get_mouse_position(); + + //Stoping the character. + if is_pause { + //println!("Pause : {}", is_pause); + self.player.set_state(CharacterState::Halt); + } else if is_pause == false { + //println!("Pause : {}", is_pause); + self.player.set_state(CharacterState::Running); + } if is_jump { self.player.apply_force(Vector2::new(0.0, -30.0)); @@ -37,6 +48,7 @@ impl FrameUpdate for InGameScreen { self.player.set_state(CharacterState::Running); } } + self.player.update_gravity(); } } diff --git a/game/src/scenes/mod.rs b/game/src/scenes/mod.rs index d9ec17b..caf3b8e 100644 --- a/game/src/scenes/mod.rs +++ b/game/src/scenes/mod.rs @@ -1,6 +1,6 @@ use self::{ fsm_error_screen::FsmErrorScreen, ingame_scene::InGameScreen, loading_screen::LoadingScreen, - main_menu_screen::MainMenuScreen, + main_menu_screen::MainMenuScreen, pause_screen::PauseScreen }; use crate::{ context::GameContext, @@ -16,6 +16,8 @@ pub mod fsm_error_screen; pub mod ingame_scene; pub mod loading_screen; pub mod main_menu_screen; +pub mod pause_screen; + /// Defines all scenes #[derive(Debug, Clone, Copy, PartialEq, Eq, Default, Hash)] @@ -25,6 +27,7 @@ pub enum Scenes { LoadingScreen, MainMenuScreen, InGameScene, + PauseScreen, } /// Contains any possible errors thrown while rendering @@ -55,6 +58,7 @@ pub fn build_screen_state_machine( LoadingScreen::new(raylib_handle, thread)?, )?; machine.add_action(Scenes::MainMenuScreen, MainMenuScreen::new())?; + machine.add_action(Scenes::PauseScreen, PauseScreen::new())?; machine.add_action(Scenes::InGameScene, InGameScreen::new(player_sprite_sheet))?; Ok(machine) } diff --git a/game/src/scenes/pause_screen.rs b/game/src/scenes/pause_screen.rs new file mode 100644 index 0000000..8d63b9b --- /dev/null +++ b/game/src/scenes/pause_screen.rs @@ -0,0 +1,194 @@ +use std::ops::{Div, Sub}; + +use chrono::{DateTime, Utc}; +use dirty_fsm::{Action, ActionFlag}; +use pkg_version::pkg_version_major; +use raylib::prelude::*; + +use crate::{GameConfig, context::GameContext, utilities::{ + datastore::{load_texture_from_internal_data, ResourceLoadError}, + game_version::get_version_string, + math::interpolate_exp, + non_ref_raylib::HackedRaylibHandle, + render_layer::ScreenSpaceRender, + }}; + +use super::{Scenes, ScreenError}; +use tracing::{debug, info, trace}; + +#[derive(Debug)] +pub struct PauseScreen {} + +impl PauseScreen { + /// Construct a new `PauseScreen` + pub fn new() -> Self { + Self {} + } +} + +impl Action for PauseScreen { + fn on_register(&mut self) -> Result<(), ScreenError> { + debug!("Registered"); + Ok(()) + } + + fn on_first_run(&mut self, _context: &GameContext) -> Result<(), ScreenError> { + debug!("Running PauseScreen for the first time"); + + Ok(()) + } + + fn execute( + &mut self, + _delta: &chrono::Duration, + context: &GameContext, + ) -> Result, ScreenError> { + trace!("execute() called on PauseScreen"); + self.render_screen_space(&mut context.renderer.borrow_mut(), &context.config); + + //Mouse Position + let mouse_position: Vector2 = context.renderer.borrow_mut().get_mouse_position(); + //Mouse Input + let is_left_click = context.renderer.borrow_mut().is_mouse_button_down(MouseButton::MOUSE_LEFT_BUTTON); + + + //"Hitboxes" for the resume and Main menu buttons + if is_left_click && Rectangle::new(322.0,321.0,435.0,80.0).check_collision_point_rec(mouse_position) { + return Ok(ActionFlag::SwitchState(Scenes::InGameScene)); + } + + if is_left_click && Rectangle::new(390.0,464.0,200.0,50.0).check_collision_point_rec(mouse_position) { + return Ok(ActionFlag::SwitchState(Scenes::MainMenuScreen)); + } + + if context.renderer.borrow_mut().is_key_pressed(KeyboardKey::KEY_ESCAPE) { + Ok(ActionFlag::SwitchState(Scenes::InGameScene)) + } else { + Ok(ActionFlag::Continue) + } + } + + + fn on_finish(&mut self, _interrupted: bool) -> Result<(), ScreenError> { + debug!("Finished PauseScreen"); + Ok(()) + } +} + +impl ScreenSpaceRender for PauseScreen { + + fn render_screen_space( + &self, + raylib: &mut crate::utilities::non_ref_raylib::HackedRaylibHandle, + config: &GameConfig + ) { + let screen_size = raylib.get_screen_size(); + + // Render the background + raylib.clear_background(Color::BLACK.fade(50.0)); + + //Mouse Position + let mouse_position: Vector2 = raylib.get_mouse_position(); + //Mouse Input + let is_left_click = raylib.is_mouse_button_down(MouseButton::MOUSE_LEFT_BUTTON); + + //Pause Menu Texts With Glitchy Effect + raylib.draw_text( + "Paused", + (screen_size.x as i32 / 2) - 223, + (screen_size.y as i32 / 2) - 40, + 120, + Color::RED + ); + raylib.draw_text( + "Paused", + (screen_size.x as i32 / 2) - 217, + (screen_size.y as i32 / 2) - 40, + 120, + Color::BLUE + ); + raylib.draw_text( + "Paused", + (screen_size.x as i32 / 2) - 220, + (screen_size.y as i32 / 2) - 40, + 120, + Color::WHITE + ); + raylib.draw_text( + "Click To Resume", + (screen_size.x as i32 / 2) - 80, + (screen_size.y as i32 / 2) + 60, + 20, + Color::RED + ); + raylib.draw_text( + "Click To Resume", + (screen_size.x as i32 / 2) - 80, + (screen_size.y as i32 / 2) + 60, + 20, + Color::BLUE + ); + raylib.draw_text( + "Click To Resume", + (screen_size.x as i32 / 2) - 80, + (screen_size.y as i32 / 2) + 60, + 20, + Color::WHITE + ); + raylib.draw_text( + "Main Menu", + (screen_size.x as i32 / 2) - 123, + (screen_size.y as i32 / 2) + 100, + 50, + Color::RED + ); + raylib.draw_text( + "Main Menu", + (screen_size.x as i32 / 2) - 117, + (screen_size.y as i32 / 2) + 100, + 50, + Color::BLUE + ); + raylib.draw_text( + "Main Menu", + (screen_size.x as i32 / 2) - 120, + (screen_size.y as i32 / 2) + 100, + 50, + Color::WHITE + ); + + raylib.draw_text( + &format!( + "Position x: {} Position y: {}", + mouse_position.x, + mouse_position.y + ), + screen_size.x as i32 / 30, + screen_size.y as i32 / 30, + 20, + Color::WHITE + ); + + if Rectangle::new(390.0,464.0,200.0,50.0).check_collision_point_rec(mouse_position) { + raylib.draw_text( + "Main Menu", + (screen_size.x as i32 / 2) - 120, + (screen_size.y as i32 / 2) + 100, + 50, + Color::YELLOW + ); + } + + if Rectangle::new(322.0,321.0,435.0,80.0).check_collision_point_rec(mouse_position) { + raylib.draw_text( + "Paused", + (screen_size.x as i32 / 2) - 220, + (screen_size.y as i32 / 2) - 40, + 120, + Color::DARKBLUE + ); + } + + + } +} From bd5659cbaaee507e25701b0c813cfdc7f1fd3236 Mon Sep 17 00:00:00 2001 From: Evan Pratten Date: Sat, 2 Oct 2021 17:04:52 -0400 Subject: [PATCH 3/3] Some small touch-ups --- game/src/character/mod.rs | 1 - game/src/scenes/mod.rs | 2 +- game/src/scenes/pause_screen.rs | 12 ------------ 3 files changed, 1 insertion(+), 14 deletions(-) diff --git a/game/src/character/mod.rs b/game/src/character/mod.rs index ada2cb4..9c1b0d2 100644 --- a/game/src/character/mod.rs +++ b/game/src/character/mod.rs @@ -17,7 +17,6 @@ pub enum CharacterState { Running, Jumping, Dashing, - Halt, } #[derive(Debug)] diff --git a/game/src/scenes/mod.rs b/game/src/scenes/mod.rs index 1d3ae66..a3afe32 100644 --- a/game/src/scenes/mod.rs +++ b/game/src/scenes/mod.rs @@ -1,5 +1,5 @@ use self::{ - pause_screen::PauseScreen + pause_screen::PauseScreen, fsm_error_screen::FsmErrorScreen, ingame_scene::{level::loader::load_all_levels, InGameScreen}, loading_screen::LoadingScreen, diff --git a/game/src/scenes/pause_screen.rs b/game/src/scenes/pause_screen.rs index 8d63b9b..e960b71 100644 --- a/game/src/scenes/pause_screen.rs +++ b/game/src/scenes/pause_screen.rs @@ -157,18 +157,6 @@ impl ScreenSpaceRender for PauseScreen { Color::WHITE ); - raylib.draw_text( - &format!( - "Position x: {} Position y: {}", - mouse_position.x, - mouse_position.y - ), - screen_size.x as i32 / 30, - screen_size.y as i32 / 30, - 20, - Color::WHITE - ); - if Rectangle::new(390.0,464.0,200.0,50.0).check_collision_point_rec(mouse_position) { raylib.draw_text( "Main Menu",