From 902f71f57c0732e2ee7c929ca7dded9c12864864 Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Fri, 7 Jan 2022 09:39:47 -0500 Subject: [PATCH] Add cheat mode for development --- src/gui.rs | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++ src/main.rs | 11 +++++++++ src/player.rs | 3 +++ 3 files changed, 81 insertions(+) diff --git a/src/gui.rs b/src/gui.rs index 9347b76..3e44fb7 100644 --- a/src/gui.rs +++ b/src/gui.rs @@ -890,3 +890,70 @@ pub fn game_over(ctx: &mut Rltk) -> GameOverResult { Some(_) => GameOverResult::QuitToMenu, } } + +#[derive(PartialEq, Copy, Clone)] +pub enum CheatMenuResult { + NoResponse, + Cancel, + TeleportToExit, +} + +pub fn show_cheat_mode(_gs: &mut State, ctx: &mut Rltk) -> CheatMenuResult { + let count = 2; + let y = (25 - (count / 2)) as i32; + ctx.draw_box( + 15, + y - 2, + 31, + (count + 3) as i32, + RGB::named(rltk::WHITE), + RGB::named(rltk::BLACK), + ); + ctx.print_color( + 18, + y - 2, + RGB::named(rltk::YELLOW), + RGB::named(rltk::BLACK), + "Cheating!", + ); + ctx.print_color( + 18, + y + count as i32 + 1, + RGB::named(rltk::YELLOW), + RGB::named(rltk::BLACK), + "ESCAPE to cancel", + ); + + ctx.set( + 17, + y, + RGB::named(rltk::WHITE), + RGB::named(rltk::BLACK), + rltk::to_cp437('('), + ); + ctx.set( + 18, + y, + RGB::named(rltk::YELLOW), + RGB::named(rltk::BLACK), + rltk::to_cp437('T'), + ); + ctx.set( + 19, + y, + RGB::named(rltk::WHITE), + RGB::named(rltk::BLACK), + rltk::to_cp437(')'), + ); + + ctx.print(21, y, "Teleport to exit"); + + match ctx.key { + None => CheatMenuResult::NoResponse, + Some(key) => match key { + VirtualKeyCode::T => CheatMenuResult::TeleportToExit, + VirtualKeyCode::Escape => CheatMenuResult::Cancel, + _ => CheatMenuResult::NoResponse, + }, + } +} diff --git a/src/main.rs b/src/main.rs index d066272..2454220 100644 --- a/src/main.rs +++ b/src/main.rs @@ -35,6 +35,7 @@ use bystander_ai_system::BystanderAI; use components::*; use damage_system::DamageSystem; pub use game_log::GameLog; +use gui::{show_cheat_mode, CheatMenuResult}; use hunger_system::HungerSystem; use inventory_system::{ItemCollectionSystem, ItemDropSystem, ItemRemoveSystem, ItemUseSystem}; pub use map::*; @@ -84,6 +85,7 @@ pub enum RunState { row: i32, }, MapGeneration, + ShowCheatMenu, } pub struct State { @@ -364,6 +366,15 @@ impl GameState for State { newrunstate = RunState::MagicMapReveal { row: row + 1 }; } } + RunState::ShowCheatMenu => match show_cheat_mode(self, ctx) { + CheatMenuResult::Cancel => newrunstate = RunState::AwaitingInput, + CheatMenuResult::NoResponse => {} + CheatMenuResult::TeleportToExit => { + self.goto_level(1); + self.mapgen_next_state = Some(RunState::PreRun); + newrunstate = RunState::MapGeneration + } + }, } { diff --git a/src/player.rs b/src/player.rs index 5289eb1..6739730 100644 --- a/src/player.rs +++ b/src/player.rs @@ -359,6 +359,9 @@ pub fn player_input(gs: &mut State, ctx: &mut Rltk) -> RunState { // Save and Quit VirtualKeyCode::Escape => return RunState::SaveGame, + // Cheating! + VirtualKeyCode::Backslash => return RunState::ShowCheatMenu, + _ => return RunState::AwaitingInput, }, }