From a44a7faa42e3e50d716f316e2f9a53580f786fd5 Mon Sep 17 00:00:00 2001 From: hut Date: Mon, 8 Apr 2024 01:44:36 +0200 Subject: [PATCH] implement god mode --- README.md | 2 ++ src/actor.rs | 33 +++++++++++++++++++++++---------- src/settings.rs | 4 ++++ src/world.rs | 15 +++++++++++++-- 4 files changed, 42 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 0d3579b..73ddf7b 100644 --- a/README.md +++ b/README.md @@ -43,6 +43,7 @@ Links: - T: Toggle music - M: Toggle sound effects - Cheats + - G: Toggle god mode / cheats - V/B: Impossible acceleration forward/backward - Shift+V/B: Same as V/B, but a thousand times faster - C: Impossibly instant stopping @@ -155,6 +156,7 @@ python -m http.server -d wasm - Implement targeting objects with left click (AR only) - Implement matching velocity to targeted objects with space - Implement damage from g-forces, passing out + - Implement god mode - Fix crash by avoiding legacy fullscreen mode - v0.5.3: - Implement death & respawning diff --git a/src/actor.rs b/src/actor.rs index 64367fd..6545fe6 100644 --- a/src/actor.rs +++ b/src/actor.rs @@ -403,8 +403,12 @@ fn handle_player_death( mut ew_sfx: EventWriter, mut ew_effect: EventWriter, mut log: ResMut, + settings: Res, ) { for _ in er_playerdies.read() { + if settings.god_mode { + return; + } for entity in &q_noscenes { cmd.entity(entity).despawn(); } @@ -427,21 +431,28 @@ fn handle_player_death( fn handle_damage( mut ew_playerdies: EventWriter, mut q_hp: Query<(&mut HitPoints, Option<&Player>), Changed>, + settings: Res, ) { for (mut hp, player_maybe) in &mut q_hp { - hp.current -= hp.damage; - hp.damage = 0.0; if player_maybe.is_some() { + if !settings.god_mode { + hp.current -= hp.damage; + } if hp.current <= 0.0 { ew_playerdies.send(PlayerDiesEvent); } } + else { + hp.current -= hp.damage; + } + hp.damage = 0.0; } } fn handle_gforce( time: Res