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" } ] } diff --git a/game/src/scenes/ingame_scene/mod.rs b/game/src/scenes/ingame_scene/mod.rs index cbcb340..1509484 100644 --- a/game/src/scenes/ingame_scene/mod.rs +++ b/game/src/scenes/ingame_scene/mod.rs @@ -100,7 +100,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/mod.rs b/game/src/scenes/mod.rs index 018934b..a3afe32 100644 --- a/game/src/scenes/mod.rs +++ b/game/src/scenes/mod.rs @@ -1,4 +1,5 @@ use self::{ + pause_screen::PauseScreen, fsm_error_screen::FsmErrorScreen, ingame_scene::{level::loader::load_all_levels, InGameScreen}, loading_screen::LoadingScreen, @@ -18,6 +19,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)] @@ -27,6 +30,7 @@ pub enum Scenes { LoadingScreen, MainMenuScreen, InGameScene, + PauseScreen, } /// Contains any possible errors thrown while rendering @@ -60,6 +64,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, world_background, levels), diff --git a/game/src/scenes/pause_screen.rs b/game/src/scenes/pause_screen.rs new file mode 100644 index 0000000..e960b71 --- /dev/null +++ b/game/src/scenes/pause_screen.rs @@ -0,0 +1,182 @@ +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 + ); + + 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 + ); + } + + + } +}