Proper firing logic handling
This commit is contained in:
parent
b58c740e06
commit
6a317d1913
12 changed files with 44 additions and 20 deletions
|
@ -50,13 +50,10 @@ tracks/1/path = NodePath("../..")
|
||||||
tracks/1/interp = 1
|
tracks/1/interp = 1
|
||||||
tracks/1/loop_wrap = true
|
tracks/1/loop_wrap = true
|
||||||
tracks/1/keys = {
|
tracks/1/keys = {
|
||||||
"times": PackedFloat32Array(0.2, 0.3),
|
"times": PackedFloat32Array(0.3),
|
||||||
"transitions": PackedFloat32Array(1, 1),
|
"transitions": PackedFloat32Array(1),
|
||||||
"values": [{
|
"values": [{
|
||||||
"args": [],
|
"args": [],
|
||||||
"method": &"finish_task"
|
|
||||||
}, {
|
|
||||||
"args": [],
|
|
||||||
"method": &"reset_animation"
|
"method": &"reset_animation"
|
||||||
}]
|
}]
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,13 +50,10 @@ tracks/1/path = NodePath("../..")
|
||||||
tracks/1/interp = 1
|
tracks/1/interp = 1
|
||||||
tracks/1/loop_wrap = true
|
tracks/1/loop_wrap = true
|
||||||
tracks/1/keys = {
|
tracks/1/keys = {
|
||||||
"times": PackedFloat32Array(0.2, 0.3),
|
"times": PackedFloat32Array(0.3),
|
||||||
"transitions": PackedFloat32Array(1, 1),
|
"transitions": PackedFloat32Array(1),
|
||||||
"values": [{
|
"values": [{
|
||||||
"args": [],
|
"args": [],
|
||||||
"method": &"finish_task"
|
|
||||||
}, {
|
|
||||||
"args": [],
|
|
||||||
"method": &"reset_animation"
|
"method": &"reset_animation"
|
||||||
}]
|
}]
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
[gd_scene load_steps=8 format=3 uid="uid://dwx5tcatj35gu"]
|
[gd_scene load_steps=8 format=3 uid="uid://dwx5tcatj35gu"]
|
||||||
|
|
||||||
[ext_resource type="Script" uid="uid://dts8lbivkgsmj" path="res://base/scripts/player/player.gd" id="1_1w3ab"]
|
[ext_resource type="Script" uid="uid://dts8lbivkgsmj" path="res://base/scripts/player/player.gd" id="1_1w3ab"]
|
||||||
[ext_resource type="Texture2D" uid="uid://dftqlo1lltx5f" path="res://base/assets/sprites/guns/gangstaholder/static.png" id="2_1w3ab"]
|
[ext_resource type="Texture2D" uid="uid://cy3ija8ratxjq" path="res://base/assets/sprites/guns/gangstaholder/shoot1.png" id="2_gt0rj"]
|
||||||
[ext_resource type="PackedScene" uid="uid://bb6ovrbusyxpi" path="res://base/scenes/weapons/weapon_base.tscn" id="2_ma1q3"]
|
[ext_resource type="PackedScene" uid="uid://bb6ovrbusyxpi" path="res://base/scenes/weapons/weapon_base.tscn" id="2_ma1q3"]
|
||||||
[ext_resource type="Script" uid="uid://byhp4pklbjltn" path="res://base/scripts/player/weapon_container.gd" id="3_1w3ab"]
|
[ext_resource type="Script" uid="uid://byhp4pklbjltn" path="res://base/scripts/player/weapon_container.gd" id="3_1w3ab"]
|
||||||
[ext_resource type="Script" uid="uid://diu6eno2ag6ga" path="res://base/scripts/player/weapon_slot.gd" id="4_gt0rj"]
|
[ext_resource type="Script" uid="uid://diu6eno2ag6ga" path="res://base/scripts/player/weapon_slot.gd" id="4_gt0rj"]
|
||||||
|
@ -32,7 +32,7 @@ grow_horizontal = 2
|
||||||
grow_vertical = 2
|
grow_vertical = 2
|
||||||
size_flags_horizontal = 3
|
size_flags_horizontal = 3
|
||||||
size_flags_vertical = 3
|
size_flags_vertical = 3
|
||||||
texture = ExtResource("2_1w3ab")
|
texture = ExtResource("2_gt0rj")
|
||||||
stretch_mode = 6
|
stretch_mode = 6
|
||||||
|
|
||||||
[node name="AnimationPlayer" type="AnimationPlayer" parent="HUD/Weapon"]
|
[node name="AnimationPlayer" type="AnimationPlayer" parent="HUD/Weapon"]
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
|
|
||||||
[sub_resource type="Resource" id="Resource_s6ep3"]
|
[sub_resource type="Resource" id="Resource_s6ep3"]
|
||||||
script = ExtResource("2_wftdl")
|
script = ExtResource("2_wftdl")
|
||||||
fire_delay = 0.3
|
fire_delay = 0.35
|
||||||
metadata/_custom_type_script = "uid://dsvgbyeerw1ld"
|
metadata/_custom_type_script = "uid://dsvgbyeerw1ld"
|
||||||
|
|
||||||
[node name="Weapon" instance=ExtResource("1_dnsf3")]
|
[node name="Weapon" instance=ExtResource("1_dnsf3")]
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
|
|
||||||
[sub_resource type="Resource" id="Resource_ij06d"]
|
[sub_resource type="Resource" id="Resource_ij06d"]
|
||||||
script = ExtResource("2_bt0tf")
|
script = ExtResource("2_bt0tf")
|
||||||
fire_delay = 0.5
|
fire_delay = 0.3
|
||||||
metadata/_custom_type_script = "uid://ckexgw71dd5jc"
|
metadata/_custom_type_script = "uid://ckexgw71dd5jc"
|
||||||
|
|
||||||
[node name="Weapon" type="Node3D"]
|
[node name="Weapon" type="Node3D"]
|
||||||
|
|
|
@ -8,6 +8,7 @@ enum Command {
|
||||||
NONE,
|
NONE,
|
||||||
TAKE_WEAPON,
|
TAKE_WEAPON,
|
||||||
FIRE,
|
FIRE,
|
||||||
|
STOP_FIRING,
|
||||||
RELOAD,
|
RELOAD,
|
||||||
HOLSTER_WEAPON,
|
HOLSTER_WEAPON,
|
||||||
TAKE_ZAZA,
|
TAKE_ZAZA,
|
||||||
|
@ -30,7 +31,6 @@ var command_queue: Dictionary = {}
|
||||||
|
|
||||||
func _init() -> void:
|
func _init() -> void:
|
||||||
for side in Side.values():
|
for side in Side.values():
|
||||||
print(side)
|
|
||||||
var arr: Array[Command] = []
|
var arr: Array[Command] = []
|
||||||
command_queue[side] = arr
|
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)
|
var weapon_sides_are_free = not queue.sides_are_busy(weapon_sides)
|
||||||
if weapon_sides_are_free:
|
if weapon_sides_are_free:
|
||||||
# Fire logic
|
# Fire logic
|
||||||
var fire_action = Input.is_action_just_pressed('shoot') if \
|
var fire_action = Input.is_action_just_pressed('shoot')
|
||||||
current_weapon.fire_mode is SingleFireMode else \
|
|
||||||
Input.is_action_pressed('shoot')
|
|
||||||
if fire_action:
|
if fire_action:
|
||||||
push_copied_command(CommandQueue.Command.FIRE, weapon_sides)
|
push_copied_command(CommandQueue.Command.FIRE, weapon_sides)
|
||||||
|
|
||||||
|
|
||||||
# Reload logic
|
# Reload logic
|
||||||
var reload_action = Input.is_action_just_pressed('reload')
|
var reload_action = Input.is_action_just_pressed('reload')
|
||||||
if reload_action:
|
if reload_action:
|
||||||
|
@ -58,6 +57,13 @@ func _process(_delta: float) -> void:
|
||||||
if slot_action:
|
if slot_action:
|
||||||
weapons.select_slot(slot_id)
|
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():
|
for side in CommandQueue.Side.values():
|
||||||
var command = queue.current_command(side)
|
var command = queue.current_command(side)
|
||||||
match side:
|
match side:
|
||||||
|
@ -92,6 +98,7 @@ func on_weapon_slot_selected():
|
||||||
if current_weapon != null:
|
if current_weapon != null:
|
||||||
current_weapon.fired.disconnect(on_weapon_fired)
|
current_weapon.fired.disconnect(on_weapon_fired)
|
||||||
current_weapon.fire_failed.disconnect(finish_task)
|
current_weapon.fire_failed.disconnect(finish_task)
|
||||||
|
current_weapon.fire_allowed.disconnect(finish_task)
|
||||||
|
|
||||||
weapon_player.remove_animation_library("current")
|
weapon_player.remove_animation_library("current")
|
||||||
|
|
||||||
|
@ -99,6 +106,7 @@ func on_weapon_slot_selected():
|
||||||
|
|
||||||
current_weapon.fired.connect(on_weapon_fired)
|
current_weapon.fired.connect(on_weapon_fired)
|
||||||
current_weapon.fire_failed.connect(finish_task)
|
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.add_animation_library("current", current_weapon.animation_library)
|
||||||
weapon_player.play("current/static")
|
weapon_player.play("current/static")
|
||||||
|
@ -150,6 +158,7 @@ func update_ammo_label():
|
||||||
})
|
})
|
||||||
|
|
||||||
func on_weapon_fired():
|
func on_weapon_fired():
|
||||||
|
weapon_player.stop()
|
||||||
weapon_player.play("current/fire")
|
weapon_player.play("current/fire")
|
||||||
update_ammo_label()
|
update_ammo_label()
|
||||||
|
|
||||||
|
@ -167,6 +176,9 @@ func handle_new_right_command(command: CommandQueue.Command):
|
||||||
match command:
|
match command:
|
||||||
CommandQueue.Command.RELOAD:
|
CommandQueue.Command.RELOAD:
|
||||||
weapon_player.play('current/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):
|
func handle_ended_left_command(command: CommandQueue.Command):
|
||||||
match command:
|
match command:
|
||||||
|
@ -189,6 +201,8 @@ func handle_started_right_command(command: CommandQueue.Command):
|
||||||
match command:
|
match command:
|
||||||
CommandQueue.Command.FIRE:
|
CommandQueue.Command.FIRE:
|
||||||
current_weapon.request_fire()
|
current_weapon.request_fire()
|
||||||
|
CommandQueue.Command.STOP_FIRING:
|
||||||
|
queue.pop()
|
||||||
|
|
||||||
func handle_current_left_command(command: CommandQueue.Command):
|
func handle_current_left_command(command: CommandQueue.Command):
|
||||||
match command:
|
match command:
|
||||||
|
|
|
@ -26,5 +26,4 @@ func select_slot(index: int):
|
||||||
if slots[index].has_weapon:
|
if slots[index].has_weapon:
|
||||||
current_slot = slots[index]
|
current_slot = slots[index]
|
||||||
current_weapon = current_slot.weapon
|
current_weapon = current_slot.weapon
|
||||||
print('here we go')
|
|
||||||
slot_selected.emit()
|
slot_selected.emit()
|
||||||
|
|
|
@ -24,6 +24,8 @@ func _process() -> void:
|
||||||
if _fire():
|
if _fire():
|
||||||
on_fire()
|
on_fire()
|
||||||
|
|
||||||
|
func _on_fire_end() -> void:
|
||||||
|
fire_allowed.emit()
|
||||||
|
|
||||||
## Invoked when cooldown has ended
|
## Invoked when cooldown has ended
|
||||||
func on_cooldown_timeout() -> void:
|
func on_cooldown_timeout() -> void:
|
||||||
|
|
|
@ -7,6 +7,9 @@ class_name BaseFireMode
|
||||||
var barrel : Barrel
|
var barrel : Barrel
|
||||||
var tree : SceneTree
|
var tree : SceneTree
|
||||||
|
|
||||||
|
## Emits when it's possible to request fire from outside
|
||||||
|
signal fire_allowed
|
||||||
|
|
||||||
func _init() -> void:
|
func _init() -> void:
|
||||||
resource_local_to_scene = true
|
resource_local_to_scene = true
|
||||||
|
|
||||||
|
|
|
@ -26,3 +26,4 @@ func _on_fire_begin() -> void:
|
||||||
## Invoked when cooldown has ended
|
## Invoked when cooldown has ended
|
||||||
func on_cooldown_timeout() -> void:
|
func on_cooldown_timeout() -> void:
|
||||||
cooldown = false
|
cooldown = false
|
||||||
|
fire_allowed.emit()
|
||||||
|
|
|
@ -4,12 +4,13 @@ class_name Weapon
|
||||||
|
|
||||||
signal fired()
|
signal fired()
|
||||||
signal fire_failed()
|
signal fire_failed()
|
||||||
|
signal fire_allowed()
|
||||||
|
|
||||||
@onready var barrel = $"Barrel"
|
@onready var barrel = $"Barrel"
|
||||||
@export var uses_hands: Array[CommandQueue.Side]
|
@export var uses_hands: Array[CommandQueue.Side]
|
||||||
|
|
||||||
@export var max_ammo: int = 7
|
@export var max_ammo: int = 7
|
||||||
var ammo: int = max_ammo
|
var ammo: int
|
||||||
@export var ammo_consumption: int = 1
|
@export var ammo_consumption: int = 1
|
||||||
|
|
||||||
@export var fire_mode: BaseFireMode
|
@export var fire_mode: BaseFireMode
|
||||||
|
@ -20,15 +21,19 @@ var ammo: int = max_ammo
|
||||||
var is_firing: bool = false
|
var is_firing: bool = false
|
||||||
|
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
|
ammo = max_ammo
|
||||||
fire_mode.barrel = barrel
|
fire_mode.barrel = barrel
|
||||||
fire_mode.tree = get_tree()
|
fire_mode.tree = get_tree()
|
||||||
|
fire_mode.fire_allowed.connect(on_fire_allowed)
|
||||||
barrel.fired.connect(on_barrel_fired)
|
barrel.fired.connect(on_barrel_fired)
|
||||||
|
|
||||||
## Begin to fire
|
## Begin to fire
|
||||||
func request_fire() -> void:
|
func request_fire() -> void:
|
||||||
if not is_firing and ammo >= ammo_consumption:
|
if not is_firing and ammo >= ammo_consumption:
|
||||||
|
is_firing = true
|
||||||
fire_mode._on_fire_begin()
|
fire_mode._on_fire_begin()
|
||||||
elif ammo < ammo_consumption:
|
elif ammo < ammo_consumption:
|
||||||
|
end_fire()
|
||||||
fire_failed.emit()
|
fire_failed.emit()
|
||||||
|
|
||||||
func _process(_dt) -> void:
|
func _process(_dt) -> void:
|
||||||
|
@ -45,6 +50,12 @@ func on_barrel_fired() -> void:
|
||||||
is_firing = true
|
is_firing = true
|
||||||
ammo -= ammo_consumption
|
ammo -= ammo_consumption
|
||||||
fired.emit()
|
fired.emit()
|
||||||
|
if ammo < ammo_consumption:
|
||||||
|
end_fire()
|
||||||
|
|
||||||
|
func on_fire_allowed() -> void:
|
||||||
|
fire_allowed.emit()
|
||||||
|
is_firing = false
|
||||||
|
|
||||||
func reload() -> void:
|
func reload() -> void:
|
||||||
ammo = max_ammo
|
ammo = max_ammo
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue