1
0
Fork 0
mirror of https://github.com/doukutsu-rs/doukutsu-rs synced 2024-11-22 13:42:47 +00:00

weapon switching

This commit is contained in:
Alula 2020-09-21 01:55:52 +02:00
parent b83f3e0288
commit f87ccaf694
No known key found for this signature in database
GPG key ID: 3E00485503A1D8BA
2 changed files with 28 additions and 2 deletions

View file

@ -73,6 +73,22 @@ impl Inventory {
self.weapons.get_mut(self.current_weapon as usize)
}
pub fn next_weapon(&mut self) {
if (1 + self.current_weapon as usize) < self.weapons.len() {
self.current_weapon += 1;
} else {
self.current_weapon = 0;
}
}
pub fn prev_weapon(&mut self) {
if self.current_weapon as usize > 0 {
self.current_weapon -= 1;
} else {
self.current_weapon = self.weapons.len().saturating_sub(1) as u16;
}
}
pub fn refill_all_ammo(&mut self) {
for weapon in self.weapons.iter_mut() {
weapon.ammo = weapon.max_ammo;

View file

@ -151,11 +151,11 @@ impl GameScene {
let weapon_count = self.inventory.get_weapon_count();
if weapon_count != 0 {
let current_weapon = self.inventory.get_current_weapon_idx() as usize;
let current_weapon = self.inventory.get_current_weapon_idx() as isize;
let mut rect = Rect::new(0, 0, 0, 16);
for a in 0..weapon_count {
let mut pos_x = ((a - current_weapon) as f32 * 16.0) + weap_x;
let mut pos_x = ((a as isize - current_weapon) as f32 * 16.0) + weap_x;
if pos_x < 8.0 {
pos_x += 48.0 + weapon_count as f32 * 16.0;
@ -753,6 +753,16 @@ impl Scene for GameScene {
weapon.shoot_bullet(&self.player, &mut self.bullet_manager, state);
}
if state.key_trigger.weapon_next() {
self.inventory.next_weapon();
self.weapon_x_pos = 32;
}
if state.key_trigger.weapon_prev() {
self.inventory.prev_weapon();
self.weapon_x_pos = 0;
}
// update health bar
if self.life_bar < self.player.life as u16 {
self.life_bar = self.player.life as u16;