Started fps system
This commit is contained in:
parent
0dc6247f91
commit
cc26793ab6
32 changed files with 2756 additions and 11 deletions
|
|
@ -5,6 +5,8 @@ func _ready() -> void:
|
|||
|
||||
func _on_leave_button_pressed() -> void:
|
||||
Lobby.leave()
|
||||
$"../..".hide()
|
||||
$"../../../MainMenu".show()
|
||||
|
||||
func _on_start_button_pressed() -> void:
|
||||
Lobby.start_game.rpc()
|
||||
|
|
|
|||
|
|
@ -9,6 +9,11 @@ func _on_host_button_pressed() -> void:
|
|||
|
||||
|
||||
func _on_connect_button_pressed() -> void:
|
||||
Lobby.join("localhost")
|
||||
var ip = $MainMenu/VBoxContainer/LineEdit.text
|
||||
if ip == "":
|
||||
ip = "localhost"
|
||||
var joined = Lobby.join(ip)
|
||||
if joined != Error.OK:
|
||||
return
|
||||
$MainMenu.hide()
|
||||
$Lobby.show()
|
||||
|
|
|
|||
|
|
@ -14,11 +14,14 @@ func host() -> void:
|
|||
multiplayer.multiplayer_peer = peer
|
||||
lobby_created.emit()
|
||||
|
||||
func join(ip: String) -> void:
|
||||
func join(ip: String) -> Error:
|
||||
var peer: ENetMultiplayerPeer = ENetMultiplayerPeer.new()
|
||||
peer.create_client(ip,PORT)
|
||||
var res = peer.create_client(ip,PORT)
|
||||
if res != 0:
|
||||
return res
|
||||
multiplayer.multiplayer_peer = peer
|
||||
lobby_joined.emit()
|
||||
return Error.OK
|
||||
|
||||
func leave() -> void:
|
||||
multiplayer.multiplayer_peer = OfflineMultiplayerPeer.new()
|
||||
|
|
|
|||
|
|
@ -1,5 +1,19 @@
|
|||
extends CharacterBody3D
|
||||
|
||||
const MAX_HP = 100
|
||||
|
||||
@export var hp: int = 100:
|
||||
set(value):
|
||||
if value < 0:
|
||||
hp = 0
|
||||
else:
|
||||
hp = value
|
||||
if hp == 0:
|
||||
die()
|
||||
|
||||
get:
|
||||
return hp
|
||||
|
||||
@export var animation_player: AnimationPlayer
|
||||
@export var stand_up_area: Area3D
|
||||
|
||||
|
|
@ -71,7 +85,6 @@ func _input(event: InputEvent) -> void:
|
|||
crouched = true
|
||||
elif event.is_action_released("plr_crouch") and TOGGLE_CROUCH == false:
|
||||
crouched = false
|
||||
if event.is_action_pressed("plr_drop"):
|
||||
var grenade = preload("res://scenes/smoke.tscn").instantiate()
|
||||
get_tree().current_scene.add_child(grenade)
|
||||
grenade.global_position = global_position + Vector3.UP * 0.5
|
||||
|
||||
func die() -> void:
|
||||
queue_free()
|
||||
|
|
|
|||
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
|
||||
1
scripts/weapon_system/gun.gd.uid
Normal file
1
scripts/weapon_system/gun.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://c76n6qgu6o4hn
|
||||
107
scripts/weapon_system/system.gd
Normal file
107
scripts/weapon_system/system.gd
Normal file
|
|
@ -0,0 +1,107 @@
|
|||
extends Node
|
||||
|
||||
|
||||
class_name WeaponSystem
|
||||
|
||||
@export var default_pistol: Usable
|
||||
@export var default_knife: Usable
|
||||
|
||||
@export var animation_player: AnimationPlayer
|
||||
|
||||
var current_usable: Usable
|
||||
|
||||
var slots: Dictionary[StringName,Usable] = {
|
||||
"primary": null,
|
||||
"secondary": default_pistol,
|
||||
"knife": default_knife,
|
||||
"bomb": null,
|
||||
"ability_first": null,
|
||||
"ability_second": null,
|
||||
"ability_third": null,
|
||||
"ultimate": null
|
||||
}
|
||||
|
||||
signal switched_to(usable: Usable)
|
||||
|
||||
func _ready() -> void:
|
||||
for child in get_children():
|
||||
if child is Usable:
|
||||
child.system = self
|
||||
else:
|
||||
push_warning("Child of weapon system is not ability or weapon")
|
||||
|
||||
current_usable = default_pistol
|
||||
current_usable.enter()
|
||||
|
||||
func can_add(slot: StringName) -> bool:
|
||||
return slots.has(slot)
|
||||
|
||||
func add(usable: Usable, slot: StringName) -> void:
|
||||
if can_add(slot) == false:
|
||||
return
|
||||
|
||||
add_child(usable)
|
||||
|
||||
slots[slot] = usable
|
||||
usable.system = self
|
||||
|
||||
|
||||
func switch(to: StringName):
|
||||
if slots.has(to) == false or slots[to] == null:
|
||||
return
|
||||
|
||||
current_usable.exit()
|
||||
current_usable.in_use = false
|
||||
current_usable = slots[to]
|
||||
current_usable.enter()
|
||||
current_usable.in_use = true
|
||||
|
||||
switched_to.emit(current_usable)
|
||||
|
||||
update_remotes.rpc(to)
|
||||
|
||||
@rpc("authority","call_remote","reliable")
|
||||
func update_remotes(to: StringName):
|
||||
switch(to)
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
if current_usable == null:
|
||||
push_error("State is not set")
|
||||
return
|
||||
current_usable.update(delta)
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
if current_usable == null:
|
||||
push_error("State is not set")
|
||||
return
|
||||
current_usable.physics_update(delta)
|
||||
|
||||
func _input(event: InputEvent) -> void:
|
||||
if is_multiplayer_authority() == false: return
|
||||
|
||||
if event.is_action_pressed("plr_ult"):
|
||||
switch("ultimate")
|
||||
elif event.is_action_pressed("plr_bomb"):
|
||||
switch("bomb")
|
||||
elif event.is_action_pressed("plr_primary"):
|
||||
switch("primary")
|
||||
elif event.is_action_pressed("plr_active_first"):
|
||||
switch("ability_first")
|
||||
elif event.is_action_pressed("plr_active_second"):
|
||||
switch("ability_second")
|
||||
elif event.is_action_pressed("plr_active_third"):
|
||||
switch("ability_third")
|
||||
elif event.is_action_pressed("plr_secondary"):
|
||||
switch("secondary")
|
||||
elif event.is_action_pressed("plr_knife"):
|
||||
switch("knife")
|
||||
|
||||
if event.is_action_pressed("plr_fire"):
|
||||
current_usable.use_begin.rpc()
|
||||
if event.is_action_released("plr_fire"):
|
||||
current_usable.use_end.rpc()
|
||||
if event.is_action_pressed("plr_scope"):
|
||||
current_usable.alternate_state()
|
||||
if event.is_action_pressed("plr_firemode"):
|
||||
current_usable.switch_mode()
|
||||
|
||||
1
scripts/weapon_system/system.gd.uid
Normal file
1
scripts/weapon_system/system.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://bmecgup3kcua7
|
||||
25
scripts/weapon_system/usable.gd
Normal file
25
scripts/weapon_system/usable.gd
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
@abstract
|
||||
extends Node
|
||||
|
||||
class_name Usable
|
||||
|
||||
var system: WeaponSystem
|
||||
var in_use: bool = false
|
||||
|
||||
@rpc("authority","call_local","reliable")
|
||||
@abstract func use_begin() -> void
|
||||
@rpc("authority","call_local","reliable")
|
||||
@abstract func use_end() -> void
|
||||
@abstract func alternate_state() -> void
|
||||
# Need to clarify naming; Switch mode like firemode. For different states use
|
||||
# alternate_state
|
||||
@abstract func switch_mode() -> void
|
||||
|
||||
func enter() -> void:
|
||||
pass
|
||||
func exit() -> void:
|
||||
pass
|
||||
func update(_delta: float) -> void:
|
||||
pass
|
||||
func physics_update(_delta: float) -> void:
|
||||
pass
|
||||
1
scripts/weapon_system/usable.gd.uid
Normal file
1
scripts/weapon_system/usable.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://qj4m67w7ps7j
|
||||
Loading…
Add table
Add a link
Reference in a new issue