menu thingies

This commit is contained in:
Evan Pratten 2021-10-03 11:51:25 -04:00
parent f549cab250
commit fe42b962f0
5 changed files with 70 additions and 32 deletions

View File

@ -1,5 +1,6 @@
use std::{cell::RefCell, sync::mpsc::Sender};
use chrono::{DateTime, Utc};
use discord_sdk::activity::ActivityBuilder;
use crate::{utilities::non_ref_raylib::HackedRaylibHandle, GameConfig};
@ -8,6 +9,7 @@ use crate::{utilities::non_ref_raylib::HackedRaylibHandle, GameConfig};
pub enum ControlFlag {
Quit,
SwitchLevel(usize),
UpdateLevelStart(DateTime<Utc>)
}
#[derive(Debug)]
@ -15,6 +17,7 @@ pub struct GameContext {
pub renderer: RefCell<HackedRaylibHandle>,
pub config: GameConfig,
pub current_level: usize,
pub level_start_time: DateTime<Utc>,
pub discord_rpc_send: Sender<Option<ActivityBuilder>>,
pub flag_send: Sender<Option<ControlFlag>>,
}

View File

@ -72,6 +72,7 @@
use std::{borrow::BorrowMut, cell::RefCell, sync::mpsc::TryRecvError};
use chrono::Utc;
use discord_sdk::activity::ActivityBuilder;
use raylib::prelude::*;
use tracing::{error, info, warn};
@ -171,6 +172,7 @@ pub async fn game_begin(game_config: &mut GameConfig) -> Result<(), Box<dyn std:
renderer: RefCell::new(rl.into()),
config: game_config.clone(),
current_level: 0,
level_start_time: Utc::now(),
discord_rpc_send: send_discord_rpc,
flag_send: send_control_signal,
});
@ -319,6 +321,9 @@ pub async fn game_begin(game_config: &mut GameConfig) -> Result<(), Box<dyn std:
context::ControlFlag::SwitchLevel(level) => {
context.as_mut().current_level = level;
}
context::ControlFlag::UpdateLevelStart(time) => {
context.as_mut().level_start_time = time;
}
}
}
}

View File

@ -6,27 +6,33 @@ use discord_sdk::activity::{ActivityBuilder, Assets};
use pkg_version::pkg_version_major;
use raylib::prelude::*;
use crate::{GameConfig, context::GameContext, utilities::{
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, error, trace};
use tracing::{debug, error, info, trace};
#[derive(Debug)]
pub struct DeathScreen {
is_retry_pressed: bool
is_retry_pressed: bool,
timer_value: String,
}
impl DeathScreen {
/// Construct a new `DeathScreen`
pub fn new() -> Self {
Self {
is_retry_pressed: false
is_retry_pressed: false,
timer_value: "XX:XX".to_string(),
}
}
}
@ -41,11 +47,9 @@ impl Action<Scenes, ScreenError, GameContext> for DeathScreen {
debug!("Running DeathScreen for the first time");
if let Err(e) = context.discord_rpc_send.send(Some(
ActivityBuilder::default()
.details("dead... again")
.assets(
Assets::default().large("game-logo-small", Some(context.config.name.clone())),
)
ActivityBuilder::default().details("dead... again").assets(
Assets::default().large("game-logo-small", Some(context.config.name.clone())),
),
)) {
error!("Failed to update discord: {}", e);
}
@ -61,11 +65,12 @@ impl Action<Scenes, ScreenError, GameContext> for DeathScreen {
trace!("execute() called on DeathScreen");
self.render_screen_space(&mut context.renderer.borrow_mut(), &context.config);
let elapsed = Utc::now() - context.level_start_time;
self.timer_value = format!("{:02}:{:02}", elapsed.num_minutes(), elapsed.num_seconds() % 60);
if self.is_retry_pressed {
Ok(ActionFlag::SwitchState(Scenes::InGameScene))
}
else{
} else {
Ok(ActionFlag::Continue)
}
}
@ -81,9 +86,8 @@ impl ScreenSpaceRender for DeathScreen {
fn render_screen_space(
&mut self,
raylib: &mut crate::utilities::non_ref_raylib::HackedRaylibHandle,
config: &GameConfig
config: &GameConfig,
) {
// Render the background
raylib.clear_background(Color::DARKBLUE);
@ -95,8 +99,8 @@ impl ScreenSpaceRender for DeathScreen {
let mouse_pressed: bool = raylib.is_mouse_button_pressed(MouseButton::MOUSE_LEFT_BUTTON);
raylib.draw_text(
"ERR: Corrupted Player Data Detected
&format!(
"ERR: Corrupted Player Data Detected
The program has detected lowering player integrity,
and has halted as a safety precaution.
@ -104,13 +108,18 @@ and has halted as a safety precaution.
If this is the first time you've seen this error screen,
restart the level. If problems continue, simply get good.
The timer has not been reset. You are wasting time
reading this message. GLHF ;)
-------- Technical information --------
*** CALL STACK:
*** C [libraylib.so+0x75c] END_DRAWING()
*** RS [data_loss.so+0x48f] validate_player()
*** ---------------------------------------
*** PROGRAM_HALT (TIMER: {}:{})
*** PROGRAM_HALT (TIMER: {})
*** ---------------------------------------",
self.timer_value
),
25,
20,
20,
@ -118,9 +127,10 @@ restart the level. If problems continue, simply get good.
);
//Retry
if Rectangle::new(35.0, screen_size.y as f32 - 80.0, 200.0, 40.0).check_collision_point_rec(mouse_position){
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,
@ -129,10 +139,8 @@ restart the level. If problems continue, simply get good.
);
self.is_retry_pressed = mouse_pressed
}
else {
} else {
raylib.draw_text(
">>CLICK HERE TO RETRY",
25,
screen_size.y as i32 - 40,

View File

@ -104,6 +104,7 @@ impl Action<Scenes, ScreenError, GameContext> for InGameScreen {
if self.current_level_idx != context.current_level {
self.current_level_idx = context.current_level;
self.level_switch_timestamp = Utc::now();
context.flag_send.send(Some(ControlFlag::UpdateLevelStart(self.level_switch_timestamp))).unwrap();
}
// Grab exclusive access to the renderer

View File

@ -6,13 +6,17 @@ use discord_sdk::activity::{ActivityBuilder, Assets};
use pkg_version::pkg_version_major;
use raylib::prelude::*;
use crate::{GameConfig, context::{ControlFlag, GameContext}, utilities::{
use crate::{
context::{ControlFlag, 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, error, info, trace};
@ -170,7 +174,7 @@ impl ScreenSpaceRender for MainMenuScreen {
Color::WHITE,
);
if hovering_start_game{
if hovering_start_game {
raylib.draw_rgb_split_text(
Vector2::new(50.0, 300.0),
">>",
@ -192,7 +196,7 @@ impl ScreenSpaceRender for MainMenuScreen {
hovering_htp,
Color::WHITE,
);
if hovering_htp{
if hovering_htp {
raylib.draw_rgb_split_text(
Vector2::new(50.0, 350.0),
">>",
@ -213,7 +217,7 @@ impl ScreenSpaceRender for MainMenuScreen {
hovering_options,
Color::WHITE,
);
if hovering_options{
if hovering_options {
raylib.draw_rgb_split_text(
Vector2::new(50.0, 400.0),
">>",
@ -224,19 +228,36 @@ impl ScreenSpaceRender for MainMenuScreen {
};
self.is_options_pressed = mouse_pressed && hovering_options;
// QUIT
let hovering_quit =
Rectangle::new(80.0, 445.0, 65.0, 20.0).check_collision_point_rec(mouse_position);
// CREDITS
let hovering_credits =
Rectangle::new(80.0, 445.0, 135.0, 20.0).check_collision_point_rec(mouse_position);
raylib.draw_rgb_split_text(
Vector2::new(80.0, 450.0),
"CREDITS",
25,
hovering_credits,
Color::WHITE,
);
if hovering_credits {
raylib.draw_rgb_split_text(Vector2::new(50.0, 450.0), ">>", 25, true, Color::WHITE);
};
if hovering_credits && mouse_pressed {
let _ = webbrowser::open("https://github.com/Ewpratten/ludum-dare-49#the-team");
}
// QUIT
let hovering_quit =
Rectangle::new(80.0, 495.0, 65.0, 20.0).check_collision_point_rec(mouse_position);
raylib.draw_rgb_split_text(
Vector2::new(80.0, 500.0),
"QUIT",
25,
hovering_quit,
Color::WHITE,
);
if hovering_quit{
if hovering_quit {
raylib.draw_rgb_split_text(
Vector2::new(50.0, 450.0),
Vector2::new(50.0, 500.0),
">>",
25,
hovering_quit,