commit
7246238aa5
139
game/src/scenes/death_screen.rs
Normal file
139
game/src/scenes/death_screen.rs
Normal file
@ -0,0 +1,139 @@
|
||||
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 DeathScreen {
|
||||
is_retry_pressed: bool
|
||||
}
|
||||
|
||||
impl DeathScreen {
|
||||
/// Construct a new `DeathScreen`
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
is_retry_pressed: false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Action<Scenes, ScreenError, GameContext> for DeathScreen {
|
||||
fn on_register(&mut self) -> Result<(), ScreenError> {
|
||||
debug!("Registered");
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn on_first_run(&mut self, _context: &GameContext) -> Result<(), ScreenError> {
|
||||
debug!("Running DeathScreen for the first time");
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn execute(
|
||||
&mut self,
|
||||
_delta: &chrono::Duration,
|
||||
context: &GameContext,
|
||||
) -> Result<dirty_fsm::ActionFlag<Scenes>, ScreenError> {
|
||||
trace!("execute() called on DeathScreen");
|
||||
self.render_screen_space(&mut context.renderer.borrow_mut(), &context.config);
|
||||
|
||||
|
||||
if self.is_retry_pressed {
|
||||
Ok(ActionFlag::SwitchState(Scenes::InGameScene))
|
||||
}
|
||||
else{
|
||||
Ok(ActionFlag::Continue)
|
||||
}
|
||||
}
|
||||
|
||||
fn on_finish(&mut self, _interrupted: bool) -> Result<(), ScreenError> {
|
||||
debug!("Finished DeathScreen");
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl ScreenSpaceRender for DeathScreen {
|
||||
fn render_screen_space(
|
||||
&mut self,
|
||||
raylib: &mut crate::utilities::non_ref_raylib::HackedRaylibHandle,
|
||||
config: &GameConfig
|
||||
) {
|
||||
|
||||
// Render the background
|
||||
raylib.clear_background(Color::DARKBLUE);
|
||||
|
||||
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);
|
||||
|
||||
raylib.draw_text(
|
||||
|
||||
"ERR: Corrupted Player Data Detected
|
||||
|
||||
The program has detected lowering player integrity, and has halted as a safety precaution.
|
||||
|
||||
If this is the first time you've seen this error screen, restart the level. If this screen appears \nagain, follow these steps:
|
||||
|
||||
Check to make sure any new powerups or abilities are properly installed.
|
||||
If this is a new run, ask the game dev for any game updates you might need.
|
||||
|
||||
If problems continue, get better or stop being bad at the game.
|
||||
If you need to use safemode to actually complete the game, please just get good.
|
||||
|
||||
-------- Technical information --------
|
||||
*** CALL STACK:
|
||||
*** C [libraylib.so+0x75c] END_DRAWING()
|
||||
*** RS [data_loss.so+0x48f] validate_player()
|
||||
*** ---------------------------------------
|
||||
*** PROGRAM_HALT (TIME: XX:XX, BEST: XX:XX)
|
||||
*** ---------------------------------------",
|
||||
25,
|
||||
20,
|
||||
20,
|
||||
Color::WHITE,
|
||||
);
|
||||
|
||||
//Retry
|
||||
if Rectangle::new(35.0, screen_size.y as f32 - 80.0, 200.0, 40.0).check_collision_point_rec(mouse_position){
|
||||
raylib.draw_text(
|
||||
|
||||
">>CLICK HERE TO RETRY",
|
||||
20,
|
||||
screen_size.y as i32 - 40,
|
||||
19,
|
||||
Color::WHITE,
|
||||
);
|
||||
|
||||
if mouse_pressed{
|
||||
self.is_retry_pressed = true;
|
||||
|
||||
}
|
||||
}
|
||||
else {
|
||||
raylib.draw_text(
|
||||
|
||||
">>CLICK HERE TO RETRY",
|
||||
25,
|
||||
screen_size.y as i32 - 40,
|
||||
18,
|
||||
Color::WHITE,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
@ -115,10 +115,7 @@ impl Action<Scenes, ScreenError, GameContext> for InGameScreen {
|
||||
if renderer.is_key_pressed(KeyboardKey::KEY_ESCAPE) {
|
||||
Ok(ActionFlag::SwitchState(Scenes::PauseScreen))
|
||||
} else if self.player_dead {
|
||||
|
||||
// TODO: (luna) make this switch to the death screen plz
|
||||
// Ok(ActionFlag::SwitchState(Scenes::FsmErrorScreen))
|
||||
Ok(ActionFlag::Continue)
|
||||
Ok(ActionFlag::SwitchState(Scenes::DeathScreen))
|
||||
} else {
|
||||
Ok(ActionFlag::Continue)
|
||||
}
|
||||
|
@ -3,6 +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
|
||||
};
|
||||
use crate::{
|
||||
context::GameContext,
|
||||
@ -20,6 +21,7 @@ pub mod main_menu_screen;
|
||||
pub mod how_to_play_screen;
|
||||
pub mod options_screen;
|
||||
pub mod pause_screen;
|
||||
pub mod death_screen;
|
||||
|
||||
/// Defines all scenes
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, Hash)]
|
||||
@ -31,6 +33,7 @@ pub enum Scenes {
|
||||
HowToPlayScreen,
|
||||
OptionsScreen,
|
||||
PauseScreen,
|
||||
DeathScreen,
|
||||
}
|
||||
|
||||
/// Contains any possible errors thrown while rendering
|
||||
@ -67,6 +70,7 @@ pub fn build_screen_state_machine(
|
||||
Scenes::InGameScene,
|
||||
InGameScreen::new(player_sprite_sheet, world_background, levels),
|
||||
)?;
|
||||
machine.add_action(Scenes::DeathScreen, DeathScreen::new())?;
|
||||
Ok(machine)
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user