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 a506daa..91e2cef 100644 --- a/src/logic/ingame/playerlogic.rs +++ b/src/logic/ingame/playerlogic.rs @@ -142,11 +142,18 @@ 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; 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() { 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 {