Burst fire mode
This commit is contained in:
parent
667c1b22b2
commit
db6544b6eb
3 changed files with 54 additions and 2 deletions
|
@ -15,10 +15,15 @@ func _fire() -> bool:
|
|||
|
||||
|
||||
## Invoked when fire button is just pressed or reload ended while fire button is still pressed
|
||||
func _on_fire_begin() -> void:
|
||||
func _on_fire_begin(tree : SceneTree) -> void:
|
||||
pass
|
||||
|
||||
|
||||
## Invoked when fire button is just released or reload started while fire button is still pressed
|
||||
func _on_fire_end() -> void:
|
||||
func _on_fire_end(tree : SceneTree) -> void:
|
||||
pass
|
||||
|
||||
|
||||
## Invoked every process frame on active fire mode
|
||||
func _process(tree : SceneTree) -> void:
|
||||
pass
|
||||
|
|
46
base/scripts/weapons/fire_mode/burst_fire_mode.gd
Normal file
46
base/scripts/weapons/fire_mode/burst_fire_mode.gd
Normal file
|
@ -0,0 +1,46 @@
|
|||
extends BaseFireMode
|
||||
|
||||
## Fire mode that fires in bursts
|
||||
class_name BurstFireMode
|
||||
|
||||
|
||||
## Amount of bullets in burst
|
||||
@export_range(1,25,1,"or_greater") var burst_amount : int = 1
|
||||
|
||||
## Time to reload a burst
|
||||
@export var burst_time : float
|
||||
|
||||
## Amount of bullets currently [br]
|
||||
## Resets in _on_fire_end
|
||||
var current_amount : int = 0
|
||||
|
||||
## Controls burst internal reload
|
||||
var reloading : bool = false
|
||||
|
||||
## Reference to scene timer
|
||||
var timer : SceneTreeTimer = null
|
||||
|
||||
|
||||
func _on_fire_begin(_tree : SceneTree) -> void:
|
||||
current_amount = 0
|
||||
if timer != null:
|
||||
timer.timeout.disconnect(on_reload_timeout)
|
||||
timer = null
|
||||
|
||||
|
||||
func _process(_tree : SceneTree) -> void:
|
||||
if reloading:
|
||||
return
|
||||
if _fire():
|
||||
current_amount += 1
|
||||
if current_amount >= burst_amount:
|
||||
reloading = true
|
||||
timer = _tree.create_timer(burst_time)
|
||||
timer.timeout.connect(on_reload_timeout)
|
||||
|
||||
|
||||
## Invoked when reload has ended
|
||||
func on_reload_timeout() -> void:
|
||||
reloading = false
|
||||
current_amount = 0
|
||||
timer = null
|
1
base/scripts/weapons/fire_mode/burst_fire_mode.gd.uid
Normal file
1
base/scripts/weapons/fire_mode/burst_fire_mode.gd.uid
Normal file
|
@ -0,0 +1 @@
|
|||
uid://msfvntjnawy5
|
Loading…
Add table
Add a link
Reference in a new issue