Merge branch 'master' into wonky_blocks
This commit is contained in:
commit
e690f3dde5
@ -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)
|
||||
|
||||
}
|
||||
|
126
game/src/scenes/next_level_screen.rs
Normal file
126
game/src/scenes/next_level_screen.rs
Normal file
@ -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<Scenes, ScreenError, GameContext> 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<dirty_fsm::ActionFlag<Scenes>, 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;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user