From da3b52e39516060b6be576d9f4f1574c5eaa012f Mon Sep 17 00:00:00 2001 From: Evan Pratten Date: Sun, 25 Apr 2021 13:25:05 -0400 Subject: [PATCH 1/2] Add flipper logic --- src/logic/ingame/playerlogic.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/logic/ingame/playerlogic.rs b/src/logic/ingame/playerlogic.rs index a506daa..9ff92ed 100644 --- a/src/logic/ingame/playerlogic.rs +++ b/src/logic/ingame/playerlogic.rs @@ -147,6 +147,13 @@ pub fn update_player_movement( // Only do this if the mouse is far enough away let player_stunned = game_core.player.stun_timer > 0.0; let mut player_real_movement = game_core.player.direction * speed_multiplier; + + // Handle the player wearing flippers + if game_core.player.inventory.flippers.is_some() { + player_real_movement *= game_core.player.inventory.flippers.as_ref().unwrap().speed_increase; + } + + // Handle movement and collisions if raw_movement_direction.distance_to(Vector2::zero()) > game_core.player.size.y / 2.0 && !game_core.player.is_stunned() { From 2d6d1f3629fcf498d1d147fb001ce6f01b528029 Mon Sep 17 00:00:00 2001 From: Evan Pratten Date: Sun, 25 Apr 2021 13:28:34 -0400 Subject: [PATCH 2/2] air bag impl --- src/items.rs | 8 ++++---- src/logic/ingame/playerlogic.rs | 2 +- src/player.rs | 5 +++++ 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/items.rs b/src/items.rs index d30dabc..f83afd1 100644 --- a/src/items.rs +++ b/src/items.rs @@ -67,7 +67,7 @@ impl ItemBase for StunGun { #[derive(Debug, PartialEq, Clone, Serialize, Deserialize)] pub struct AirBag { - extra_oxygen: u32, + pub extra_oxygen: f32, pub level: u8, cost: u32, } @@ -75,21 +75,21 @@ pub struct AirBag { impl AirBag { pub fn lvl1() -> Self { Self { - extra_oxygen: 15, + extra_oxygen: 0.15, level: 1, cost: 30, } } pub fn lvl2() -> Self { Self { - extra_oxygen: 30, + extra_oxygen: 0.30, level: 2, cost: 40, } } pub fn lvl3() -> Self { Self { - extra_oxygen: 45, + extra_oxygen: 0.45, level: 3, cost: 50, } diff --git a/src/logic/ingame/playerlogic.rs b/src/logic/ingame/playerlogic.rs index 9ff92ed..91e2cef 100644 --- a/src/logic/ingame/playerlogic.rs +++ b/src/logic/ingame/playerlogic.rs @@ -142,7 +142,7 @@ pub fn update_player_movement( // Update the player's breath game_core.player.breath_percent = - (game_core.player.breath_percent - BREATH_DECREASE_PER_SECOND * dt as f32).clamp(0.0, 1.0); + (game_core.player.breath_percent - BREATH_DECREASE_PER_SECOND * dt as f32).max(0.0); // Only do this if the mouse is far enough away let player_stunned = game_core.player.stun_timer > 0.0; diff --git a/src/player.rs b/src/player.rs index 48fcdbe..0a78a20 100644 --- a/src/player.rs +++ b/src/player.rs @@ -66,6 +66,11 @@ impl Player { self.position = position; self.breath_percent = 1.0; self.boost_percent = 1.0; + + // Handle an air bag being used + if self.inventory.air_bag.is_some() { + self.breath_percent += self.inventory.air_bag.as_ref().unwrap().extra_oxygen; + } } pub fn collides_with_rec(&self, rectangle: &Rectangle) -> bool {