1
0
Fork 0
mirror of https://github.com/doukutsu-rs/doukutsu-rs synced 2025-03-22 01:49:33 +00:00

xp bar fixes

This commit is contained in:
Alula 2020-09-13 02:29:11 +02:00
parent 27e4d72f48
commit 82511ca6b7
No known key found for this signature in database
GPG key ID: 3E00485503A1D8BA
2 changed files with 18 additions and 17 deletions

View file

@ -115,21 +115,24 @@ impl Inventory {
result 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 let Some(weapon) = self.weapons.get(self.current_weapon as usize) {
if weapon.level == WeaponLevel::None { if weapon.level == WeaponLevel::None {
return (0, 0); return (0, 0, false);
} }
let level_idx = weapon.level as usize - 1; let level_idx = weapon.level as usize - 1;
let max_exp = constants.weapon.level_table[weapon.wtype as usize][level_idx]; 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 { } else {
(0, 0) (0, 0, false)
} }
} }
/// Get current ammunition state. Returns a (ammo, max ammo) tuple.
pub fn get_current_ammo(&self) -> (u16, u16) { pub fn get_current_ammo(&self) -> (u16, u16) {
if let Some(weapon) = self.weapons.get(self.current_weapon as usize) { if let Some(weapon) = self.weapons.get(self.current_weapon as usize) {
(weapon.ammo, weapon.max_ammo) (weapon.ammo, weapon.max_ammo)

View file

@ -103,7 +103,7 @@ impl GameScene {
// none // none
let weap_x = self.weapon_x_pos as f32; let weap_x = self.weapon_x_pos as f32;
let (ammo, max_ammo) = self.inventory.get_current_ammo(); 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")?; let batch = state.texture_set.get_or_load_batch(ctx, &state.constants, "TextBox")?;
if max_ammo == 0 { if max_ammo == 0 {
@ -122,20 +122,19 @@ impl GameScene {
// xp box // xp box
batch.add_rect(weap_x + 24.0, 32.0, batch.add_rect(weap_x + 24.0, 32.0,
&Rect::<usize>::new_size(0, 72, 40, 8)); &Rect::<usize>::new_size(0, 72, 40, 8));
if max_xp > 0 {
if xp == max_xp { if max_level {
// max level bar
batch.add_rect(weap_x + 24.0, 32.0, batch.add_rect(weap_x + 24.0, 32.0,
&Rect::<usize>::new_size(40, 72, 40, 8)); &Rect::<usize>::new_size(40, 72, 40, 8));
}
} else { if max_xp > 0 {
// xp bar // xp bar
let bar_width = (xp as f32 / max_xp as f32 * 40.0) as usize; let bar_width = (xp as f32 / max_xp as f32 * 40.0) as usize;
batch.add_rect(weap_x + 24.0, 32.0, batch.add_rect(weap_x + 24.0, 32.0,
&Rect::<usize>::new_size(0, 80, bar_width, 8)); &Rect::<usize>::new_size(0, 80, bar_width, 8));
} }
}
if self.player.max_life != 0 { if self.player.max_life != 0 {
// life box // life box
@ -613,7 +612,6 @@ impl GameScene {
if !hit { if !hit {
continue; continue;
} }
println!("npc hit: {}", npc.id);
if npc.npc_flags.shootable() { if npc.npc_flags.shootable() {
log::info!("damage: {} {}", npc.life, -(bullet.damage.min(npc.life) as isize)); log::info!("damage: {} {}", npc.life, -(bullet.damage.min(npc.life) as isize));