some glue code between player and weapon
This commit is contained in:
parent
39fb87f62d
commit
ec7b08812d
6 changed files with 100 additions and 124 deletions
|
@ -9,17 +9,22 @@ var queue: CommandQueue = CommandQueue.new()
|
|||
|
||||
@onready var camera: Camera3D = $"Camera"
|
||||
@onready var weapon_player: AnimationPlayer = $"HUD/Weapon/AnimationPlayer"
|
||||
@onready var weapons: Node3D = $"WeaponContainer"
|
||||
|
||||
var current_weapon: Weapon
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void:
|
||||
queue.command_pushed.connect(on_queue_command_pushed)
|
||||
queue.command_popped.connect(on_queue_command_popped)
|
||||
weapon_player.play("static")
|
||||
|
||||
current_weapon = weapons.get_child(0) as Weapon
|
||||
|
||||
weapon_player.add_animation_library("current", current_weapon.animation_library)
|
||||
weapon_player.play("current/static")
|
||||
|
||||
Input.mouse_mode = Input.MOUSE_MODE_CAPTURED
|
||||
|
||||
|
||||
func _process(_delta: float) -> void:
|
||||
# TODO: use proper weapon system, this is just for testing command queue
|
||||
if Input.is_action_pressed("shoot") \
|
||||
and queue.current_command(CommandQueue.Side.RIGHT) \
|
||||
== CommandQueue.DEFAULT_COMMAND:
|
||||
|
@ -30,8 +35,15 @@ func _process(_delta: float) -> void:
|
|||
CommandQueue.Side.LEFT,
|
||||
CommandQueue.Side.RIGHT
|
||||
])
|
||||
|
||||
for side in CommandQueue.Side.values():
|
||||
var command = queue.current_command(side)
|
||||
match side:
|
||||
CommandQueue.Side.LEFT:
|
||||
handle_current_left_command(command)
|
||||
CommandQueue.Side.RIGHT:
|
||||
handle_current_right_command(command)
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _physics_process(delta: float) -> void:
|
||||
var direction = Vector3.ZERO
|
||||
direction.z = Input.get_axis("move_forward", "move_backward")
|
||||
|
@ -62,22 +74,6 @@ func on_queue_command_pushed(sides, commands):
|
|||
CommandQueue.Side.RIGHT:
|
||||
handle_new_right_command(commands[i])
|
||||
|
||||
func handle_new_left_command(command: CommandQueue.Command):
|
||||
match command:
|
||||
CommandQueue.Command.NONE:
|
||||
pass
|
||||
_:
|
||||
print('New command %s is not implemented for left hand.' % str(command))
|
||||
|
||||
func handle_new_right_command(command: CommandQueue.Command):
|
||||
match command:
|
||||
CommandQueue.Command.NONE:
|
||||
pass
|
||||
CommandQueue.Command.SHOOT:
|
||||
weapon_player.play('shoot')
|
||||
_:
|
||||
print('New command %s is not implemented for right hand.' % str(command))
|
||||
|
||||
func shoot_animation_ended():
|
||||
queue.pop()
|
||||
|
||||
|
@ -89,18 +85,46 @@ func on_queue_command_popped(commands):
|
|||
CommandQueue.Side.RIGHT:
|
||||
handle_ended_right_command(commands[i])
|
||||
|
||||
func handle_new_left_command(command: CommandQueue.Command):
|
||||
match command:
|
||||
CommandQueue.Command.NONE:
|
||||
pass
|
||||
_:
|
||||
print('New command %s is not implemented for left hand.' % command)
|
||||
|
||||
func handle_new_right_command(command: CommandQueue.Command):
|
||||
match command:
|
||||
CommandQueue.Command.NONE | CommandQueue.Command.SHOOT:
|
||||
pass
|
||||
_:
|
||||
print('New command %s is not implemented for right hand.' % command)
|
||||
|
||||
func handle_ended_left_command(command: CommandQueue.Command):
|
||||
match command:
|
||||
CommandQueue.Command.NONE:
|
||||
pass
|
||||
_:
|
||||
print('Ended command %s is not implemented for left hand.' % str(command))
|
||||
print('Ended command %s is not implemented for left hand.' % command)
|
||||
|
||||
func handle_ended_right_command(command: CommandQueue.Command):
|
||||
match command:
|
||||
CommandQueue.Command.NONE:
|
||||
pass
|
||||
CommandQueue.Command.SHOOT:
|
||||
weapon_player.play('static')
|
||||
weapon_player.play('current/static')
|
||||
_:
|
||||
print('Ended command %s is not implemented for right hand.' % str(command))
|
||||
print('Ended command %s is not implemented for right hand.' % command)
|
||||
|
||||
func handle_current_left_command(command: CommandQueue.Command):
|
||||
match command:
|
||||
CommandQueue.Command.NONE:
|
||||
pass
|
||||
_:
|
||||
print('Current command %s is not implemented for left hand.' % command)
|
||||
|
||||
func handle_current_right_command(command: CommandQueue.Command):
|
||||
match command:
|
||||
CommandQueue.Command.NONE:
|
||||
pass
|
||||
_:
|
||||
print('Current command %s is not implemented for right hand.' % command)
|
||||
|
|
|
@ -18,7 +18,6 @@ func _on_fire_begin(_tree : SceneTree) -> void:
|
|||
cooldown = false
|
||||
check_unfinished_timer(cooldown_timer,on_cooldown_timeout)
|
||||
|
||||
|
||||
func _process(tree : SceneTree) -> void:
|
||||
if can_fire() :
|
||||
return
|
||||
|
|
|
@ -2,7 +2,7 @@ extends Node3D
|
|||
|
||||
class_name Weapon
|
||||
|
||||
@export var barrel: Barrel
|
||||
@onready var barrel = $"Barrel"
|
||||
@export var uses_hands: Array[CommandQueue.Side]
|
||||
|
||||
@export var max_ammo: int = 7
|
||||
|
@ -12,3 +12,22 @@ var ammo: int = max_ammo
|
|||
@export var fire_mode: BaseFireMode
|
||||
## Weapon animation library. Should contain "static", "fire", "reload" animations
|
||||
@export var animation_library: AnimationLibrary
|
||||
|
||||
var is_firing: bool = false
|
||||
|
||||
func _ready() -> void:
|
||||
fire_mode.barrel = barrel
|
||||
|
||||
## Begin to fire
|
||||
func request_fire() -> void:
|
||||
fire_mode.on_fire_begin(get_tree())
|
||||
is_firing = true
|
||||
|
||||
func _process(_dt) -> void:
|
||||
if is_firing:
|
||||
fire_mode._process(get_tree())
|
||||
|
||||
## End fire
|
||||
func end_fire() -> void:
|
||||
fire_mode.on_fire_end(get_tree())
|
||||
is_firing = false
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue