Add cheat mode for development
This commit is contained in:
parent
542c05cb6c
commit
902f71f57c
67
src/gui.rs
67
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,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
11
src/main.rs
11
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
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
{
|
||||
|
@ -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,
|
||||
},
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user