blank weapon fire system
This commit is contained in:
parent
8aa37bd929
commit
16b1d0f701
11 changed files with 92 additions and 51 deletions
|
@ -2,5 +2,10 @@ extends Node3D
|
|||
|
||||
class_name Barrel
|
||||
|
||||
signal fired()
|
||||
|
||||
func can_fire() -> bool:
|
||||
return true
|
||||
|
||||
func fire() -> void:
|
||||
fired.emit()
|
||||
|
|
|
@ -14,15 +14,15 @@ var cooldown : bool = false
|
|||
## Reference to cooldown scene timer
|
||||
var cooldown_timer : SceneTreeTimer = null
|
||||
|
||||
func _on_fire_begin(_tree : SceneTree) -> void:
|
||||
func _on_fire_begin() -> void:
|
||||
cooldown = false
|
||||
check_unfinished_timer(cooldown_timer,on_cooldown_timeout)
|
||||
|
||||
func _process(tree : SceneTree) -> void:
|
||||
func _process() -> void:
|
||||
if can_fire() :
|
||||
return
|
||||
if _fire():
|
||||
on_fire(tree)
|
||||
on_fire()
|
||||
|
||||
|
||||
## Invoked when cooldown has ended
|
||||
|
@ -42,7 +42,7 @@ func can_fire() -> bool:
|
|||
return cooldown
|
||||
|
||||
## Invoked when fired
|
||||
func on_fire(tree : SceneTree) -> void:
|
||||
func on_fire() -> void:
|
||||
cooldown = true
|
||||
cooldown_timer = tree.create_timer(fire_delay)
|
||||
cooldown_timer.timeout.connect(on_cooldown_timeout)
|
||||
|
|
|
@ -5,7 +5,7 @@ class_name BaseFireMode
|
|||
|
||||
## Assigned barrel to shoot out of
|
||||
var barrel : Barrel
|
||||
var tree : Tree
|
||||
var tree : SceneTree
|
||||
|
||||
func _init() -> void:
|
||||
resource_local_to_scene = true
|
||||
|
@ -14,6 +14,7 @@ func _init() -> void:
|
|||
## Returns [color=green]true[/color] if barrel can shoot,[br]
|
||||
## Returns [color=red]false[/color] if barrel cannot shoot
|
||||
func _fire() -> bool:
|
||||
barrel.fire()
|
||||
return true
|
||||
|
||||
|
||||
|
|
|
@ -20,15 +20,15 @@ var reloading : bool = false
|
|||
## Reference to reload scene timer
|
||||
var reload_timer : SceneTreeTimer = null
|
||||
|
||||
func _on_fire_begin(_tree : SceneTree) -> void:
|
||||
super._on_fire_begin(_tree)
|
||||
func _on_fire_begin() -> void:
|
||||
super._on_fire_begin()
|
||||
current_amount = 0
|
||||
reloading = false
|
||||
check_unfinished_timer(reload_timer,on_reload_timeout)
|
||||
|
||||
|
||||
func on_fire(tree : SceneTree) -> void:
|
||||
super.on_fire(tree)
|
||||
func on_fire() -> void:
|
||||
super.on_fire()
|
||||
current_amount += 1
|
||||
if current_amount >= burst_amount:
|
||||
reloading = true
|
||||
|
|
|
@ -13,7 +13,7 @@ class_name SingleFireMode
|
|||
var cooldown : bool = false
|
||||
|
||||
|
||||
func _on_fire_begin(tree) -> void:
|
||||
func _on_fire_begin() -> void:
|
||||
if cooldown:
|
||||
return
|
||||
|
||||
|
|
|
@ -2,6 +2,8 @@ extends Node3D
|
|||
|
||||
class_name Weapon
|
||||
|
||||
signal fired()
|
||||
|
||||
@onready var barrel = $"Barrel"
|
||||
@export var uses_hands: Array[CommandQueue.Side]
|
||||
|
||||
|
@ -10,6 +12,7 @@ var ammo: int = max_ammo
|
|||
@export var ammo_consumption: int = 1
|
||||
|
||||
@export var fire_mode: BaseFireMode
|
||||
|
||||
## Weapon animation library. Should contain "static", "fire", "reload" animations
|
||||
@export var animation_library: AnimationLibrary
|
||||
|
||||
|
@ -17,17 +20,23 @@ var is_firing: bool = false
|
|||
|
||||
func _ready() -> void:
|
||||
fire_mode.barrel = barrel
|
||||
fire_mode.tree = get_tree()
|
||||
barrel.fired.connect(on_barrel_fired)
|
||||
|
||||
## Begin to fire
|
||||
func request_fire() -> void:
|
||||
fire_mode.on_fire_begin(get_tree())
|
||||
is_firing = true
|
||||
fire_mode._on_fire_begin()
|
||||
|
||||
func _process(_dt) -> void:
|
||||
if is_firing:
|
||||
fire_mode._process(get_tree())
|
||||
fire_mode._process()
|
||||
|
||||
## End fire
|
||||
func end_fire() -> void:
|
||||
fire_mode.on_fire_end(get_tree())
|
||||
is_firing = false
|
||||
if is_firing:
|
||||
fire_mode._on_fire_end()
|
||||
is_firing = false
|
||||
|
||||
func on_barrel_fired() -> void:
|
||||
is_firing = true
|
||||
fired.emit()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue