From 348c9288596dd3114056e8f06c764624ff64d314 Mon Sep 17 00:00:00 2001 From: Luna Date: Mon, 4 Oct 2021 01:07:02 -0400 Subject: [PATCH] no cheating, get good --- game/src/scenes/cheater_screen.rs | 162 ++++++++++++++++++++++++++++ game/src/scenes/ingame_scene/mod.rs | 4 + game/src/scenes/mod.rs | 5 +- 3 files changed, 170 insertions(+), 1 deletion(-) create mode 100644 game/src/scenes/cheater_screen.rs diff --git a/game/src/scenes/cheater_screen.rs b/game/src/scenes/cheater_screen.rs new file mode 100644 index 0000000..001672e --- /dev/null +++ b/game/src/scenes/cheater_screen.rs @@ -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 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, 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, + ); + } + } + } +} diff --git a/game/src/scenes/ingame_scene/mod.rs b/game/src/scenes/ingame_scene/mod.rs index 722e9c3..fa7c3db 100644 --- a/game/src/scenes/ingame_scene/mod.rs +++ b/game/src/scenes/ingame_scene/mod.rs @@ -102,6 +102,10 @@ impl Action 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(); diff --git a/game/src/scenes/mod.rs b/game/src/scenes/mod.rs index 442fd2d..d8ce114 100644 --- a/game/src/scenes/mod.rs +++ b/game/src/scenes/mod.rs @@ -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) }