Merge branch 'master' into levels

This commit is contained in:
Evan Pratten 2021-10-03 22:41:21 -07:00 committed by GitHub
commit beedf7d336
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 186 additions and 15 deletions

View File

@ -0,0 +1,162 @@
use std::ops::{Div, Sub};
use chrono::{DateTime, Utc};
use dirty_fsm::{Action, ActionFlag};
use discord_sdk::activity::{ActivityBuilder, Assets};
use pkg_version::pkg_version_major;
use raylib::prelude::*;
use crate::{GameConfig, 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,
}};
use super::{Scenes, ScreenError};
use tracing::{debug, error, info, trace};
#[derive(Debug)]
pub struct CheaterScreen {
is_menu_pressed: bool, //Is menu button pressed
counter: i32,
}
impl CheaterScreen {
/// Construct a new `CheaterScreen`
pub fn new() -> Self {
Self {
is_menu_pressed: false,
counter: 0,
}
}
}
impl Action<Scenes, ScreenError, GameContext> for CheaterScreen {
fn on_register(&mut self) -> Result<(), ScreenError> {
debug!("Registered");
Ok(())
}
fn on_first_run(&mut self, context: &GameContext) -> Result<(), ScreenError> {
debug!("Running CheaterScreen for the first time");
if let Err(e) = context.discord_rpc_send.send(Some(
ActivityBuilder::default()
.details("somehow won the game")
.assets(
Assets::default().large("game-logo-small", Some(context.config.name.clone())),
),
)) {
error!("Failed to update discord: {}", e);
}
Ok(())
}
fn execute(
&mut self,
_delta: &chrono::Duration,
context: &GameContext,
) -> Result<dirty_fsm::ActionFlag<Scenes>, ScreenError> {
trace!("execute() called on CheaterScreen");
self.render_screen_space(&mut context.renderer.borrow_mut(), &context.config);
self.counter += 1;
if self.is_menu_pressed {
context
.flag_send
.send(Some(ControlFlag::SoundTrigger("button-press".to_string())))
.unwrap();
Ok(ActionFlag::SwitchState(Scenes::MainMenuScreen))
} else {
Ok(ActionFlag::Continue)
}
}
fn on_finish(&mut self, _interrupted: bool) -> Result<(), ScreenError> {
debug!("Finished CheaterScreen");
self.is_menu_pressed = false;
self.counter = 0;
Ok(())
}
}
impl ScreenSpaceRender for CheaterScreen {
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,
);
//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_rgb_split_text(
Vector2::new(100.0, screen_size.y as f32 / 2.0 - 120.0),
"what are you doing.",
30,
false,
Color::WHITE,
);
if self.counter > 100 {
raylib.draw_rgb_split_text(
Vector2::new(100.0, screen_size.y as f32 / 2.0 - 60.0),
"don't cheat.",
30,
false,
Color::WHITE,
);
}
if self.counter > 300 {
raylib.draw_rgb_split_text(
Vector2::new(100.0, screen_size.y as f32 / 2.0 + 50.0),
"get good.",
30,
false,
Color::WHITE,
);
};
//Return to Main Menu
if self.counter > 450 {
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,
);
}
}
}
}

View File

@ -102,6 +102,10 @@ impl Action<Scenes, ScreenError, GameContext> for InGameScreen {
puffin::profile_function!();
trace!("execute() called on InGameScreen");
if self.player.position.y < -1200.0{
return Ok(ActionFlag::SwitchState(Scenes::CheaterScreen));
}
if self.current_level_idx != context.current_level {
self.current_level_idx = context.current_level;
// self.level_switch_timestamp = Utc::now();

View File

@ -45,13 +45,14 @@ impl WorldSpaceRender for InGameScreen {
.appear
.iter()
.map(|zone| {
// Vector2::new(
// zone.x + WORLD_LEVEL_X_OFFSET + (zone.width / 2.0),
// zone.y - cur_level.platform_tex.height as f32,
// )
// .distance_to(self.player.position) as i32
((zone.x + WORLD_LEVEL_X_OFFSET + (zone.width / 2.0)) - self.player.position.x)
.abs() as i32
let left_edge_dist = (zone.x + WORLD_LEVEL_X_OFFSET) - self.player.position.x;
let right_edge_dist =
(zone.x + zone.width + WORLD_LEVEL_X_OFFSET) - self.player.position.x;
if left_edge_dist < 0.0 && right_edge_dist > 0.0 {
0
} else {
left_edge_dist.abs().min(right_edge_dist.abs()) as i32
}
})
.min()
.unwrap_or(i32::MAX);
@ -88,13 +89,14 @@ impl WorldSpaceRender for InGameScreen {
.disappear
.iter()
.map(|zone| {
// Vector2::new(
// zone.x + WORLD_LEVEL_X_OFFSET + (zone.width / 2.0),
// zone.y - cur_level.platform_tex.height as f32,
// )
// .distance_to(self.player.position) as i32
((zone.x + WORLD_LEVEL_X_OFFSET + (zone.width / 2.0)) - self.player.position.x)
.abs() as i32
let left_edge_dist = (zone.x + WORLD_LEVEL_X_OFFSET) - self.player.position.x;
let right_edge_dist =
(zone.x + zone.width + WORLD_LEVEL_X_OFFSET) - self.player.position.x;
if left_edge_dist < 0.0 && right_edge_dist > 0.0 {
0
} else {
left_edge_dist.abs().min(right_edge_dist.abs()) as i32
}
})
.min()
.unwrap_or(i32::MAX);

View File

@ -1,4 +1,4 @@
use self::{death_screen::DeathScreen, fsm_error_screen::FsmErrorScreen, how_to_play_screen::HowToPlayScreen, ingame_scene::{InGameScreen, level::{Level, loader::load_all_levels}}, level_select_screen::LevelSelectScreen, main_menu_screen::MainMenuScreen, next_level_screen::NextLevelScreen, options_screen::OptionsScreen, pause_screen::PauseScreen, win_screen::WinScreen};
use self::{death_screen::DeathScreen, fsm_error_screen::FsmErrorScreen, how_to_play_screen::HowToPlayScreen, ingame_scene::{InGameScreen, level::{Level, loader::load_all_levels}}, level_select_screen::LevelSelectScreen, main_menu_screen::MainMenuScreen, next_level_screen::NextLevelScreen, options_screen::OptionsScreen, pause_screen::PauseScreen, win_screen::WinScreen, cheater_screen::CheaterScreen};
use crate::{context::GameContext, utilities::{datastore::{ResourceLoadError, load_music_from_internal_data, load_sound_from_internal_data, load_texture_from_internal_data}, non_ref_raylib::HackedRaylibHandle}};
use dirty_fsm::StateMachine;
use raylib::{texture::Texture2D, RaylibThread};
@ -13,6 +13,7 @@ pub mod death_screen;
pub mod win_screen;
pub mod next_level_screen;
pub mod level_select_screen;
pub mod cheater_screen;
/// Defines all scenes
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, Hash)]
@ -28,6 +29,7 @@ pub enum Scenes {
WinScreen,
NextLevelScreen,
LevelSelectScreen,
CheaterScreen,
}
/// Contains any possible errors thrown while rendering
@ -68,6 +70,7 @@ pub fn build_screen_state_machine(
machine.add_action(Scenes::WinScreen, WinScreen::new())?;
machine.add_action(Scenes::NextLevelScreen, NextLevelScreen::new())?;
machine.add_action(Scenes::LevelSelectScreen, LevelSelectScreen::new())?;
machine.add_action(Scenes::CheaterScreen, CheaterScreen::new())?;
Ok(machine)
}