weapon system rework
This commit is contained in:
parent
0ffc2b2497
commit
30b01100f0
27 changed files with 352 additions and 190 deletions
26
scripts/weapon_system/gun/idle_state.gd
Normal file
26
scripts/weapon_system/gun/idle_state.gd
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
extends WeaponState
|
||||
|
||||
@export var emptyable: bool
|
||||
|
||||
func enter() -> void:
|
||||
machine.animation_player.play(with_morphems("idle"))
|
||||
|
||||
func exit() -> void:
|
||||
pass
|
||||
|
||||
func _input(event: InputEvent) -> void:
|
||||
if not machine.is_multiplayer_authority(): return
|
||||
|
||||
if event.is_action_pressed("plr_reload"):
|
||||
init_reload()
|
||||
|
||||
func use_begin() -> void:
|
||||
transition.emit("Shoot")
|
||||
|
||||
func init_reload():
|
||||
if machine.ammo == machine.max_ammo:
|
||||
return
|
||||
transition.emit("Reload")
|
||||
|
||||
func with_morphems(animation):
|
||||
return machine.animation_prefix + (animation+"_empty") if emptyable and machine.ammo == 0 else animation
|
||||
1
scripts/weapon_system/gun/idle_state.gd.uid
Normal file
1
scripts/weapon_system/gun/idle_state.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://ofv4e3dsfe8
|
||||
17
scripts/weapon_system/gun/intro_state.gd
Normal file
17
scripts/weapon_system/gun/intro_state.gd
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
extends WeaponState
|
||||
|
||||
@export var emptyable: bool
|
||||
|
||||
func enter() -> void:
|
||||
machine.animation_player.play(with_morphems("intro"))
|
||||
machine.animation_player.animation_finished.connect(on_animation_finished)
|
||||
|
||||
func exit() -> void:
|
||||
machine.animation_player.animation_finished.disconnect(on_animation_finished)
|
||||
|
||||
func on_animation_finished(animation):
|
||||
if animation == with_morphems("intro"):
|
||||
transition.emit("Idle")
|
||||
|
||||
func with_morphems(animation):
|
||||
return machine.animation_prefix + (animation+"_empty") if emptyable and machine.ammo == 0 else animation
|
||||
1
scripts/weapon_system/gun/intro_state.gd.uid
Normal file
1
scripts/weapon_system/gun/intro_state.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://bmj0bwy2tlian
|
||||
18
scripts/weapon_system/gun/reload_state.gd
Normal file
18
scripts/weapon_system/gun/reload_state.gd
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
extends WeaponState
|
||||
|
||||
@export var emptyable: bool
|
||||
|
||||
func enter() -> void:
|
||||
machine.animation_player.play(with_morphems("reload"))
|
||||
machine.animation_player.animation_finished.connect(on_animation_finished)
|
||||
|
||||
func exit() -> void:
|
||||
machine.animation_player.animation_finished.disconnect(on_animation_finished)
|
||||
|
||||
func on_animation_finished(animation):
|
||||
if animation == with_morphems("reload"):
|
||||
machine.ammo = machine.max_ammo
|
||||
transition.emit("Idle")
|
||||
|
||||
func with_morphems(animation):
|
||||
return machine.animation_prefix + (animation+"_empty") if emptyable and machine.ammo == 0 else animation
|
||||
1
scripts/weapon_system/gun/reload_state.gd.uid
Normal file
1
scripts/weapon_system/gun/reload_state.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://hmekwp8444ao
|
||||
39
scripts/weapon_system/gun/semi_auto_shoot_state.gd
Normal file
39
scripts/weapon_system/gun/semi_auto_shoot_state.gd
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
extends WeaponState
|
||||
|
||||
@export var raycast: RayCast3D
|
||||
@export var emptyable: bool
|
||||
@export var damage: int
|
||||
|
||||
@export var fire_timer: Timer
|
||||
|
||||
func enter() -> void:
|
||||
fire()
|
||||
machine.animation_player.animation_finished.connect(on_animation_finished)
|
||||
|
||||
func exit() -> void:
|
||||
machine.animation_player.animation_finished.disconnect(on_animation_finished)
|
||||
|
||||
func on_animation_finished(animation):
|
||||
if animation == with_morphems("shoot"):
|
||||
transition.emit("Idle")
|
||||
|
||||
func use_begin() -> void:
|
||||
if fire_timer.time_left > 0:
|
||||
return
|
||||
fire()
|
||||
|
||||
func fire() -> void:
|
||||
if machine.ammo == 0 or fire_timer.time_left > 0:
|
||||
return
|
||||
machine.ammo -= 1
|
||||
|
||||
machine.animation_player.stop()
|
||||
machine.animation_player.play(with_morphems("shoot"))
|
||||
|
||||
if raycast.is_colliding():
|
||||
raycast.get_collider().hp -= damage
|
||||
|
||||
fire_timer.start()
|
||||
|
||||
func with_morphems(animation):
|
||||
return machine.animation_prefix + (animation+"_empty") if emptyable and machine.ammo == 0 else animation
|
||||
1
scripts/weapon_system/gun/semi_auto_shoot_state.gd.uid
Normal file
1
scripts/weapon_system/gun/semi_auto_shoot_state.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://vj13r83l3xyq
|
||||
Loading…
Add table
Add a link
Reference in a new issue