From 00ffc23e81e8cb6e9d5f7800a629ee9ffaaa8161 Mon Sep 17 00:00:00 2001 From: Luna Date: Sat, 2 Oct 2021 23:31:48 -0400 Subject: [PATCH] created next level screen --- game/src/scenes/mod.rs | 6 +- game/src/scenes/next_level_screen.rs | 126 +++++++++++++++++++++++++++ 2 files changed, 131 insertions(+), 1 deletion(-) create mode 100644 game/src/scenes/next_level_screen.rs diff --git a/game/src/scenes/mod.rs b/game/src/scenes/mod.rs index 628f1bb..1a1c055 100644 --- a/game/src/scenes/mod.rs +++ b/game/src/scenes/mod.rs @@ -3,7 +3,8 @@ 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, win_screen::WinScreen + death_screen::DeathScreen, win_screen::WinScreen, + next_level_screen::NextLevelScreen }; use crate::{ context::GameContext, @@ -23,6 +24,7 @@ pub mod options_screen; pub mod pause_screen; pub mod death_screen; pub mod win_screen; +pub mod next_level_screen; /// Defines all scenes #[derive(Debug, Clone, Copy, PartialEq, Eq, Default, Hash)] @@ -36,6 +38,7 @@ pub enum Scenes { PauseScreen, DeathScreen, WinScreen, + NextLevelScreen, } /// Contains any possible errors thrown while rendering @@ -74,6 +77,7 @@ pub fn build_screen_state_machine( )?; machine.add_action(Scenes::DeathScreen, DeathScreen::new())?; machine.add_action(Scenes::WinScreen, WinScreen::new())?; + machine.add_action(Scenes::NextLevelScreen, NextLevelScreen::new())?; Ok(machine) } diff --git a/game/src/scenes/next_level_screen.rs b/game/src/scenes/next_level_screen.rs new file mode 100644 index 0000000..c7c5ccb --- /dev/null +++ b/game/src/scenes/next_level_screen.rs @@ -0,0 +1,126 @@ +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::{ + 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, + }, + GameConfig, +}; + +use super::{Scenes, ScreenError}; +use tracing::{debug, info, trace}; + +#[derive(Debug)] +pub struct NextLevelScreen { + is_next_pressed: bool, +} + +impl NextLevelScreen { + /// Construct a new `NextLevelScreen` + pub fn new() -> Self { + Self { + is_next_pressed: false, + } + } +} + +impl Action for NextLevelScreen { + fn on_register(&mut self) -> Result<(), ScreenError> { + debug!("Registered"); + Ok(()) + } + + fn on_first_run(&mut self, _context: &GameContext) -> Result<(), ScreenError> { + debug!("Running NextLevelScreen for the first time"); + Ok(()) + } + + fn execute( + &mut self, + _delta: &chrono::Duration, + context: &GameContext, + ) -> Result, ScreenError> { + trace!("execute() called on NextLevelScreen"); + self.render_screen_space(&mut context.renderer.borrow_mut(), &context.config); + + if self.is_next_pressed { + Ok(ActionFlag::SwitchState(Scenes::InGameScene)) + } else { + Ok(ActionFlag::Continue) + } + + } + + fn on_finish(&mut self, _interrupted: bool) -> Result<(), ScreenError> { + debug!("Finished NextLevelScreen"); + self.is_next_pressed = false; + Ok(()) + } +} + +impl ScreenSpaceRender for NextLevelScreen { + fn render_screen_space( + &mut 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); + raylib.draw_rectangle_lines( + 0, + 0, + screen_size.x as i32, + screen_size.y as i32, + config.colors.white, + ); + + 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); + + //Render the title + raylib.draw_rgb_split_text( + Vector2::new(80.0, screen_size.y / 2.0 - 100.0), + "LEVEL COMPLETE", + 50, + true, + Color::WHITE, + ); + + //Time + raylib.draw_rgb_split_text( + Vector2::new(80.0, screen_size.y / 2.0 - 40.0), + "YOUR TIME: ", + 20, + false, + Color::WHITE, + ); + + //Next Level + let hovering_next_button = Rectangle::new(80.0, screen_size.y as f32 / 2.0 + 50.0, 200.0, 40.0) + .check_collision_point_rec(mouse_position); + raylib.draw_rgb_split_text( + Vector2::new(80.0, screen_size.y / 2.0 + 50.0), + ">> Next Level", + 25, + hovering_next_button, + Color::WHITE, + ); + self.is_next_pressed = hovering_next_button && mouse_pressed; + } +}