From 82511ca6b772b111dac622490527ed267840f869 Mon Sep 17 00:00:00 2001 From: Alula Date: Sun, 13 Sep 2020 02:29:11 +0200 Subject: [PATCH] xp bar fixes --- src/inventory.rs | 11 +++++++---- src/scene/game_scene.rs | 24 +++++++++++------------- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/src/inventory.rs b/src/inventory.rs index 9e99653..5e0b52e 100644 --- a/src/inventory.rs +++ b/src/inventory.rs @@ -115,21 +115,24 @@ impl Inventory { result } - pub fn get_current_max_exp(&self, constants: &EngineConstants) -> (u16, u16) { + /// Get current experience state. Returns a (exp, max exp, max level/exp) tuple. + pub fn get_current_max_exp(&self, constants: &EngineConstants) -> (u16, u16, bool) { if let Some(weapon) = self.weapons.get(self.current_weapon as usize) { if weapon.level == WeaponLevel::None { - return (0, 0); + return (0, 0, false); } let level_idx = weapon.level as usize - 1; let max_exp = constants.weapon.level_table[weapon.wtype as usize][level_idx]; + let max = weapon.level == WeaponLevel::Level3 && weapon.experience == max_exp; - (weapon.experience, max_exp) + (weapon.experience, max_exp, max) } else { - (0, 0) + (0, 0, false) } } + /// Get current ammunition state. Returns a (ammo, max ammo) tuple. pub fn get_current_ammo(&self) -> (u16, u16) { if let Some(weapon) = self.weapons.get(self.current_weapon as usize) { (weapon.ammo, weapon.max_ammo) diff --git a/src/scene/game_scene.rs b/src/scene/game_scene.rs index ce2c592..26f3f6a 100644 --- a/src/scene/game_scene.rs +++ b/src/scene/game_scene.rs @@ -103,7 +103,7 @@ impl GameScene { // none let weap_x = self.weapon_x_pos as f32; let (ammo, max_ammo) = self.inventory.get_current_ammo(); - let (xp, max_xp) = self.inventory.get_current_max_exp(&state.constants); + let (xp, max_xp, max_level) = self.inventory.get_current_max_exp(&state.constants); let batch = state.texture_set.get_or_load_batch(ctx, &state.constants, "TextBox")?; if max_ammo == 0 { @@ -122,19 +122,18 @@ impl GameScene { // xp box batch.add_rect(weap_x + 24.0, 32.0, &Rect::::new_size(0, 72, 40, 8)); + + if max_level { + batch.add_rect(weap_x + 24.0, 32.0, + &Rect::::new_size(40, 72, 40, 8)); + } + if max_xp > 0 { - if xp == max_xp { - // max level bar - batch.add_rect(weap_x + 24.0, 32.0, - &Rect::::new_size(40, 72, 40, 8)); + // xp bar + let bar_width = (xp as f32 / max_xp as f32 * 40.0) as usize; - } else { - // xp bar - let bar_width = (xp as f32 / max_xp as f32 * 40.0) as usize; - - batch.add_rect(weap_x + 24.0, 32.0, - &Rect::::new_size(0, 80, bar_width, 8)); - } + batch.add_rect(weap_x + 24.0, 32.0, + &Rect::::new_size(0, 80, bar_width, 8)); } if self.player.max_life != 0 { @@ -613,7 +612,6 @@ impl GameScene { if !hit { continue; } - println!("npc hit: {}", npc.id); if npc.npc_flags.shootable() { log::info!("damage: {} {}", npc.life, -(bullet.damage.min(npc.life) as isize));