blank weapon fire system
This commit is contained in:
parent
8aa37bd929
commit
16b1d0f701
11 changed files with 92 additions and 51 deletions
|
@ -7,7 +7,7 @@ class_name CommandQueue
|
|||
enum Command {
|
||||
NONE,
|
||||
TAKE_WEAPON,
|
||||
SHOOT,
|
||||
FIRE,
|
||||
RELOAD,
|
||||
HOLSTER_WEAPON,
|
||||
TAKE_ZAZA,
|
||||
|
|
|
@ -11,6 +11,9 @@ var queue: CommandQueue = CommandQueue.new()
|
|||
@onready var weapon_player: AnimationPlayer = $"HUD/Weapon/AnimationPlayer"
|
||||
@onready var weapons: Node3D = $"WeaponContainer"
|
||||
|
||||
const DEFAULT_SIDES: Array[CommandQueue.Side] = [CommandQueue.Side.LEFT, CommandQueue.Side.RIGHT]
|
||||
const ONEHANDED_FIRE_COMMAND: Array[CommandQueue.Command] = [CommandQueue.Command.NONE, CommandQueue.Command.FIRE]
|
||||
|
||||
var current_weapon: Weapon
|
||||
|
||||
func _ready() -> void:
|
||||
|
@ -18,6 +21,7 @@ func _ready() -> void:
|
|||
queue.command_popped.connect(on_queue_command_popped)
|
||||
|
||||
current_weapon = weapons.get_child(0) as Weapon
|
||||
current_weapon.fired.connect(on_weapon_fired)
|
||||
|
||||
weapon_player.add_animation_library("current", current_weapon.animation_library)
|
||||
weapon_player.play("current/static")
|
||||
|
@ -25,16 +29,13 @@ func _ready() -> void:
|
|||
Input.mouse_mode = Input.MOUSE_MODE_CAPTURED
|
||||
|
||||
func _process(_delta: float) -> void:
|
||||
if Input.is_action_pressed("shoot") \
|
||||
and queue.current_command(CommandQueue.Side.RIGHT) \
|
||||
if queue.current_command(CommandQueue.Side.RIGHT) \
|
||||
== CommandQueue.DEFAULT_COMMAND:
|
||||
queue.push([
|
||||
CommandQueue.Command.NONE,
|
||||
CommandQueue.Command.SHOOT
|
||||
], [
|
||||
CommandQueue.Side.LEFT,
|
||||
CommandQueue.Side.RIGHT
|
||||
])
|
||||
var fire_action = Input.is_action_just_pressed('shoot') if \
|
||||
current_weapon.fire_mode is SingleFireMode else \
|
||||
Input.is_action_pressed('shoot')
|
||||
if fire_action:
|
||||
queue.push(ONEHANDED_FIRE_COMMAND, DEFAULT_SIDES)
|
||||
|
||||
for side in CommandQueue.Side.values():
|
||||
var command = queue.current_command(side)
|
||||
|
@ -74,7 +75,7 @@ func on_queue_command_pushed(sides, commands):
|
|||
CommandQueue.Side.RIGHT:
|
||||
handle_new_right_command(commands[i])
|
||||
|
||||
func shoot_animation_ended():
|
||||
func fire_task_finish():
|
||||
queue.pop()
|
||||
|
||||
func on_queue_command_popped(commands):
|
||||
|
@ -85,6 +86,12 @@ func on_queue_command_popped(commands):
|
|||
CommandQueue.Side.RIGHT:
|
||||
handle_ended_right_command(commands[i])
|
||||
|
||||
func on_weapon_fired():
|
||||
weapon_player.play("current/fire")
|
||||
|
||||
func on_fire_animation_end():
|
||||
weapon_player.play("current/static")
|
||||
|
||||
func handle_new_left_command(command: CommandQueue.Command):
|
||||
match command:
|
||||
CommandQueue.Command.NONE:
|
||||
|
@ -94,7 +101,7 @@ func handle_new_left_command(command: CommandQueue.Command):
|
|||
|
||||
func handle_new_right_command(command: CommandQueue.Command):
|
||||
match command:
|
||||
CommandQueue.Command.NONE | CommandQueue.Command.SHOOT:
|
||||
CommandQueue.Command.NONE | CommandQueue.Command.FIRE:
|
||||
pass
|
||||
_:
|
||||
print('New command %s is not implemented for right hand.' % command)
|
||||
|
@ -108,10 +115,8 @@ func handle_ended_left_command(command: CommandQueue.Command):
|
|||
|
||||
func handle_ended_right_command(command: CommandQueue.Command):
|
||||
match command:
|
||||
CommandQueue.Command.NONE:
|
||||
CommandQueue.Command.NONE | CommandQueue.Command.FIRE:
|
||||
pass
|
||||
CommandQueue.Command.SHOOT:
|
||||
weapon_player.play('current/static')
|
||||
_:
|
||||
print('Ended command %s is not implemented for right hand.' % command)
|
||||
|
||||
|
@ -126,5 +131,7 @@ func handle_current_right_command(command: CommandQueue.Command):
|
|||
match command:
|
||||
CommandQueue.Command.NONE:
|
||||
pass
|
||||
CommandQueue.Command.FIRE:
|
||||
current_weapon.request_fire()
|
||||
_:
|
||||
print('Current command %s is not implemented for right hand.' % command)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue