Merge pull request #38 from Ewpratten/win_screen

created win screen
This commit is contained in:
Evan Pratten 2021-10-02 20:04:59 -07:00 committed by GitHub
commit 23892fe7d2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 146 additions and 5 deletions

View File

@ -117,10 +117,7 @@ restart the level. If problems continue, simply get good.
Color::WHITE, Color::WHITE,
); );
if mouse_pressed{ self.is_retry_pressed = mouse_pressed
self.is_retry_pressed = true;
}
} }
else { else {
raylib.draw_text( raylib.draw_text(

View File

@ -3,7 +3,7 @@ use self::{
fsm_error_screen::FsmErrorScreen, fsm_error_screen::FsmErrorScreen,
ingame_scene::{level::loader::load_all_levels, InGameScreen}, ingame_scene::{level::loader::load_all_levels, InGameScreen},
main_menu_screen::MainMenuScreen, options_screen::OptionsScreen, how_to_play_screen::HowToPlayScreen, main_menu_screen::MainMenuScreen, options_screen::OptionsScreen, how_to_play_screen::HowToPlayScreen,
death_screen::DeathScreen death_screen::DeathScreen, win_screen::WinScreen
}; };
use crate::{ use crate::{
context::GameContext, context::GameContext,
@ -22,6 +22,7 @@ pub mod how_to_play_screen;
pub mod options_screen; pub mod options_screen;
pub mod pause_screen; pub mod pause_screen;
pub mod death_screen; pub mod death_screen;
pub mod win_screen;
/// Defines all scenes /// Defines all scenes
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, Hash)] #[derive(Debug, Clone, Copy, PartialEq, Eq, Default, Hash)]
@ -34,6 +35,7 @@ pub enum Scenes {
OptionsScreen, OptionsScreen,
PauseScreen, PauseScreen,
DeathScreen, DeathScreen,
WinScreen,
} }
/// Contains any possible errors thrown while rendering /// 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), InGameScreen::new(player_sprite_sheet, world_background, levels),
)?; )?;
machine.add_action(Scenes::DeathScreen, DeathScreen::new())?; machine.add_action(Scenes::DeathScreen, DeathScreen::new())?;
machine.add_action(Scenes::WinScreen, WinScreen::new())?;
Ok(machine) Ok(machine)
} }

View File

@ -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<Scenes, ScreenError, GameContext> 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<dirty_fsm::ActionFlag<Scenes>, 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,
);
}
}
}
}