2021-03-09 14:05:38 +00:00
|
|
|
use crate::caret::CaretType;
|
|
|
|
use crate::common::Direction;
|
|
|
|
use crate::player::{Player, TargetPlayer};
|
|
|
|
use crate::shared_game_state::SharedGameState;
|
|
|
|
use crate::weapon::bullet::BulletManager;
|
|
|
|
use crate::weapon::{Weapon, WeaponLevel};
|
|
|
|
|
|
|
|
impl Weapon {
|
|
|
|
pub(in crate::weapon) fn tick_spur(
|
|
|
|
&mut self,
|
|
|
|
player: &mut Player,
|
|
|
|
player_id: TargetPlayer,
|
|
|
|
bullet_manager: &mut BulletManager,
|
|
|
|
state: &mut SharedGameState,
|
|
|
|
) {
|
2021-12-02 05:57:44 +00:00
|
|
|
const BULLETS: [u16; 6] = [37, 38, 39, 40, 41, 42];
|
2021-03-09 14:05:38 +00:00
|
|
|
|
|
|
|
let mut shoot = false;
|
|
|
|
let btype;
|
|
|
|
|
|
|
|
if player.controller.shoot() {
|
2021-03-23 12:51:55 +00:00
|
|
|
self.add_xp(if player.equip.has_turbocharge() { 3 } else { 2 }, player, state);
|
2021-03-09 14:05:38 +00:00
|
|
|
self.counter1 += 1;
|
|
|
|
|
2021-12-02 05:57:44 +00:00
|
|
|
if self.counter1 & 2 != 0 {
|
2021-03-09 14:05:38 +00:00
|
|
|
match self.level {
|
|
|
|
WeaponLevel::Level1 => {
|
|
|
|
state.sound_manager.play_sfx(59);
|
|
|
|
}
|
|
|
|
WeaponLevel::Level2 => {
|
|
|
|
state.sound_manager.play_sfx(60);
|
|
|
|
}
|
|
|
|
WeaponLevel::Level3 => {
|
2021-03-23 12:51:55 +00:00
|
|
|
if let (_, _, false) = self.get_max_exp(&state.constants) {
|
2021-03-09 14:05:38 +00:00
|
|
|
state.sound_manager.play_sfx(61);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
WeaponLevel::None => unreachable!(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if self.counter1 > 0 {
|
|
|
|
shoot = true;
|
|
|
|
self.counter1 = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-23 12:51:55 +00:00
|
|
|
if let (_, _, true) = self.get_max_exp(&state.constants) {
|
2021-03-09 14:05:38 +00:00
|
|
|
if self.counter2 == 0 {
|
|
|
|
self.counter2 = 1;
|
|
|
|
state.sound_manager.play_sfx(65);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
self.counter2 = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
let level = self.level;
|
|
|
|
if !player.controller.shoot() {
|
2021-03-23 12:51:55 +00:00
|
|
|
self.reset_xp();
|
2021-03-09 14:05:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
match level {
|
|
|
|
WeaponLevel::Level1 => {
|
|
|
|
btype = 6;
|
|
|
|
shoot = false;
|
|
|
|
}
|
|
|
|
WeaponLevel::Level2 => btype = 37,
|
|
|
|
WeaponLevel::Level3 => {
|
|
|
|
if self.counter2 == 1 {
|
|
|
|
btype = 39;
|
|
|
|
} else {
|
|
|
|
btype = 38;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
WeaponLevel::None => unreachable!(),
|
|
|
|
}
|
|
|
|
|
2021-03-23 12:51:55 +00:00
|
|
|
if bullet_manager.count_bullets_multi(&BULLETS, player_id) > 0 || !(player.controller.trigger_shoot() || shoot)
|
|
|
|
{
|
2021-03-09 14:05:38 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if !self.consume_ammo(1) {
|
|
|
|
state.sound_manager.play_sfx(37);
|
|
|
|
} else {
|
|
|
|
match player.direction {
|
|
|
|
Direction::Left if player.up => {
|
2021-03-23 12:51:55 +00:00
|
|
|
bullet_manager.create_bullet(
|
|
|
|
player.x - 0x200,
|
|
|
|
player.y - 0x1000,
|
|
|
|
btype,
|
|
|
|
player_id,
|
|
|
|
Direction::Up,
|
|
|
|
&state.constants,
|
|
|
|
);
|
2021-03-09 14:05:38 +00:00
|
|
|
state.create_caret(player.x - 0x200, player.y - 0x1000, CaretType::Shoot, Direction::Left);
|
|
|
|
}
|
|
|
|
Direction::Right if player.up => {
|
2021-03-23 12:51:55 +00:00
|
|
|
bullet_manager.create_bullet(
|
|
|
|
player.x + 0x200,
|
|
|
|
player.y - 0x1000,
|
|
|
|
btype,
|
|
|
|
player_id,
|
|
|
|
Direction::Up,
|
|
|
|
&state.constants,
|
|
|
|
);
|
2021-03-09 14:05:38 +00:00
|
|
|
state.create_caret(player.x + 0x200, player.y - 0x1000, CaretType::Shoot, Direction::Left);
|
|
|
|
}
|
|
|
|
Direction::Left if player.down => {
|
2021-03-23 12:51:55 +00:00
|
|
|
bullet_manager.create_bullet(
|
|
|
|
player.x - 0x200,
|
|
|
|
player.y + 0x1000,
|
|
|
|
btype,
|
|
|
|
player_id,
|
|
|
|
Direction::Bottom,
|
|
|
|
&state.constants,
|
|
|
|
);
|
2021-03-09 14:05:38 +00:00
|
|
|
state.create_caret(player.x - 0x200, player.y + 0x1000, CaretType::Shoot, Direction::Left);
|
|
|
|
}
|
|
|
|
Direction::Right if player.down => {
|
2021-03-23 12:51:55 +00:00
|
|
|
bullet_manager.create_bullet(
|
|
|
|
player.x + 0x200,
|
|
|
|
player.y + 0x1000,
|
|
|
|
btype,
|
|
|
|
player_id,
|
|
|
|
Direction::Bottom,
|
|
|
|
&state.constants,
|
|
|
|
);
|
2021-03-09 14:05:38 +00:00
|
|
|
state.create_caret(player.x + 0x200, player.y + 0x1000, CaretType::Shoot, Direction::Left);
|
|
|
|
}
|
|
|
|
Direction::Left => {
|
2021-03-23 12:51:55 +00:00
|
|
|
bullet_manager.create_bullet(
|
2022-01-08 04:52:26 +00:00
|
|
|
player.x - 0x1800,
|
2021-03-23 12:51:55 +00:00
|
|
|
player.y + 0x600,
|
|
|
|
btype,
|
|
|
|
player_id,
|
|
|
|
Direction::Left,
|
|
|
|
&state.constants,
|
|
|
|
);
|
2022-01-08 04:52:26 +00:00
|
|
|
state.create_caret(player.x - 0x1800, player.y + 0x600, CaretType::Shoot, Direction::Left);
|
2021-03-09 14:05:38 +00:00
|
|
|
}
|
|
|
|
Direction::Right => {
|
2021-03-23 12:51:55 +00:00
|
|
|
bullet_manager.create_bullet(
|
2022-01-08 04:52:26 +00:00
|
|
|
player.x + 0x1800,
|
2021-03-23 12:51:55 +00:00
|
|
|
player.y + 0x600,
|
|
|
|
btype,
|
|
|
|
player_id,
|
|
|
|
Direction::Right,
|
|
|
|
&state.constants,
|
|
|
|
);
|
2022-01-08 04:52:26 +00:00
|
|
|
state.create_caret(player.x + 0x1800, player.y + 0x600, CaretType::Shoot, Direction::Right);
|
2021-03-09 14:05:38 +00:00
|
|
|
}
|
|
|
|
_ => {}
|
|
|
|
}
|
|
|
|
|
|
|
|
let sound = match btype {
|
|
|
|
6 => 49,
|
|
|
|
37 => 62,
|
|
|
|
38 => 63,
|
|
|
|
39 => 64,
|
|
|
|
_ => 0,
|
|
|
|
};
|
|
|
|
|
|
|
|
state.sound_manager.play_sfx(sound);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|