From fccb47491a38696b0439e0b32edf077b916860aa Mon Sep 17 00:00:00 2001 From: Luna Date: Sat, 2 Oct 2021 23:00:59 -0400 Subject: [PATCH] created win screen --- game/src/scenes/death_screen.rs | 5 +- game/src/scenes/mod.rs | 5 +- game/src/scenes/win_screen.rs | 141 ++++++++++++++++++++++++++++++++ 3 files changed, 146 insertions(+), 5 deletions(-) create mode 100644 game/src/scenes/win_screen.rs diff --git a/game/src/scenes/death_screen.rs b/game/src/scenes/death_screen.rs index 996eeb3..b989a68 100644 --- a/game/src/scenes/death_screen.rs +++ b/game/src/scenes/death_screen.rs @@ -120,10 +120,7 @@ If you need to use safemode to actually complete the game, please just get good. Color::WHITE, ); - if mouse_pressed{ - self.is_retry_pressed = true; - - } + self.is_retry_pressed = mouse_pressed } else { raylib.draw_text( diff --git a/game/src/scenes/mod.rs b/game/src/scenes/mod.rs index 8cf65e7..628f1bb 100644 --- a/game/src/scenes/mod.rs +++ b/game/src/scenes/mod.rs @@ -3,7 +3,7 @@ use self::{ fsm_error_screen::FsmErrorScreen, ingame_scene::{level::loader::load_all_levels, InGameScreen}, main_menu_screen::MainMenuScreen, options_screen::OptionsScreen, how_to_play_screen::HowToPlayScreen, - death_screen::DeathScreen + death_screen::DeathScreen, win_screen::WinScreen }; use crate::{ context::GameContext, @@ -22,6 +22,7 @@ pub mod how_to_play_screen; pub mod options_screen; pub mod pause_screen; pub mod death_screen; +pub mod win_screen; /// Defines all scenes #[derive(Debug, Clone, Copy, PartialEq, Eq, Default, Hash)] @@ -34,6 +35,7 @@ pub enum Scenes { OptionsScreen, PauseScreen, DeathScreen, + WinScreen, } /// Contains any possible errors thrown while rendering @@ -71,6 +73,7 @@ pub fn build_screen_state_machine( InGameScreen::new(player_sprite_sheet, world_background, levels), )?; machine.add_action(Scenes::DeathScreen, DeathScreen::new())?; + machine.add_action(Scenes::WinScreen, WinScreen::new())?; Ok(machine) } diff --git a/game/src/scenes/win_screen.rs b/game/src/scenes/win_screen.rs new file mode 100644 index 0000000..9a3200b --- /dev/null +++ b/game/src/scenes/win_screen.rs @@ -0,0 +1,141 @@ +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 WinScreen { + is_menu_pressed: bool, //Is menu button pressed + counter: i32 +} + +impl WinScreen { + /// Construct a new `WinScreen` + pub fn new() -> Self { + Self { + is_menu_pressed: false, + counter: 0 + + } + } +} + +impl Action for WinScreen { + fn on_register(&mut self) -> Result<(), ScreenError> { + debug!("Registered"); + Ok(()) + } + + fn on_first_run(&mut self, _context: &GameContext) -> Result<(), ScreenError> { + debug!("Running WinScreen for the first time"); + Ok(()) + } + + fn execute( + &mut self, + _delta: &chrono::Duration, + context: &GameContext, + ) -> Result, ScreenError> { + trace!("execute() called on WinScreen"); + self.render_screen_space(&mut context.renderer.borrow_mut(), &context.config); + self.counter += 1; + + if self.is_menu_pressed { + Ok(ActionFlag::SwitchState(Scenes::MainMenuScreen)) + } + else{ + Ok(ActionFlag::Continue) + } + } + + fn on_finish(&mut self, _interrupted: bool) -> Result<(), ScreenError> { + debug!("Finished WinScreen"); + self.is_menu_pressed = false; + self.counter = 0; + Ok(()) + } +} + +impl ScreenSpaceRender for WinScreen { + fn render_screen_space( + &mut self, + raylib: &mut crate::utilities::non_ref_raylib::HackedRaylibHandle, + config: &GameConfig + ) { + + // Render the background + raylib.clear_background(Color::BLACK); + + let screen_size = raylib.get_screen_size(); + + //Mouse Position + let mouse_position: Vector2 = raylib.get_mouse_position(); + + let mouse_pressed: bool = raylib.is_mouse_button_pressed(MouseButton::MOUSE_LEFT_BUTTON); + + if self.counter > 100{ + raylib.draw_rgb_split_text( + Vector2::new(100.0, screen_size.y as f32 / 2.0 - 120.0), + "congrats.", + 40, + false, + Color::WHITE, + ); + } + if self.counter > 200{ + raylib.draw_rgb_split_text( + Vector2::new(100.0, screen_size.y as f32 / 2.0 - 60.0), + "you win.", + 40, + false, + Color::WHITE, + ); + } + if self.counter > 400{ + raylib.draw_rgb_split_text( + Vector2::new(100.0, screen_size.y as f32 / 2.0), + "yay.", + 40, + false, + Color::WHITE, + ); + }; + + //Return to Main Menu + if self.counter > 550{ + if Rectangle::new(100.0, screen_size.y as f32 / 2.0 + 90.0, 270.0, 20.0).check_collision_point_rec(mouse_position){ + raylib.draw_rgb_split_text( + Vector2::new(100.0, screen_size.y as f32 / 2.0 + 100.0), + ">> RETURN TO MAIN MENU", + 20, + true, + Color::WHITE, + ); + + self.is_menu_pressed = mouse_pressed + } + else { + raylib.draw_rgb_split_text( + Vector2::new(100.0, screen_size.y as f32 / 2.0 + 100.0), + ">> RETURN TO MAIN MENU", + 20, + false, + Color::WHITE, + ); + } + } + } +}