Merge pull request #29 from Ewpratten/item_impl

Implement items
This commit is contained in:
Evan Pratten 2021-04-25 13:28:59 -04:00 committed by GitHub
commit 021e597747
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 5 deletions

View File

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

View File

@ -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()
{

View File

@ -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 {