add cheat codes in dev mode

This commit is contained in:
yuni 2024-04-01 05:25:35 +02:00
parent efc840b031
commit f70c12a3c6
2 changed files with 55 additions and 1 deletions

View file

@ -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,
}
}
}

View file

@ -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::<RingMaterial>::default());
//app.add_plugins(PhysicsDebugPlugin::default());
@ -180,3 +181,40 @@ pub fn setup(
..default()
});
}
fn handle_cheats(
key_input: Res<ButtonInput<KeyCode>>,
mut q_player: Query<(&mut Transform, &mut LinearVelocity), With<actor::PlayerCamera>>,
mut q_life: Query<(&mut actor::LifeForm, ), With<actor::Player>>,
settings: ResMut<settings::Settings>,
) {
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;
}
}