From f70c12a3c67c172419b91340758f9c41c66c569b Mon Sep 17 00:00:00 2001 From: hut Date: Mon, 1 Apr 2024 05:25:35 +0200 Subject: [PATCH] add cheat codes in dev mode --- src/settings.rs | 16 ++++++++++++++++ src/world.rs | 40 +++++++++++++++++++++++++++++++++++++++- 2 files changed, 55 insertions(+), 1 deletion(-) diff --git a/src/settings.rs b/src/settings.rs index 6fc098c..ba4c077 100644 --- a/src/settings.rs +++ b/src/settings.rs @@ -45,6 +45,14 @@ pub struct Settings { pub key_reply8: KeyCode, pub key_reply9: KeyCode, pub key_reply10: KeyCode, + pub key_cheat_stop: KeyCode, + pub key_cheat_speed: KeyCode, + pub key_cheat_pizza: KeyCode, + pub key_cheat_farview1: KeyCode, + pub key_cheat_farview2: KeyCode, + pub key_cheat_adrenaline_zero: KeyCode, + pub key_cheat_adrenaline_mid: KeyCode, + pub key_cheat_adrenaline_max: KeyCode, } impl Default for Settings { @@ -108,6 +116,14 @@ impl Default for Settings { key_reply8: KeyCode::Digit8, key_reply9: KeyCode::Digit9, key_reply10: KeyCode::Digit0, + key_cheat_stop: KeyCode::KeyC, + key_cheat_speed: KeyCode::KeyV, + key_cheat_pizza: KeyCode::F1, + key_cheat_farview1: KeyCode::F2, + key_cheat_farview2: KeyCode::F3, + key_cheat_adrenaline_zero: KeyCode::F5, + key_cheat_adrenaline_mid: KeyCode::F6, + key_cheat_adrenaline_max: KeyCode::F7, } } } diff --git a/src/world.rs b/src/world.rs index 97a0869..d981f60 100644 --- a/src/world.rs +++ b/src/world.rs @@ -1,4 +1,4 @@ -use crate::{actor, nature}; +use crate::{actor, nature, settings}; use bevy::prelude::*; use bevy::pbr::CascadeShadowConfigBuilder; use bevy::render::render_resource::{AsBindGroup, ShaderRef}; @@ -29,6 +29,7 @@ pub struct WorldPlugin; impl Plugin for WorldPlugin { fn build(&self, app: &mut App) { app.add_systems(Startup, setup); + app.add_systems(Update, handle_cheats); app.add_plugins(PhysicsPlugins::default()); app.add_plugins(MaterialPlugin::::default()); //app.add_plugins(PhysicsDebugPlugin::default()); @@ -180,3 +181,40 @@ pub fn setup( ..default() }); } + +fn handle_cheats( + key_input: Res>, + mut q_player: Query<(&mut Transform, &mut LinearVelocity), With>, + mut q_life: Query<(&mut actor::LifeForm, ), With>, + settings: ResMut, +) { + if !settings.dev_mode || q_player.is_empty() || q_life.is_empty() { + return; + } + let (mut trans, mut v) = q_player.get_single_mut().unwrap(); + let (mut lifeform, ) = q_life.get_single_mut().unwrap(); + if key_input.just_pressed(settings.key_cheat_pizza) { + trans.translation = Vec3::new(-3370.0, 0.0, 0.0); + } + if key_input.just_pressed(settings.key_cheat_farview1) { + trans.translation = Vec3::new(-800000.0, 800000.0, 0.0); + } + if key_input.just_pressed(settings.key_cheat_farview2) { + trans.translation = Vec3::new(800000.0, 400000.0, 0.0); + } + if key_input.just_pressed(settings.key_cheat_stop) { + v.0 = Vec3::ZERO; + } + if key_input.pressed(settings.key_cheat_speed) { + v.0 += trans.rotation * Vec3::new(0.0, 0.0, 1000.0); + } + if key_input.pressed(settings.key_cheat_adrenaline_zero) { + lifeform.adrenaline = 0.0; + } + if key_input.pressed(settings.key_cheat_adrenaline_mid) { + lifeform.adrenaline = 0.5; + } + if key_input.pressed(settings.key_cheat_adrenaline_max) { + lifeform.adrenaline = 1.0; + } +}