Merge pull request #32 from Ewpratten/no_loading_screen
Remove and replace some UI elements
This commit is contained in:
commit
bf1852eee3
BIN
game/assets/background.png
Normal file
BIN
game/assets/background.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 35 KiB |
Binary file not shown.
Before Width: | Height: | Size: 35 KiB After Width: | Height: | Size: 265 KiB |
@ -21,6 +21,7 @@ pub enum CharacterState {
|
|||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct MainCharacter {
|
pub struct MainCharacter {
|
||||||
|
pub start_position: Vector2,
|
||||||
pub position: Vector2,
|
pub position: Vector2,
|
||||||
pub movement_force: Vector2,
|
pub movement_force: Vector2,
|
||||||
pub base_velocity: Vector2,
|
pub base_velocity: Vector2,
|
||||||
@ -34,6 +35,7 @@ pub struct MainCharacter {
|
|||||||
impl MainCharacter {
|
impl MainCharacter {
|
||||||
pub fn new(position: Vector2, sprite_sheet: Texture2D) -> Self {
|
pub fn new(position: Vector2, sprite_sheet: Texture2D) -> Self {
|
||||||
Self {
|
Self {
|
||||||
|
start_position: position.clone(),
|
||||||
position,
|
position,
|
||||||
movement_force: Vector2::zero(),
|
movement_force: Vector2::zero(),
|
||||||
velocity: Vector2::zero(),
|
velocity: Vector2::zero(),
|
||||||
@ -78,7 +80,7 @@ impl MainCharacter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn reset(&mut self) {
|
pub fn reset(&mut self) {
|
||||||
self.position = Vector2::new(0.0, 0.0);
|
self.position = self.start_position;
|
||||||
self.velocity = Vector2::zero();
|
self.velocity = Vector2::zero();
|
||||||
self.movement_force = Vector2::zero();
|
self.movement_force = Vector2::zero();
|
||||||
self.current_state = CharacterState::default();
|
self.current_state = CharacterState::default();
|
||||||
|
@ -5,11 +5,17 @@ use discord_sdk::activity::ActivityBuilder;
|
|||||||
use crate::{GameConfig, utilities::non_ref_raylib::HackedRaylibHandle};
|
use crate::{GameConfig, utilities::non_ref_raylib::HackedRaylibHandle};
|
||||||
|
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub enum ControlFlag {
|
||||||
|
Quit
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct GameContext {
|
pub struct GameContext {
|
||||||
pub renderer: RefCell<HackedRaylibHandle>,
|
pub renderer: RefCell<HackedRaylibHandle>,
|
||||||
pub config: GameConfig,
|
pub config: GameConfig,
|
||||||
pub discord_rpc_send: Sender<Option<ActivityBuilder>>
|
pub discord_rpc_send: Sender<Option<ActivityBuilder>>,
|
||||||
|
pub flag_send: Sender<Option<ControlFlag>>
|
||||||
}
|
}
|
||||||
|
|
||||||
// impl GameContext {
|
// impl GameContext {
|
||||||
|
@ -144,6 +144,9 @@ pub async fn game_begin(game_config: &mut GameConfig) -> Result<(), Box<dyn std:
|
|||||||
// Build an MPSC for the game to send rich presence data to discord
|
// Build an MPSC for the game to send rich presence data to discord
|
||||||
let (send_discord_rpc, recv_discord_rpc) = std::sync::mpsc::channel();
|
let (send_discord_rpc, recv_discord_rpc) = std::sync::mpsc::channel();
|
||||||
|
|
||||||
|
// Build an MPSC for signaling the control thread
|
||||||
|
let (send_control_signal, recv_control_signal) = std::sync::mpsc::channel();
|
||||||
|
|
||||||
let context;
|
let context;
|
||||||
let raylib_thread;
|
let raylib_thread;
|
||||||
{
|
{
|
||||||
@ -168,6 +171,7 @@ pub async fn game_begin(game_config: &mut GameConfig) -> Result<(), Box<dyn std:
|
|||||||
renderer: RefCell::new(rl.into()),
|
renderer: RefCell::new(rl.into()),
|
||||||
config: game_config.clone(),
|
config: game_config.clone(),
|
||||||
discord_rpc_send: send_discord_rpc,
|
discord_rpc_send: send_discord_rpc,
|
||||||
|
flag_send: send_control_signal,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -176,7 +180,7 @@ pub async fn game_begin(game_config: &mut GameConfig) -> Result<(), Box<dyn std:
|
|||||||
let mut game_state_machine =
|
let mut game_state_machine =
|
||||||
build_screen_state_machine(&mut context.renderer.borrow_mut(), &raylib_thread).unwrap();
|
build_screen_state_machine(&mut context.renderer.borrow_mut(), &raylib_thread).unwrap();
|
||||||
game_state_machine
|
game_state_machine
|
||||||
.force_change_state(Scenes::LoadingScreen)
|
.force_change_state(Scenes::MainMenuScreen)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
// Create a dynamic texture to draw to for processing by shaders
|
// Create a dynamic texture to draw to for processing by shaders
|
||||||
@ -304,6 +308,21 @@ pub async fn game_begin(game_config: &mut GameConfig) -> Result<(), Box<dyn std:
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Handle control flags
|
||||||
|
match recv_control_signal.try_recv() {
|
||||||
|
Ok(flag) => {
|
||||||
|
if let Some(flag) = flag {
|
||||||
|
match flag {
|
||||||
|
context::ControlFlag::Quit => break,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(TryRecvError::Empty) => {}
|
||||||
|
Err(TryRecvError::Disconnected) => {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -5,27 +5,31 @@ use dirty_fsm::{Action, ActionFlag};
|
|||||||
use pkg_version::pkg_version_major;
|
use pkg_version::pkg_version_major;
|
||||||
use raylib::prelude::*;
|
use raylib::prelude::*;
|
||||||
|
|
||||||
use crate::{GameConfig, context::GameContext, utilities::{
|
use crate::{
|
||||||
|
context::GameContext,
|
||||||
|
utilities::{
|
||||||
datastore::{load_texture_from_internal_data, ResourceLoadError},
|
datastore::{load_texture_from_internal_data, ResourceLoadError},
|
||||||
game_version::get_version_string,
|
game_version::get_version_string,
|
||||||
math::interpolate_exp,
|
math::interpolate_exp,
|
||||||
non_ref_raylib::HackedRaylibHandle,
|
non_ref_raylib::HackedRaylibHandle,
|
||||||
render_layer::ScreenSpaceRender,
|
render_layer::ScreenSpaceRender,
|
||||||
}};
|
},
|
||||||
|
GameConfig,
|
||||||
|
};
|
||||||
|
|
||||||
use super::{Scenes, ScreenError};
|
use super::{Scenes, ScreenError};
|
||||||
use tracing::{debug, info, trace};
|
use tracing::{debug, info, trace};
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct HowToPlayScreen {
|
pub struct HowToPlayScreen {
|
||||||
is_btm_pressed: bool //Is back to menu button pressed
|
is_btm_pressed: bool, //Is back to menu button pressed
|
||||||
}
|
}
|
||||||
|
|
||||||
impl HowToPlayScreen {
|
impl HowToPlayScreen {
|
||||||
/// Construct a new `HowToPlayScreen`
|
/// Construct a new `HowToPlayScreen`
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Self {
|
Self {
|
||||||
is_btm_pressed: false
|
is_btm_pressed: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -52,8 +56,7 @@ impl Action<Scenes, ScreenError, GameContext> for HowToPlayScreen {
|
|||||||
|
|
||||||
if self.is_btm_pressed {
|
if self.is_btm_pressed {
|
||||||
Ok(ActionFlag::SwitchState(Scenes::MainMenuScreen))
|
Ok(ActionFlag::SwitchState(Scenes::MainMenuScreen))
|
||||||
}
|
} else {
|
||||||
else{
|
|
||||||
Ok(ActionFlag::Continue)
|
Ok(ActionFlag::Continue)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -69,11 +72,19 @@ impl ScreenSpaceRender for HowToPlayScreen {
|
|||||||
fn render_screen_space(
|
fn render_screen_space(
|
||||||
&mut self,
|
&mut self,
|
||||||
raylib: &mut crate::utilities::non_ref_raylib::HackedRaylibHandle,
|
raylib: &mut crate::utilities::non_ref_raylib::HackedRaylibHandle,
|
||||||
config: &GameConfig
|
config: &GameConfig,
|
||||||
) {
|
) {
|
||||||
|
let screen_size = raylib.get_screen_size();
|
||||||
|
|
||||||
// Render the background
|
// Render the background
|
||||||
raylib.clear_background(Color::BLACK);
|
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();
|
let screen_size = raylib.get_screen_size();
|
||||||
|
|
||||||
@ -82,89 +93,34 @@ impl ScreenSpaceRender for HowToPlayScreen {
|
|||||||
|
|
||||||
let mouse_pressed: bool = raylib.is_mouse_button_pressed(MouseButton::MOUSE_LEFT_BUTTON);
|
let mouse_pressed: bool = raylib.is_mouse_button_pressed(MouseButton::MOUSE_LEFT_BUTTON);
|
||||||
|
|
||||||
raylib.draw_text(
|
//Render the title
|
||||||
|
raylib.draw_rgb_split_text(
|
||||||
|
Vector2::new(40.0, 80.0),
|
||||||
"How to Play",
|
"How to Play",
|
||||||
37,
|
|
||||||
80,
|
|
||||||
70,
|
70,
|
||||||
Color::BLUE,
|
true,
|
||||||
|
Color::WHITE,
|
||||||
);
|
);
|
||||||
|
|
||||||
raylib.draw_text(
|
// Render the instructions
|
||||||
|
raylib.draw_rgb_split_text(
|
||||||
"How to Play",
|
Vector2::new(100.0, 300.0),
|
||||||
43,
|
">> SPACE to jump\n>> SHIFT to dash\n>> Don't die",
|
||||||
80,
|
45,
|
||||||
70,
|
true,
|
||||||
Color::RED,
|
|
||||||
);
|
|
||||||
|
|
||||||
raylib.draw_text(
|
|
||||||
|
|
||||||
"How to Play",
|
|
||||||
40,
|
|
||||||
80,
|
|
||||||
70,
|
|
||||||
Color::WHITE,
|
Color::WHITE,
|
||||||
);
|
);
|
||||||
|
|
||||||
//Back to Menu
|
//Back to Menu
|
||||||
if Rectangle::new(35.0, screen_size.y as f32 - 80.0, 200.0, 40.0).check_collision_point_rec(mouse_position){
|
let hovering_back_button = Rectangle::new(35.0, screen_size.y as f32 - 80.0, 200.0, 40.0)
|
||||||
raylib.draw_text(
|
.check_collision_point_rec(mouse_position);
|
||||||
|
raylib.draw_rgb_split_text(
|
||||||
"BACK TO MENU",
|
Vector2::new(25.0, screen_size.y - 50.0),
|
||||||
28,
|
|
||||||
screen_size.y as i32 - 50,
|
|
||||||
25,
|
|
||||||
Color::RED,
|
|
||||||
);
|
|
||||||
raylib.draw_text(
|
|
||||||
|
|
||||||
"BACK TO MENU",
|
|
||||||
22,
|
|
||||||
screen_size.y as i32 - 50,
|
|
||||||
25,
|
|
||||||
Color::BLUE,
|
|
||||||
);
|
|
||||||
raylib.draw_text(
|
|
||||||
|
|
||||||
"BACK TO MENU",
|
"BACK TO MENU",
|
||||||
25,
|
25,
|
||||||
screen_size.y as i32 - 50,
|
hovering_back_button,
|
||||||
25,
|
|
||||||
Color::WHITE,
|
Color::WHITE,
|
||||||
);
|
);
|
||||||
|
self.is_btm_pressed = hovering_back_button && mouse_pressed;
|
||||||
if mouse_pressed{
|
|
||||||
self.is_btm_pressed = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
raylib.draw_text(
|
|
||||||
|
|
||||||
"BACK TO MENU",
|
|
||||||
26,
|
|
||||||
screen_size.y as i32 - 50,
|
|
||||||
25,
|
|
||||||
Color::RED,
|
|
||||||
);
|
|
||||||
raylib.draw_text(
|
|
||||||
|
|
||||||
"BACK TO MENU",
|
|
||||||
24,
|
|
||||||
screen_size.y as i32 - 50,
|
|
||||||
25,
|
|
||||||
Color::BLUE,
|
|
||||||
);
|
|
||||||
raylib.draw_text(
|
|
||||||
|
|
||||||
"BACK TO MENU",
|
|
||||||
25,
|
|
||||||
screen_size.y as i32 - 50,
|
|
||||||
25,
|
|
||||||
Color::WHITE,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -117,7 +117,8 @@ impl Action<Scenes, ScreenError, GameContext> for InGameScreen {
|
|||||||
} else if self.player_dead {
|
} else if self.player_dead {
|
||||||
|
|
||||||
// TODO: (luna) make this switch to the death screen plz
|
// TODO: (luna) make this switch to the death screen plz
|
||||||
Ok(ActionFlag::SwitchState(Scenes::FsmErrorScreen))
|
// Ok(ActionFlag::SwitchState(Scenes::FsmErrorScreen))
|
||||||
|
Ok(ActionFlag::Continue)
|
||||||
} else {
|
} else {
|
||||||
Ok(ActionFlag::Continue)
|
Ok(ActionFlag::Continue)
|
||||||
}
|
}
|
||||||
|
@ -1,164 +0,0 @@
|
|||||||
use std::ops::{Div, Sub};
|
|
||||||
|
|
||||||
use cfg_if::cfg_if;
|
|
||||||
use chrono::{DateTime, Utc};
|
|
||||||
use dirty_fsm::{Action, ActionFlag};
|
|
||||||
use discord_sdk::activity::{ActivityBuilder, Assets};
|
|
||||||
use raylib::prelude::*;
|
|
||||||
|
|
||||||
use crate::{GameConfig, context::GameContext, utilities::{
|
|
||||||
datastore::{load_texture_from_internal_data, ResourceLoadError},
|
|
||||||
math::interpolate_exp,
|
|
||||||
non_ref_raylib::HackedRaylibHandle,
|
|
||||||
render_layer::ScreenSpaceRender,
|
|
||||||
}};
|
|
||||||
|
|
||||||
use super::{Scenes, ScreenError};
|
|
||||||
use tracing::{debug, info, error, trace};
|
|
||||||
|
|
||||||
/// Defines how long the loading screen should be displayed.
|
|
||||||
const LOADING_SCREEN_DURATION_SECONDS: u8 = 3;
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub struct LoadingScreen {
|
|
||||||
start_timestamp: Option<DateTime<Utc>>,
|
|
||||||
game_logo_texture: Texture2D,
|
|
||||||
game_logo_size: Vector2,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl LoadingScreen {
|
|
||||||
/// Construct a new `LoadingScreen`
|
|
||||||
pub fn new(
|
|
||||||
raylib_handle: &mut HackedRaylibHandle,
|
|
||||||
thread: &RaylibThread,
|
|
||||||
) -> Result<Self, ResourceLoadError> {
|
|
||||||
// Load the game logo asset
|
|
||||||
let game_logo =
|
|
||||||
load_texture_from_internal_data(raylib_handle, thread, "logos/game-logo.png")?;
|
|
||||||
|
|
||||||
Ok(Self {
|
|
||||||
start_timestamp: None,
|
|
||||||
game_logo_size: Vector2::new(game_logo.width as f32, game_logo.height as f32),
|
|
||||||
game_logo_texture: game_logo,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Action<Scenes, ScreenError, GameContext> for LoadingScreen {
|
|
||||||
fn on_register(&mut self) -> Result<(), ScreenError> {
|
|
||||||
debug!("Registered");
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
fn on_first_run(&mut self, context: &GameContext) -> Result<(), ScreenError> {
|
|
||||||
debug!("Running LoadingScreen for the first time");
|
|
||||||
|
|
||||||
// Update discord
|
|
||||||
if let Err(e) = context.discord_rpc_send.send(Some(
|
|
||||||
ActivityBuilder::default().details("loading...").assets(
|
|
||||||
Assets::default().large("game-logo-small", Some(context.config.name.clone())),
|
|
||||||
),
|
|
||||||
)) {
|
|
||||||
error!("Failed to update discord: {}", e);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Keep track of when this screen is opened
|
|
||||||
self.start_timestamp = Some(Utc::now());
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
fn execute(
|
|
||||||
&mut self,
|
|
||||||
_delta: &chrono::Duration,
|
|
||||||
context: &GameContext,
|
|
||||||
) -> Result<dirty_fsm::ActionFlag<Scenes>, ScreenError> {
|
|
||||||
trace!("execute() called on LoadingScreen");
|
|
||||||
self.render_screen_space(&mut context.renderer.borrow_mut(), &context.config);
|
|
||||||
|
|
||||||
// Check for a quick skip button in debug builds
|
|
||||||
cfg_if! {
|
|
||||||
if #[cfg(debug_assertions)] {
|
|
||||||
let debug_skip_screen = context.renderer.borrow_mut().is_key_pressed(KeyboardKey::KEY_ESCAPE);
|
|
||||||
} else {
|
|
||||||
let debug_skip_screen = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Keep rendering until we pass the loading screen duration
|
|
||||||
if let Some(start_timestamp) = self.start_timestamp {
|
|
||||||
let duration = Utc::now().signed_duration_since(start_timestamp);
|
|
||||||
if duration.num_seconds() >= LOADING_SCREEN_DURATION_SECONDS as i64 || debug_skip_screen
|
|
||||||
{
|
|
||||||
info!("LoadingScreen duration reached, moving to next screen");
|
|
||||||
Ok(ActionFlag::SwitchState(Scenes::MainMenuScreen))
|
|
||||||
} else {
|
|
||||||
Ok(ActionFlag::Continue)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
Ok(ActionFlag::Continue)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn on_finish(&mut self, _interrupted: bool) -> Result<(), ScreenError> {
|
|
||||||
debug!("Finished LoadingScreen");
|
|
||||||
|
|
||||||
// Reset the start timestamp
|
|
||||||
self.start_timestamp = None;
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ScreenSpaceRender for LoadingScreen {
|
|
||||||
fn render_screen_space(
|
|
||||||
&mut self,
|
|
||||||
raylib: &mut crate::utilities::non_ref_raylib::HackedRaylibHandle,
|
|
||||||
config: &GameConfig
|
|
||||||
) {
|
|
||||||
// Calculate the loading screen fade in/out value
|
|
||||||
// This makes the loading screen fade in/out over the duration of the loading screen
|
|
||||||
let cur_time = Utc::now();
|
|
||||||
let time_since_start =
|
|
||||||
cur_time.signed_duration_since(self.start_timestamp.unwrap_or(cur_time));
|
|
||||||
let fade_percentage = interpolate_exp(
|
|
||||||
time_since_start.num_milliseconds() as f32,
|
|
||||||
0.0..(LOADING_SCREEN_DURATION_SECONDS as f32 * 1000.0),
|
|
||||||
0.0..1.0,
|
|
||||||
8.0,
|
|
||||||
);
|
|
||||||
trace!("Loading screen fade at {:.2}%", fade_percentage);
|
|
||||||
|
|
||||||
// Render the background
|
|
||||||
raylib.clear_background(Color::BLACK);
|
|
||||||
|
|
||||||
// Calculate the logo position
|
|
||||||
let screen_size = raylib.get_screen_size();
|
|
||||||
|
|
||||||
// Render the game logo
|
|
||||||
raylib.draw_texture_ex(
|
|
||||||
&self.game_logo_texture,
|
|
||||||
screen_size.div(2.0).sub(self.game_logo_size.div(2.0)),
|
|
||||||
0.0,
|
|
||||||
1.0,
|
|
||||||
Color::WHITE.fade(fade_percentage),
|
|
||||||
);
|
|
||||||
|
|
||||||
// Only in debug mode, render a debug message
|
|
||||||
#[cfg(debug_assertions)]
|
|
||||||
{
|
|
||||||
raylib.draw_rectangle_v(
|
|
||||||
Vector2::zero(),
|
|
||||||
Vector2::new(screen_size.x, 40.0),
|
|
||||||
Color::RED,
|
|
||||||
);
|
|
||||||
raylib.draw_text(
|
|
||||||
"Game in DEBUG MODE. Do not redistribute!",
|
|
||||||
10,
|
|
||||||
10,
|
|
||||||
20,
|
|
||||||
Color::WHITE,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -6,29 +6,23 @@ use discord_sdk::activity::{ActivityBuilder, Assets};
|
|||||||
use pkg_version::pkg_version_major;
|
use pkg_version::pkg_version_major;
|
||||||
use raylib::prelude::*;
|
use raylib::prelude::*;
|
||||||
|
|
||||||
use crate::{
|
use crate::{GameConfig, context::{ControlFlag, GameContext}, utilities::{
|
||||||
context::GameContext,
|
|
||||||
utilities::{
|
|
||||||
datastore::{load_texture_from_internal_data, ResourceLoadError},
|
datastore::{load_texture_from_internal_data, ResourceLoadError},
|
||||||
game_version::get_version_string,
|
game_version::get_version_string,
|
||||||
math::interpolate_exp,
|
math::interpolate_exp,
|
||||||
non_ref_raylib::HackedRaylibHandle,
|
non_ref_raylib::HackedRaylibHandle,
|
||||||
render_layer::ScreenSpaceRender,
|
render_layer::ScreenSpaceRender,
|
||||||
},
|
}};
|
||||||
GameConfig,
|
|
||||||
};
|
|
||||||
|
|
||||||
use super::{Scenes, ScreenError};
|
use super::{Scenes, ScreenError};
|
||||||
use tracing::{debug, error, info, trace};
|
use tracing::{debug, error, info, trace};
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct MainMenuScreen {
|
pub struct MainMenuScreen {
|
||||||
|
|
||||||
is_start_pressed: bool, //Is start button pressed
|
is_start_pressed: bool, //Is start button pressed
|
||||||
is_htp_pressed: bool, //Is how to play button pressed
|
is_htp_pressed: bool, //Is how to play button pressed
|
||||||
is_options_pressed: bool, //Is options button pressed
|
is_options_pressed: bool, //Is options button pressed
|
||||||
is_quit_pressed: bool //Is quit button pressed
|
is_quit_pressed: bool, //Is quit button pressed
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl MainMenuScreen {
|
impl MainMenuScreen {
|
||||||
@ -38,7 +32,7 @@ impl MainMenuScreen {
|
|||||||
is_start_pressed: false,
|
is_start_pressed: false,
|
||||||
is_htp_pressed: false,
|
is_htp_pressed: false,
|
||||||
is_options_pressed: false,
|
is_options_pressed: false,
|
||||||
is_quit_pressed: false
|
is_quit_pressed: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -74,17 +68,14 @@ impl Action<Scenes, ScreenError, GameContext> for MainMenuScreen {
|
|||||||
|
|
||||||
if self.is_start_pressed {
|
if self.is_start_pressed {
|
||||||
Ok(ActionFlag::SwitchState(Scenes::InGameScene))
|
Ok(ActionFlag::SwitchState(Scenes::InGameScene))
|
||||||
}
|
} else if self.is_htp_pressed {
|
||||||
else if self.is_htp_pressed {
|
|
||||||
Ok(ActionFlag::SwitchState(Scenes::HowToPlayScreen))
|
Ok(ActionFlag::SwitchState(Scenes::HowToPlayScreen))
|
||||||
}
|
} else if self.is_options_pressed {
|
||||||
else if self.is_options_pressed {
|
|
||||||
Ok(ActionFlag::SwitchState(Scenes::OptionsScreen))
|
Ok(ActionFlag::SwitchState(Scenes::OptionsScreen))
|
||||||
}
|
} else if self.is_quit_pressed {
|
||||||
else if self.is_quit_pressed {
|
context.flag_send.send(Some(ControlFlag::Quit)).unwrap();
|
||||||
panic!();
|
Ok(ActionFlag::Continue)
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
Ok(ActionFlag::Continue)
|
Ok(ActionFlag::Continue)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -105,8 +96,17 @@ impl ScreenSpaceRender for MainMenuScreen {
|
|||||||
raylib: &mut crate::utilities::non_ref_raylib::HackedRaylibHandle,
|
raylib: &mut crate::utilities::non_ref_raylib::HackedRaylibHandle,
|
||||||
config: &GameConfig,
|
config: &GameConfig,
|
||||||
) {
|
) {
|
||||||
|
let screen_size = raylib.get_screen_size();
|
||||||
|
|
||||||
// Render the background
|
// Render the background
|
||||||
raylib.clear_background(Color::BLACK);
|
raylib.clear_background(Color::BLACK);
|
||||||
|
raylib.draw_rectangle_lines(
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
screen_size.x as i32,
|
||||||
|
screen_size.y as i32,
|
||||||
|
config.colors.white,
|
||||||
|
);
|
||||||
|
|
||||||
// Calculate the logo position
|
// Calculate the logo position
|
||||||
let screen_size = raylib.get_screen_size();
|
let screen_size = raylib.get_screen_size();
|
||||||
@ -150,269 +150,61 @@ impl ScreenSpaceRender for MainMenuScreen {
|
|||||||
Color::WHITE,
|
Color::WHITE,
|
||||||
);
|
);
|
||||||
|
|
||||||
raylib.draw_text(
|
// Render the title
|
||||||
|
raylib.draw_rgb_split_text(
|
||||||
|
Vector2::new(37.0, 80.0),
|
||||||
&format!("[{}]", config.name),
|
&format!("[{}]", config.name),
|
||||||
37,
|
|
||||||
80,
|
|
||||||
70,
|
|
||||||
Color::BLUE,
|
|
||||||
);
|
|
||||||
|
|
||||||
raylib.draw_text(
|
|
||||||
|
|
||||||
&format!("[{}]", config.name),
|
|
||||||
43,
|
|
||||||
80,
|
|
||||||
70,
|
|
||||||
Color::RED,
|
|
||||||
);
|
|
||||||
|
|
||||||
raylib.draw_text(
|
|
||||||
|
|
||||||
&format!("[{}]", config.name),
|
|
||||||
40,
|
|
||||||
80,
|
|
||||||
70,
|
70,
|
||||||
|
true,
|
||||||
Color::WHITE,
|
Color::WHITE,
|
||||||
);
|
);
|
||||||
|
|
||||||
// Start Game
|
// Start Game
|
||||||
if Rectangle::new(80.0, 300.0, 170.0, 20.0).check_collision_point_rec(mouse_position) {
|
let hovering_start_game =
|
||||||
raylib.draw_text(
|
Rectangle::new(80.0, 300.0, 170.0, 20.0).check_collision_point_rec(mouse_position);
|
||||||
|
raylib.draw_rgb_split_text(
|
||||||
|
Vector2::new(80.0, 300.0),
|
||||||
"START GAME",
|
"START GAME",
|
||||||
83,
|
|
||||||
300,
|
|
||||||
25,
|
|
||||||
Color::RED,
|
|
||||||
);
|
|
||||||
raylib.draw_text(
|
|
||||||
|
|
||||||
"START GAME",
|
|
||||||
77,
|
|
||||||
300,
|
|
||||||
25,
|
|
||||||
Color::BLUE,
|
|
||||||
);
|
|
||||||
raylib.draw_text(
|
|
||||||
|
|
||||||
"START GAME",
|
|
||||||
80,
|
|
||||||
300,
|
|
||||||
25,
|
25,
|
||||||
|
hovering_start_game,
|
||||||
Color::WHITE,
|
Color::WHITE,
|
||||||
);
|
);
|
||||||
|
self.is_start_pressed = mouse_pressed && hovering_start_game;
|
||||||
if mouse_pressed{
|
|
||||||
self.is_start_pressed = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
raylib.draw_text(
|
|
||||||
|
|
||||||
"START GAME",
|
|
||||||
81,
|
|
||||||
300,
|
|
||||||
25,
|
|
||||||
Color::RED,
|
|
||||||
);
|
|
||||||
raylib.draw_text(
|
|
||||||
|
|
||||||
"START GAME",
|
|
||||||
79,
|
|
||||||
300,
|
|
||||||
25,
|
|
||||||
Color::BLUE,
|
|
||||||
);
|
|
||||||
raylib.draw_text(
|
|
||||||
|
|
||||||
"START GAME",
|
|
||||||
80,
|
|
||||||
300,
|
|
||||||
25,
|
|
||||||
Color::WHITE,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// How to Play
|
// How to Play
|
||||||
if Rectangle::new(80.0, 350.0, 170.0, 20.0).check_collision_point_rec(mouse_position) {
|
let hovering_htp =
|
||||||
raylib.draw_text(
|
Rectangle::new(80.0, 350.0, 170.0, 20.0).check_collision_point_rec(mouse_position);
|
||||||
|
raylib.draw_rgb_split_text(
|
||||||
|
Vector2::new(80.0, 350.0),
|
||||||
"HOW TO PLAY",
|
"HOW TO PLAY",
|
||||||
83,
|
|
||||||
350,
|
|
||||||
25,
|
|
||||||
Color::RED,
|
|
||||||
);
|
|
||||||
raylib.draw_text(
|
|
||||||
|
|
||||||
"HOW TO PLAY",
|
|
||||||
77,
|
|
||||||
350,
|
|
||||||
25,
|
|
||||||
Color::BLUE,
|
|
||||||
);
|
|
||||||
raylib.draw_text(
|
|
||||||
|
|
||||||
"HOW TO PLAY",
|
|
||||||
80,
|
|
||||||
350,
|
|
||||||
25,
|
25,
|
||||||
|
hovering_htp,
|
||||||
Color::WHITE,
|
Color::WHITE,
|
||||||
);
|
);
|
||||||
|
self.is_htp_pressed = mouse_pressed && hovering_htp;
|
||||||
if mouse_pressed{
|
|
||||||
self.is_htp_pressed = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
raylib.draw_text(
|
|
||||||
|
|
||||||
"HOW TO PLAY",
|
|
||||||
81,
|
|
||||||
350,
|
|
||||||
25,
|
|
||||||
Color::RED,
|
|
||||||
);
|
|
||||||
raylib.draw_text(
|
|
||||||
|
|
||||||
"HOW TO PLAY",
|
|
||||||
79,
|
|
||||||
350,
|
|
||||||
25,
|
|
||||||
Color::BLUE,
|
|
||||||
);
|
|
||||||
raylib.draw_text(
|
|
||||||
|
|
||||||
"HOW TO PLAY",
|
|
||||||
80,
|
|
||||||
350,
|
|
||||||
25,
|
|
||||||
Color::WHITE,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// OPTIONS
|
// OPTIONS
|
||||||
if Rectangle::new(80.0, 400.0, 135.0, 20.0).check_collision_point_rec(mouse_position) {
|
let hovering_options =
|
||||||
raylib.draw_text(
|
Rectangle::new(80.0, 400.0, 135.0, 20.0).check_collision_point_rec(mouse_position);
|
||||||
|
raylib.draw_rgb_split_text(
|
||||||
|
Vector2::new(80.0, 400.0),
|
||||||
"OPTIONS",
|
"OPTIONS",
|
||||||
83,
|
|
||||||
400,
|
|
||||||
25,
|
|
||||||
Color::RED,
|
|
||||||
);
|
|
||||||
raylib.draw_text(
|
|
||||||
|
|
||||||
"OPTIONS",
|
|
||||||
77,
|
|
||||||
400,
|
|
||||||
25,
|
|
||||||
Color::BLUE,
|
|
||||||
);
|
|
||||||
raylib.draw_text(
|
|
||||||
|
|
||||||
"OPTIONS",
|
|
||||||
80,
|
|
||||||
400,
|
|
||||||
25,
|
25,
|
||||||
|
hovering_options,
|
||||||
Color::WHITE,
|
Color::WHITE,
|
||||||
);
|
);
|
||||||
|
self.is_options_pressed = mouse_pressed && hovering_options;
|
||||||
if mouse_pressed{
|
|
||||||
self.is_options_pressed = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
raylib.draw_text(
|
|
||||||
|
|
||||||
"OPTIONS",
|
|
||||||
81,
|
|
||||||
400,
|
|
||||||
25,
|
|
||||||
Color::RED,
|
|
||||||
);
|
|
||||||
raylib.draw_text(
|
|
||||||
|
|
||||||
"OPTIONS",
|
|
||||||
79,
|
|
||||||
400,
|
|
||||||
25,
|
|
||||||
Color::BLUE,
|
|
||||||
);
|
|
||||||
raylib.draw_text(
|
|
||||||
|
|
||||||
"OPTIONS",
|
|
||||||
80,
|
|
||||||
400,
|
|
||||||
25,
|
|
||||||
Color::WHITE,
|
|
||||||
);
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// QUIT
|
// QUIT
|
||||||
if Rectangle::new(80.0, 445.0, 65.0, 20.0).check_collision_point_rec(mouse_position) {
|
let hovering_quit =
|
||||||
raylib.draw_text(
|
Rectangle::new(80.0, 445.0, 65.0, 20.0).check_collision_point_rec(mouse_position);
|
||||||
|
raylib.draw_rgb_split_text(
|
||||||
|
Vector2::new(80.0, 450.0),
|
||||||
"QUIT",
|
"QUIT",
|
||||||
83,
|
|
||||||
450,
|
|
||||||
25,
|
|
||||||
Color::RED,
|
|
||||||
);
|
|
||||||
raylib.draw_text(
|
|
||||||
|
|
||||||
"QUIT",
|
|
||||||
77,
|
|
||||||
450,
|
|
||||||
25,
|
|
||||||
Color::BLUE,
|
|
||||||
);
|
|
||||||
raylib.draw_text(
|
|
||||||
|
|
||||||
"QUIT",
|
|
||||||
80,
|
|
||||||
450,
|
|
||||||
25,
|
25,
|
||||||
|
hovering_quit,
|
||||||
Color::WHITE,
|
Color::WHITE,
|
||||||
);
|
);
|
||||||
|
self.is_quit_pressed = mouse_pressed && hovering_quit;
|
||||||
if mouse_pressed{
|
|
||||||
self.is_quit_pressed = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
raylib.draw_text(
|
|
||||||
|
|
||||||
"QUIT",
|
|
||||||
81,
|
|
||||||
450,
|
|
||||||
25,
|
|
||||||
Color::RED,
|
|
||||||
);
|
|
||||||
raylib.draw_text(
|
|
||||||
|
|
||||||
"QUIT",
|
|
||||||
79,
|
|
||||||
450,
|
|
||||||
25,
|
|
||||||
Color::BLUE,
|
|
||||||
);
|
|
||||||
raylib.draw_text(
|
|
||||||
|
|
||||||
"QUIT",
|
|
||||||
80,
|
|
||||||
450,
|
|
||||||
25,
|
|
||||||
Color::WHITE,
|
|
||||||
);
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,6 @@ use self::{
|
|||||||
pause_screen::PauseScreen,
|
pause_screen::PauseScreen,
|
||||||
fsm_error_screen::FsmErrorScreen,
|
fsm_error_screen::FsmErrorScreen,
|
||||||
ingame_scene::{level::loader::load_all_levels, InGameScreen},
|
ingame_scene::{level::loader::load_all_levels, InGameScreen},
|
||||||
loading_screen::LoadingScreen,
|
|
||||||
main_menu_screen::MainMenuScreen, options_screen::OptionsScreen, how_to_play_screen::HowToPlayScreen,
|
main_menu_screen::MainMenuScreen, options_screen::OptionsScreen, how_to_play_screen::HowToPlayScreen,
|
||||||
};
|
};
|
||||||
use crate::{
|
use crate::{
|
||||||
@ -17,7 +16,6 @@ use raylib::{texture::Texture2D, RaylibThread};
|
|||||||
|
|
||||||
pub mod fsm_error_screen;
|
pub mod fsm_error_screen;
|
||||||
pub mod ingame_scene;
|
pub mod ingame_scene;
|
||||||
pub mod loading_screen;
|
|
||||||
pub mod main_menu_screen;
|
pub mod main_menu_screen;
|
||||||
pub mod how_to_play_screen;
|
pub mod how_to_play_screen;
|
||||||
pub mod options_screen;
|
pub mod options_screen;
|
||||||
@ -28,7 +26,6 @@ pub mod pause_screen;
|
|||||||
pub enum Scenes {
|
pub enum Scenes {
|
||||||
#[default]
|
#[default]
|
||||||
FsmErrorScreen,
|
FsmErrorScreen,
|
||||||
LoadingScreen,
|
|
||||||
MainMenuScreen,
|
MainMenuScreen,
|
||||||
InGameScene,
|
InGameScene,
|
||||||
HowToPlayScreen,
|
HowToPlayScreen,
|
||||||
@ -62,10 +59,6 @@ pub fn build_screen_state_machine(
|
|||||||
// Set up the state machine
|
// Set up the state machine
|
||||||
let mut machine = StateMachine::new();
|
let mut machine = StateMachine::new();
|
||||||
machine.add_action(Scenes::FsmErrorScreen, FsmErrorScreen::new())?;
|
machine.add_action(Scenes::FsmErrorScreen, FsmErrorScreen::new())?;
|
||||||
machine.add_action(
|
|
||||||
Scenes::LoadingScreen,
|
|
||||||
LoadingScreen::new(raylib_handle, thread)?,
|
|
||||||
)?;
|
|
||||||
machine.add_action(Scenes::MainMenuScreen, MainMenuScreen::new())?;
|
machine.add_action(Scenes::MainMenuScreen, MainMenuScreen::new())?;
|
||||||
machine.add_action(Scenes::HowToPlayScreen, HowToPlayScreen::new())?;
|
machine.add_action(Scenes::HowToPlayScreen, HowToPlayScreen::new())?;
|
||||||
machine.add_action(Scenes::OptionsScreen, OptionsScreen::new())?;
|
machine.add_action(Scenes::OptionsScreen, OptionsScreen::new())?;
|
||||||
|
@ -5,27 +5,31 @@ use dirty_fsm::{Action, ActionFlag};
|
|||||||
use pkg_version::pkg_version_major;
|
use pkg_version::pkg_version_major;
|
||||||
use raylib::prelude::*;
|
use raylib::prelude::*;
|
||||||
|
|
||||||
use crate::{GameConfig, context::GameContext, utilities::{
|
use crate::{
|
||||||
|
context::GameContext,
|
||||||
|
utilities::{
|
||||||
datastore::{load_texture_from_internal_data, ResourceLoadError},
|
datastore::{load_texture_from_internal_data, ResourceLoadError},
|
||||||
game_version::get_version_string,
|
game_version::get_version_string,
|
||||||
math::interpolate_exp,
|
math::interpolate_exp,
|
||||||
non_ref_raylib::HackedRaylibHandle,
|
non_ref_raylib::HackedRaylibHandle,
|
||||||
render_layer::ScreenSpaceRender,
|
render_layer::ScreenSpaceRender,
|
||||||
}};
|
},
|
||||||
|
GameConfig,
|
||||||
|
};
|
||||||
|
|
||||||
use super::{Scenes, ScreenError};
|
use super::{Scenes, ScreenError};
|
||||||
use tracing::{debug, info, trace};
|
use tracing::{debug, info, trace};
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct OptionsScreen {
|
pub struct OptionsScreen {
|
||||||
is_btm_pressed: bool //Is back to menu button pressed
|
is_btm_pressed: bool, //Is back to menu button pressed
|
||||||
}
|
}
|
||||||
|
|
||||||
impl OptionsScreen {
|
impl OptionsScreen {
|
||||||
/// Construct a new `OptionsScreen`
|
/// Construct a new `OptionsScreen`
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Self {
|
Self {
|
||||||
is_btm_pressed: false
|
is_btm_pressed: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -52,8 +56,7 @@ impl Action<Scenes, ScreenError, GameContext> for OptionsScreen {
|
|||||||
|
|
||||||
if self.is_btm_pressed {
|
if self.is_btm_pressed {
|
||||||
Ok(ActionFlag::SwitchState(Scenes::MainMenuScreen))
|
Ok(ActionFlag::SwitchState(Scenes::MainMenuScreen))
|
||||||
}
|
} else {
|
||||||
else{
|
|
||||||
Ok(ActionFlag::Continue)
|
Ok(ActionFlag::Continue)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -69,11 +72,19 @@ impl ScreenSpaceRender for OptionsScreen {
|
|||||||
fn render_screen_space(
|
fn render_screen_space(
|
||||||
&mut self,
|
&mut self,
|
||||||
raylib: &mut crate::utilities::non_ref_raylib::HackedRaylibHandle,
|
raylib: &mut crate::utilities::non_ref_raylib::HackedRaylibHandle,
|
||||||
config: &GameConfig
|
config: &GameConfig,
|
||||||
) {
|
) {
|
||||||
|
let screen_size = raylib.get_screen_size();
|
||||||
|
|
||||||
// Render the background
|
// Render the background
|
||||||
raylib.clear_background(Color::BLACK);
|
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();
|
let screen_size = raylib.get_screen_size();
|
||||||
|
|
||||||
@ -82,90 +93,19 @@ impl ScreenSpaceRender for OptionsScreen {
|
|||||||
|
|
||||||
let mouse_pressed: bool = raylib.is_mouse_button_pressed(MouseButton::MOUSE_LEFT_BUTTON);
|
let mouse_pressed: bool = raylib.is_mouse_button_pressed(MouseButton::MOUSE_LEFT_BUTTON);
|
||||||
|
|
||||||
raylib.draw_text(
|
// Render the title
|
||||||
|
raylib.draw_rgb_split_text(Vector2::new(40.0, 80.0), "Options", 70, true, Color::WHITE);
|
||||||
"Options",
|
|
||||||
37,
|
|
||||||
80,
|
|
||||||
70,
|
|
||||||
Color::BLUE,
|
|
||||||
);
|
|
||||||
|
|
||||||
raylib.draw_text(
|
|
||||||
|
|
||||||
"Options",
|
|
||||||
43,
|
|
||||||
80,
|
|
||||||
70,
|
|
||||||
Color::RED,
|
|
||||||
);
|
|
||||||
|
|
||||||
raylib.draw_text(
|
|
||||||
|
|
||||||
"Options",
|
|
||||||
40,
|
|
||||||
80,
|
|
||||||
70,
|
|
||||||
Color::WHITE,
|
|
||||||
);
|
|
||||||
|
|
||||||
//Back to Menu
|
//Back to Menu
|
||||||
if Rectangle::new(35.0, screen_size.y as f32 - 80.0, 200.0, 40.0).check_collision_point_rec(mouse_position){
|
let hovering_back = Rectangle::new(35.0, screen_size.y as f32 - 80.0, 200.0, 40.0)
|
||||||
raylib.draw_text(
|
.check_collision_point_rec(mouse_position);
|
||||||
|
raylib.draw_rgb_split_text(
|
||||||
"BACK TO MENU",
|
Vector2::new(25.0, screen_size.y - 50.0),
|
||||||
28,
|
"Options",
|
||||||
screen_size.y as i32 - 50,
|
|
||||||
25,
|
|
||||||
Color::RED,
|
|
||||||
);
|
|
||||||
raylib.draw_text(
|
|
||||||
|
|
||||||
"BACK TO MENU",
|
|
||||||
22,
|
|
||||||
screen_size.y as i32 - 50,
|
|
||||||
25,
|
|
||||||
Color::BLUE,
|
|
||||||
);
|
|
||||||
raylib.draw_text(
|
|
||||||
|
|
||||||
"BACK TO MENU",
|
|
||||||
25,
|
|
||||||
screen_size.y as i32 - 50,
|
|
||||||
25,
|
25,
|
||||||
|
hovering_back,
|
||||||
Color::WHITE,
|
Color::WHITE,
|
||||||
);
|
);
|
||||||
|
self.is_btm_pressed = mouse_pressed && hovering_back;
|
||||||
if mouse_pressed{
|
|
||||||
self.is_btm_pressed = true;
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
raylib.draw_text(
|
|
||||||
|
|
||||||
"BACK TO MENU",
|
|
||||||
26,
|
|
||||||
screen_size.y as i32 - 50,
|
|
||||||
25,
|
|
||||||
Color::RED,
|
|
||||||
);
|
|
||||||
raylib.draw_text(
|
|
||||||
|
|
||||||
"BACK TO MENU",
|
|
||||||
24,
|
|
||||||
screen_size.y as i32 - 50,
|
|
||||||
25,
|
|
||||||
Color::BLUE,
|
|
||||||
);
|
|
||||||
raylib.draw_text(
|
|
||||||
|
|
||||||
"BACK TO MENU",
|
|
||||||
25,
|
|
||||||
screen_size.y as i32 - 50,
|
|
||||||
25,
|
|
||||||
Color::WHITE,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -59,6 +59,13 @@ impl Action<Scenes, ScreenError, GameContext> for PauseScreen {
|
|||||||
) -> Result<dirty_fsm::ActionFlag<Scenes>, ScreenError> {
|
) -> Result<dirty_fsm::ActionFlag<Scenes>, ScreenError> {
|
||||||
trace!("execute() called on PauseScreen");
|
trace!("execute() called on PauseScreen");
|
||||||
self.render_screen_space(&mut context.renderer.borrow_mut(), &context.config);
|
self.render_screen_space(&mut context.renderer.borrow_mut(), &context.config);
|
||||||
|
//Screen Size
|
||||||
|
let screen_size = context.renderer.borrow_mut().get_screen_size();
|
||||||
|
|
||||||
|
let centered_x_menu = (screen_size.x as f32 / 2.0) - 120.0;
|
||||||
|
let centered_y_menu = (screen_size.y as f32 / 2.0) + 100.0;
|
||||||
|
let centered_x_paused = (screen_size.x as f32 / 2.0) - 220.0;
|
||||||
|
let centered_y_paused = (screen_size.y as f32 / 2.0) - 40.0;
|
||||||
|
|
||||||
//Mouse Position
|
//Mouse Position
|
||||||
let mouse_position: Vector2 = context.renderer.borrow_mut().get_mouse_position();
|
let mouse_position: Vector2 = context.renderer.borrow_mut().get_mouse_position();
|
||||||
@ -69,14 +76,18 @@ impl Action<Scenes, ScreenError, GameContext> for PauseScreen {
|
|||||||
.is_mouse_button_down(MouseButton::MOUSE_LEFT_BUTTON);
|
.is_mouse_button_down(MouseButton::MOUSE_LEFT_BUTTON);
|
||||||
|
|
||||||
//"Hitboxes" for the resume and Main menu buttons
|
//"Hitboxes" for the resume and Main menu buttons
|
||||||
|
|
||||||
|
//For Paused
|
||||||
if is_left_click
|
if is_left_click
|
||||||
&& Rectangle::new(322.0, 321.0, 435.0, 80.0).check_collision_point_rec(mouse_position)
|
&& Rectangle::new(centered_x_paused, centered_y_paused, 435.0, 80.0)
|
||||||
|
.check_collision_point_rec(mouse_position)
|
||||||
{
|
{
|
||||||
return Ok(ActionFlag::SwitchState(Scenes::InGameScene));
|
return Ok(ActionFlag::SwitchState(Scenes::InGameScene));
|
||||||
}
|
}
|
||||||
|
//For Menu
|
||||||
if is_left_click
|
if is_left_click
|
||||||
&& Rectangle::new(390.0, 464.0, 200.0, 50.0).check_collision_point_rec(mouse_position)
|
&& Rectangle::new(centered_x_menu, centered_y_menu, 200.0, 50.0)
|
||||||
|
.check_collision_point_rec(mouse_position)
|
||||||
{
|
{
|
||||||
return Ok(ActionFlag::SwitchState(Scenes::MainMenuScreen));
|
return Ok(ActionFlag::SwitchState(Scenes::MainMenuScreen));
|
||||||
}
|
}
|
||||||
@ -114,89 +125,45 @@ impl ScreenSpaceRender for PauseScreen {
|
|||||||
//Mouse Input
|
//Mouse Input
|
||||||
let is_left_click = raylib.is_mouse_button_down(MouseButton::MOUSE_LEFT_BUTTON);
|
let is_left_click = raylib.is_mouse_button_down(MouseButton::MOUSE_LEFT_BUTTON);
|
||||||
|
|
||||||
|
raylib.draw_rectangle_lines(
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
screen_size.x as i32,
|
||||||
|
screen_size.y as i32,
|
||||||
|
config.colors.white,
|
||||||
|
);
|
||||||
|
|
||||||
|
//Variables for centering
|
||||||
|
let centered_x_menu = (screen_size.x as f32 / 2.0) - 120.0;
|
||||||
|
let centered_y_menu = (screen_size.y as f32 / 2.0) + 100.0;
|
||||||
|
let centered_x_paused = (screen_size.x as f32 / 2.0) - 220.0;
|
||||||
|
let centered_y_paused = (screen_size.y as f32 / 2.0) - 40.0;
|
||||||
|
|
||||||
//Pause Menu Texts With Glitchy Effect
|
//Pause Menu Texts With Glitchy Effect
|
||||||
raylib.draw_text(
|
let hovering_pause = Rectangle::new(centered_x_paused, centered_y_paused, 435.0, 80.0)
|
||||||
|
.check_collision_point_rec(mouse_position);
|
||||||
|
raylib.draw_rgb_split_text(
|
||||||
|
Vector2::new((screen_size.x / 2.0) - 220.0, (screen_size.y / 2.0) - 40.0),
|
||||||
"Paused",
|
"Paused",
|
||||||
(screen_size.x as i32 / 2) - 223,
|
|
||||||
(screen_size.y as i32 / 2) - 40,
|
|
||||||
120,
|
|
||||||
Color::RED,
|
|
||||||
);
|
|
||||||
raylib.draw_text(
|
|
||||||
"Paused",
|
|
||||||
(screen_size.x as i32 / 2) - 217,
|
|
||||||
(screen_size.y as i32 / 2) - 40,
|
|
||||||
120,
|
|
||||||
Color::BLUE,
|
|
||||||
);
|
|
||||||
raylib.draw_text(
|
|
||||||
"Paused",
|
|
||||||
(screen_size.x as i32 / 2) - 220,
|
|
||||||
(screen_size.y as i32 / 2) - 40,
|
|
||||||
120,
|
120,
|
||||||
|
hovering_pause,
|
||||||
Color::WHITE,
|
Color::WHITE,
|
||||||
);
|
);
|
||||||
raylib.draw_text(
|
raylib.draw_rgb_split_text(
|
||||||
|
Vector2::new((screen_size.x / 2.0) - 80.0, (screen_size.y / 2.0) + 60.0),
|
||||||
"Click To Resume",
|
"Click To Resume",
|
||||||
(screen_size.x as i32 / 2) - 80,
|
|
||||||
(screen_size.y as i32 / 2) + 60,
|
|
||||||
20,
|
|
||||||
Color::RED,
|
|
||||||
);
|
|
||||||
raylib.draw_text(
|
|
||||||
"Click To Resume",
|
|
||||||
(screen_size.x as i32 / 2) - 80,
|
|
||||||
(screen_size.y as i32 / 2) + 60,
|
|
||||||
20,
|
|
||||||
Color::BLUE,
|
|
||||||
);
|
|
||||||
raylib.draw_text(
|
|
||||||
"Click To Resume",
|
|
||||||
(screen_size.x as i32 / 2) - 80,
|
|
||||||
(screen_size.y as i32 / 2) + 60,
|
|
||||||
20,
|
20,
|
||||||
|
false,
|
||||||
Color::WHITE,
|
Color::WHITE,
|
||||||
);
|
);
|
||||||
raylib.draw_text(
|
let hovering_main_menu = Rectangle::new(centered_x_menu, centered_y_menu, 200.0, 50.0)
|
||||||
|
.check_collision_point_rec(mouse_position);
|
||||||
|
raylib.draw_rgb_split_text(
|
||||||
|
Vector2::new((screen_size.x / 2.0) - 120.0, (screen_size.y / 2.0) + 100.0),
|
||||||
"Main Menu",
|
"Main Menu",
|
||||||
(screen_size.x as i32 / 2) - 123,
|
|
||||||
(screen_size.y as i32 / 2) + 100,
|
|
||||||
50,
|
|
||||||
Color::RED,
|
|
||||||
);
|
|
||||||
raylib.draw_text(
|
|
||||||
"Main Menu",
|
|
||||||
(screen_size.x as i32 / 2) - 117,
|
|
||||||
(screen_size.y as i32 / 2) + 100,
|
|
||||||
50,
|
|
||||||
Color::BLUE,
|
|
||||||
);
|
|
||||||
raylib.draw_text(
|
|
||||||
"Main Menu",
|
|
||||||
(screen_size.x as i32 / 2) - 120,
|
|
||||||
(screen_size.y as i32 / 2) + 100,
|
|
||||||
50,
|
50,
|
||||||
|
hovering_main_menu,
|
||||||
Color::WHITE,
|
Color::WHITE,
|
||||||
);
|
);
|
||||||
|
|
||||||
if Rectangle::new(390.0, 464.0, 200.0, 50.0).check_collision_point_rec(mouse_position) {
|
|
||||||
raylib.draw_text(
|
|
||||||
"Main Menu",
|
|
||||||
(screen_size.x as i32 / 2) - 120,
|
|
||||||
(screen_size.y as i32 / 2) + 100,
|
|
||||||
50,
|
|
||||||
Color::YELLOW,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if Rectangle::new(322.0, 321.0, 435.0, 80.0).check_collision_point_rec(mouse_position) {
|
|
||||||
raylib.draw_text(
|
|
||||||
"Paused",
|
|
||||||
(screen_size.x as i32 / 2) - 220,
|
|
||||||
(screen_size.y as i32 / 2) - 40,
|
|
||||||
120,
|
|
||||||
Color::DARKBLUE,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
use std::ops::{Deref, DerefMut};
|
use std::ops::{Deref, DerefMut};
|
||||||
|
|
||||||
|
use raylib::prelude::*;
|
||||||
use raylib::{math::Vector2, prelude::RaylibDraw, RaylibHandle};
|
use raylib::{math::Vector2, prelude::RaylibDraw, RaylibHandle};
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct HackedRaylibHandle(RaylibHandle);
|
pub struct HackedRaylibHandle(RaylibHandle);
|
||||||
|
|
||||||
impl HackedRaylibHandle {
|
impl HackedRaylibHandle {
|
||||||
|
|
||||||
/// Get the screen size as a vector
|
/// Get the screen size as a vector
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn get_screen_size(&self) -> Vector2 {
|
pub fn get_screen_size(&self) -> Vector2 {
|
||||||
@ -15,6 +15,33 @@ impl HackedRaylibHandle {
|
|||||||
self.get_screen_height() as f32,
|
self.get_screen_height() as f32,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn draw_rgb_split_text(
|
||||||
|
&mut self,
|
||||||
|
position: Vector2,
|
||||||
|
text: &str,
|
||||||
|
font_size: i32,
|
||||||
|
hovering: bool,
|
||||||
|
color: Color,
|
||||||
|
) {
|
||||||
|
let extra_smudge = if hovering { 2 } else { 0 };
|
||||||
|
self.draw_text(
|
||||||
|
text,
|
||||||
|
position.x as i32 - 1 - extra_smudge,
|
||||||
|
position.y as i32,
|
||||||
|
font_size,
|
||||||
|
Color::BLUE,
|
||||||
|
);
|
||||||
|
self.draw_text(
|
||||||
|
text,
|
||||||
|
position.x as i32 + 1 + extra_smudge,
|
||||||
|
position.y as i32,
|
||||||
|
font_size,
|
||||||
|
Color::RED,
|
||||||
|
);
|
||||||
|
self.draw_text(text, position.x as i32, position.y as i32, font_size, color);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RaylibDraw for HackedRaylibHandle {}
|
impl RaylibDraw for HackedRaylibHandle {}
|
||||||
|
Reference in New Issue
Block a user