air bag impl

This commit is contained in:
Evan Pratten 2021-04-25 13:28:34 -04:00
parent da3b52e395
commit 2d6d1f3629
3 changed files with 10 additions and 5 deletions

View File

@ -67,7 +67,7 @@ impl ItemBase for StunGun {
#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)] #[derive(Debug, PartialEq, Clone, Serialize, Deserialize)]
pub struct AirBag { pub struct AirBag {
extra_oxygen: u32, pub extra_oxygen: f32,
pub level: u8, pub level: u8,
cost: u32, cost: u32,
} }
@ -75,21 +75,21 @@ pub struct AirBag {
impl AirBag { impl AirBag {
pub fn lvl1() -> Self { pub fn lvl1() -> Self {
Self { Self {
extra_oxygen: 15, extra_oxygen: 0.15,
level: 1, level: 1,
cost: 30, cost: 30,
} }
} }
pub fn lvl2() -> Self { pub fn lvl2() -> Self {
Self { Self {
extra_oxygen: 30, extra_oxygen: 0.30,
level: 2, level: 2,
cost: 40, cost: 40,
} }
} }
pub fn lvl3() -> Self { pub fn lvl3() -> Self {
Self { Self {
extra_oxygen: 45, extra_oxygen: 0.45,
level: 3, level: 3,
cost: 50, cost: 50,
} }

View File

@ -142,7 +142,7 @@ pub fn update_player_movement(
// Update the player's breath // Update the player's breath
game_core.player.breath_percent = 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 // Only do this if the mouse is far enough away
let player_stunned = game_core.player.stun_timer > 0.0; let player_stunned = game_core.player.stun_timer > 0.0;

View File

@ -66,6 +66,11 @@ impl Player {
self.position = position; self.position = position;
self.breath_percent = 1.0; self.breath_percent = 1.0;
self.boost_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 { pub fn collides_with_rec(&self, rectangle: &Rectangle) -> bool {