Started fps system
This commit is contained in:
parent
0dc6247f91
commit
cc26793ab6
32 changed files with 2756 additions and 11 deletions
67
scripts/weapon_system/gun.gd
Normal file
67
scripts/weapon_system/gun.gd
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
extends Usable
|
||||
|
||||
|
||||
@export var max_ammo: int
|
||||
@export var semi_auto: bool
|
||||
@export var damage: int
|
||||
|
||||
@export var firerate: float
|
||||
|
||||
@export var prefix: String
|
||||
|
||||
var ammo_amount: int
|
||||
var fire_timer: Timer
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
fire_timer = Timer.new()
|
||||
fire_timer.wait_time = firerate
|
||||
ammo_amount = max_ammo
|
||||
add_child(fire_timer)
|
||||
if not semi_auto:
|
||||
fire_timer.timeout.connect(fire)
|
||||
|
||||
@rpc("authority","call_local","reliable")
|
||||
func use_begin() -> void:
|
||||
if fire_timer.is_stopped() == false:
|
||||
return
|
||||
fire_timer.start()
|
||||
fire_timer.one_shot = true if semi_auto else false
|
||||
fire()
|
||||
|
||||
@rpc("authority","call_local","reliable")
|
||||
func use_end() -> void:
|
||||
fire_timer.one_shot = true
|
||||
|
||||
func fire() -> void:
|
||||
if ammo_amount == 0:
|
||||
if not semi_auto:
|
||||
fire_timer.stop()
|
||||
return
|
||||
ammo_amount -= 1
|
||||
|
||||
system.animation_player.stop()
|
||||
system.animation_player.play(prefix+"_shoot")
|
||||
system.animation_player.queue(prefix+"_idle")
|
||||
|
||||
func alternate_state() -> void:
|
||||
pass
|
||||
|
||||
func switch_mode() -> void:
|
||||
pass
|
||||
|
||||
func enter() -> void:
|
||||
system.animation_player.play(prefix+"_idle")
|
||||
|
||||
func _input(event: InputEvent) -> void:
|
||||
if not system.is_multiplayer_authority(): return
|
||||
|
||||
if event.is_action_pressed("plr_reload"):
|
||||
init_reload.rpc()
|
||||
|
||||
@rpc("call_local","authority","reliable")
|
||||
func init_reload():
|
||||
if ammo_amount == max_ammo or system.animation_player.current_animation == prefix + "_reload":
|
||||
return
|
||||
system.animation_player.play(prefix+"_reload")
|
||||
ammo_amount = max_ammo
|
||||
Loading…
Add table
Add a link
Reference in a new issue