mirror of
https://github.com/doukutsu-rs/doukutsu-rs
synced 2024-11-16 10:52:44 +00:00
weapon switching
This commit is contained in:
parent
b83f3e0288
commit
f87ccaf694
|
@ -73,6 +73,22 @@ impl Inventory {
|
||||||
self.weapons.get_mut(self.current_weapon as usize)
|
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) {
|
pub fn refill_all_ammo(&mut self) {
|
||||||
for weapon in self.weapons.iter_mut() {
|
for weapon in self.weapons.iter_mut() {
|
||||||
weapon.ammo = weapon.max_ammo;
|
weapon.ammo = weapon.max_ammo;
|
||||||
|
|
|
@ -151,11 +151,11 @@ impl GameScene {
|
||||||
|
|
||||||
let weapon_count = self.inventory.get_weapon_count();
|
let weapon_count = self.inventory.get_weapon_count();
|
||||||
if weapon_count != 0 {
|
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);
|
let mut rect = Rect::new(0, 0, 0, 16);
|
||||||
|
|
||||||
for a in 0..weapon_count {
|
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 {
|
if pos_x < 8.0 {
|
||||||
pos_x += 48.0 + weapon_count as f32 * 16.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);
|
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
|
// update health bar
|
||||||
if self.life_bar < self.player.life as u16 {
|
if self.life_bar < self.player.life as u16 {
|
||||||
self.life_bar = self.player.life as u16;
|
self.life_bar = self.player.life as u16;
|
||||||
|
|
Loading…
Reference in a new issue