Proper firing logic handling
This commit is contained in:
parent
b58c740e06
commit
6a317d1913
12 changed files with 44 additions and 20 deletions
|
@ -8,6 +8,7 @@ enum Command {
|
|||
NONE,
|
||||
TAKE_WEAPON,
|
||||
FIRE,
|
||||
STOP_FIRING,
|
||||
RELOAD,
|
||||
HOLSTER_WEAPON,
|
||||
TAKE_ZAZA,
|
||||
|
@ -30,7 +31,6 @@ var command_queue: Dictionary = {}
|
|||
|
||||
func _init() -> void:
|
||||
for side in Side.values():
|
||||
print(side)
|
||||
var arr: Array[Command] = []
|
||||
command_queue[side] = arr
|
||||
|
||||
|
|
|
@ -36,12 +36,11 @@ func _process(_delta: float) -> void:
|
|||
var weapon_sides_are_free = not queue.sides_are_busy(weapon_sides)
|
||||
if weapon_sides_are_free:
|
||||
# Fire logic
|
||||
var fire_action = Input.is_action_just_pressed('shoot') if \
|
||||
current_weapon.fire_mode is SingleFireMode else \
|
||||
Input.is_action_pressed('shoot')
|
||||
var fire_action = Input.is_action_just_pressed('shoot')
|
||||
if fire_action:
|
||||
push_copied_command(CommandQueue.Command.FIRE, weapon_sides)
|
||||
|
||||
|
||||
# Reload logic
|
||||
var reload_action = Input.is_action_just_pressed('reload')
|
||||
if reload_action:
|
||||
|
@ -57,6 +56,13 @@ func _process(_delta: float) -> void:
|
|||
slot_id = slot
|
||||
if slot_action:
|
||||
weapons.select_slot(slot_id)
|
||||
|
||||
# Stop firing logic
|
||||
if not current_weapon.fire_mode is SingleFireMode:
|
||||
var stop_firing_action = Input.is_action_just_released('shoot')
|
||||
if stop_firing_action:
|
||||
push_copied_command(CommandQueue.Command.STOP_FIRING, weapon_sides)
|
||||
|
||||
|
||||
for side in CommandQueue.Side.values():
|
||||
var command = queue.current_command(side)
|
||||
|
@ -92,6 +98,7 @@ func on_weapon_slot_selected():
|
|||
if current_weapon != null:
|
||||
current_weapon.fired.disconnect(on_weapon_fired)
|
||||
current_weapon.fire_failed.disconnect(finish_task)
|
||||
current_weapon.fire_allowed.disconnect(finish_task)
|
||||
|
||||
weapon_player.remove_animation_library("current")
|
||||
|
||||
|
@ -99,6 +106,7 @@ func on_weapon_slot_selected():
|
|||
|
||||
current_weapon.fired.connect(on_weapon_fired)
|
||||
current_weapon.fire_failed.connect(finish_task)
|
||||
current_weapon.fire_allowed.connect(finish_task)
|
||||
|
||||
weapon_player.add_animation_library("current", current_weapon.animation_library)
|
||||
weapon_player.play("current/static")
|
||||
|
@ -150,6 +158,7 @@ func update_ammo_label():
|
|||
})
|
||||
|
||||
func on_weapon_fired():
|
||||
weapon_player.stop()
|
||||
weapon_player.play("current/fire")
|
||||
update_ammo_label()
|
||||
|
||||
|
@ -167,6 +176,9 @@ func handle_new_right_command(command: CommandQueue.Command):
|
|||
match command:
|
||||
CommandQueue.Command.RELOAD:
|
||||
weapon_player.play('current/reload')
|
||||
CommandQueue.Command.STOP_FIRING:
|
||||
if queue.current_command(CommandQueue.Side.RIGHT) == CommandQueue.Command.FIRE:
|
||||
current_weapon.end_fire()
|
||||
|
||||
func handle_ended_left_command(command: CommandQueue.Command):
|
||||
match command:
|
||||
|
@ -189,6 +201,8 @@ func handle_started_right_command(command: CommandQueue.Command):
|
|||
match command:
|
||||
CommandQueue.Command.FIRE:
|
||||
current_weapon.request_fire()
|
||||
CommandQueue.Command.STOP_FIRING:
|
||||
queue.pop()
|
||||
|
||||
func handle_current_left_command(command: CommandQueue.Command):
|
||||
match command:
|
||||
|
|
|
@ -26,5 +26,4 @@ func select_slot(index: int):
|
|||
if slots[index].has_weapon:
|
||||
current_slot = slots[index]
|
||||
current_weapon = current_slot.weapon
|
||||
print('here we go')
|
||||
slot_selected.emit()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue