Merge branch 'multiplayer-rework'
This commit is contained in:
commit
2c9ef1cfe1
38 changed files with 535 additions and 288 deletions
|
|
@ -7,17 +7,10 @@ extends Node
|
|||
const ATTACK_LAYER: int = 0b10000
|
||||
const DEFENCE_LAYER: int = 0b100000
|
||||
|
||||
func on_spawned() -> void:
|
||||
func _ready() -> void:
|
||||
if is_multiplayer_authority() == false: return
|
||||
var mask = (ATTACK_LAYER if (player.team == Session.TEAMS.DEFENCE != inverse) else DEFENCE_LAYER)
|
||||
if layer:
|
||||
get_parent().collision_layer |= mask
|
||||
else:
|
||||
get_parent().collision_mask |= mask
|
||||
global_update.rpc(layer,mask)
|
||||
|
||||
@rpc
|
||||
func global_update(new_layer,mask) -> void:
|
||||
if new_layer:
|
||||
get_parent().collision_layer |= mask
|
||||
else:
|
||||
get_parent().collision_mask |= mask
|
||||
|
|
|
|||
|
|
@ -4,9 +4,8 @@ extends Camera3D
|
|||
|
||||
var active: bool
|
||||
|
||||
func _ready() -> void:
|
||||
if not is_multiplayer_authority():
|
||||
return
|
||||
func _enter_tree() -> void:
|
||||
set_multiplayer_authority(int(get_parent().get_parent().name))
|
||||
|
||||
func set_active() -> void:
|
||||
if not is_multiplayer_authority():
|
||||
|
|
|
|||
|
|
@ -4,10 +4,14 @@ class_name Player
|
|||
|
||||
@export var team: Session.TEAMS
|
||||
@export var weapon_models: Dictionary[StringName,Node3D]
|
||||
@export var player_id: int = 1:
|
||||
set(id):
|
||||
player_id = id
|
||||
$PlayerInput.set_multiplayer_authority(id)
|
||||
$Camera3D.set_multiplayer_authority(id)
|
||||
|
||||
var passived: bool = false
|
||||
|
||||
signal spawned
|
||||
signal health_changed(to: int)
|
||||
signal died
|
||||
|
||||
|
|
@ -26,52 +30,24 @@ const MAX_HP = 100
|
|||
get:
|
||||
return hp
|
||||
|
||||
func _enter_tree() -> void:
|
||||
set_multiplayer_authority(str(name).to_int())
|
||||
|
||||
func _physics_process(_delta: float) -> void:
|
||||
if not is_multiplayer_authority():
|
||||
if not multiplayer.is_server():
|
||||
return
|
||||
|
||||
move_and_slide()
|
||||
|
||||
func die() -> void:
|
||||
if (not is_multiplayer_authority()):
|
||||
if (not multiplayer.is_server()):
|
||||
return
|
||||
Session.add_dead.rpc(team)
|
||||
Session.add_dead(team)
|
||||
died.emit()
|
||||
passived = true
|
||||
|
||||
@rpc("any_peer","call_local","reliable")
|
||||
func passive() -> void:
|
||||
passived = true
|
||||
|
||||
@rpc("any_peer","call_local","reliable")
|
||||
func depassive() -> void:
|
||||
passived = false
|
||||
|
||||
@rpc("any_peer","call_local","reliable")
|
||||
func kill_request() -> void:
|
||||
if multiplayer.get_remote_sender_id() != 1:
|
||||
return
|
||||
|
||||
die()
|
||||
|
||||
@rpc("any_peer","call_local","reliable")
|
||||
func set_after_spawn(start_position: Vector3,new_team: int):
|
||||
global_position = start_position
|
||||
team = new_team as Session.TEAMS
|
||||
spawned.emit()
|
||||
|
||||
@rpc("any_peer","call_local","reliable")
|
||||
func take_damage(damage: int):
|
||||
hp -= damage
|
||||
$DamageAudio.multiplayer_play()
|
||||
|
||||
func _input(event: InputEvent) -> void:
|
||||
if not is_multiplayer_authority():
|
||||
return
|
||||
if event.is_action_pressed("plr_interact"):
|
||||
Session.interact()
|
||||
if event.is_action_released("plr_interact"):
|
||||
Session.stop_interact()
|
||||
|
|
|
|||
8
scripts/player/player_interaction.gd
Normal file
8
scripts/player/player_interaction.gd
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
extends Node
|
||||
|
||||
|
||||
func on_player_start_interacting():
|
||||
Session.interact(get_parent().player_id)
|
||||
|
||||
func on_player_end_interacting():
|
||||
Session.stop_interact(get_parent().player_id)
|
||||
1
scripts/player/player_interaction.gd.uid
Normal file
1
scripts/player/player_interaction.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://dsp1sq46c5i3y
|
||||
|
|
@ -3,6 +3,9 @@ extends Node
|
|||
class_name PlayerMovement
|
||||
|
||||
@export var player: Player
|
||||
@export var player_input: PlayerInput
|
||||
|
||||
@export var jump_velocity: float
|
||||
var disabled: bool
|
||||
|
||||
func disable() -> void:
|
||||
|
|
@ -15,7 +18,7 @@ func process_movement(max_speed: float,acceleration: float,deceleration: float,d
|
|||
player.velocity.x = 0
|
||||
player.velocity.z = 0
|
||||
return
|
||||
var input_dir := Input.get_vector("plr_strafe_r","plr_strafe_l", "plr_back","plr_forward")
|
||||
var input_dir := player_input.direction
|
||||
var direction := (player.transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized()
|
||||
if direction:
|
||||
player.velocity.x = clamp(player.velocity.x + direction.x * acceleration * delta,-max_speed*abs(direction.x),max_speed*abs(direction.x))
|
||||
|
|
@ -23,3 +26,6 @@ func process_movement(max_speed: float,acceleration: float,deceleration: float,d
|
|||
else:
|
||||
player.velocity.x = move_toward(player.velocity.x, 0, deceleration*delta)
|
||||
player.velocity.z = move_toward(player.velocity.z, 0, deceleration*delta)
|
||||
|
||||
func jump() -> void:
|
||||
player.velocity.y = jump_velocity
|
||||
|
|
|
|||
|
|
@ -8,22 +8,22 @@ extends State
|
|||
@export var stand_up_area: Area3D
|
||||
@export var player: Player
|
||||
@export var player_movement: PlayerMovement
|
||||
@export var player_input: PlayerInput
|
||||
@export var animation_player: AnimationPlayer
|
||||
@export var crouch_time: float = 0.1
|
||||
@export var weapon_system: WeaponSystem
|
||||
|
||||
func enter() -> void:
|
||||
animation_player.play("crouch",-1,1/crouch_time)
|
||||
player_input.crouch_end.connect(try_end_crouch)
|
||||
|
||||
func exit() -> void:
|
||||
animation_player.play("crouch",-1,-1/crouch_time,true)
|
||||
player_input.crouch_end.disconnect(try_end_crouch)
|
||||
|
||||
func physics_update(delta: float) -> void:
|
||||
if not is_multiplayer_authority():
|
||||
return
|
||||
if Input.is_action_just_pressed("plr_jump") and player.is_on_floor() and toggle:
|
||||
transition.emit("Stand")
|
||||
return
|
||||
|
||||
if not player.is_on_floor():
|
||||
transition.emit("Fall")
|
||||
|
|
@ -31,7 +31,6 @@ func physics_update(delta: float) -> void:
|
|||
|
||||
player_movement.process_movement(max_speed * weapon_system.get_speed_modifier(),acceleration,deceleration,delta)
|
||||
|
||||
func state_input(event: InputEvent) -> void:
|
||||
if (toggle == true and event.is_action_pressed("plr_crouch")) or (toggle == false and event.is_action_released("plr_crouch")):
|
||||
if stand_up_area.has_overlapping_bodies() == false:
|
||||
transition.emit("Stand")
|
||||
func try_end_crouch() -> void:
|
||||
if player.is_on_floor() and stand_up_area.has_overlapping_bodies() == false:
|
||||
transition.emit("Stand")
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ extends State
|
|||
|
||||
@export var player: Player
|
||||
@export var player_movement: PlayerMovement
|
||||
@export var player_input: PlayerInput
|
||||
@export var max_speed: float = 5.0
|
||||
@export var acceleration: float
|
||||
@export var weapon_system: WeaponSystem
|
||||
|
|
@ -18,7 +19,12 @@ func physics_update(delta: float) -> void:
|
|||
if not is_multiplayer_authority():
|
||||
return
|
||||
if player.is_on_floor():
|
||||
transition.emit("Stand")
|
||||
if player_input.compressed_states & PlayerInput.CROUCH:
|
||||
transition.emit("Crouch")
|
||||
elif player_input.compressed_states & PlayerInput.WALK:
|
||||
transition.emit("Walk")
|
||||
else:
|
||||
transition.emit("Stand")
|
||||
land_sound.multiplayer_play()
|
||||
|
||||
player.velocity += player.get_gravity() * delta
|
||||
|
|
|
|||
|
|
@ -3,9 +3,9 @@ extends State
|
|||
@export var max_speed: float = 5.0
|
||||
@export var acceleration: float = 2.0
|
||||
@export var deceleration: float = 200.0
|
||||
@export var JUMP_VELOCITY: float = 4.5
|
||||
@export var player: Player
|
||||
@export var player_movement: PlayerMovement
|
||||
@export var player_input: PlayerInput
|
||||
@export var weapon_system: WeaponSystem
|
||||
@export var audio: MultiplayerAudio3D
|
||||
@export var step_delay: float
|
||||
|
|
@ -14,18 +14,19 @@ extends State
|
|||
var step_time: float
|
||||
|
||||
func enter() -> void:
|
||||
pass
|
||||
player_input.jumped.connect(on_jumped)
|
||||
player_input.crouch_begin.connect(begin_crouch)
|
||||
player_input.walk_begin.connect(begin_walk)
|
||||
|
||||
func exit() -> void:
|
||||
player_input.jumped.disconnect(on_jumped)
|
||||
player_input.crouch_begin.disconnect(begin_crouch)
|
||||
player_input.walk_begin.disconnect(begin_walk)
|
||||
step_time = 0
|
||||
|
||||
func physics_update(delta: float) -> void:
|
||||
if not is_multiplayer_authority():
|
||||
return
|
||||
if Input.is_action_just_pressed("plr_jump") and player.is_on_floor():
|
||||
player.velocity.y = JUMP_VELOCITY * sign(weapon_system.get_speed_modifier())
|
||||
transition.emit("Fall")
|
||||
return
|
||||
|
||||
if not player.is_on_floor():
|
||||
transition.emit("Fall")
|
||||
|
|
@ -38,9 +39,13 @@ func physics_update(delta: float) -> void:
|
|||
|
||||
player_movement.process_movement(max_speed * weapon_system.get_speed_modifier(),acceleration,deceleration,delta)
|
||||
|
||||
func state_input(event: InputEvent) -> void:
|
||||
if event.is_action_pressed("plr_crouch"):
|
||||
transition.emit("Crouch")
|
||||
|
||||
if event.is_action_pressed("plr_walk"):
|
||||
transition.emit("Walk")
|
||||
func on_jumped() -> void:
|
||||
if player.is_on_floor():
|
||||
player_movement.jump()
|
||||
transition.emit("Fall")
|
||||
|
||||
func begin_walk() -> void:
|
||||
transition.emit("Walk")
|
||||
|
||||
func begin_crouch() -> void:
|
||||
transition.emit("Crouch")
|
||||
|
|
|
|||
|
|
@ -6,21 +6,22 @@ extends State
|
|||
@export var JUMP_VELOCITY: float = 4.5
|
||||
@export var player: Player
|
||||
@export var player_movement: PlayerMovement
|
||||
@export var player_input: PlayerInput
|
||||
@export var weapon_system: WeaponSystem
|
||||
|
||||
func enter() -> void:
|
||||
pass
|
||||
player_input.crouch_begin.connect(begin_crouch)
|
||||
player_input.walk_end.connect(end_walk)
|
||||
player_input.jumped.connect(on_jumped)
|
||||
|
||||
func exit() -> void:
|
||||
pass
|
||||
player_input.crouch_begin.disconnect(begin_crouch)
|
||||
player_input.walk_end.disconnect(end_walk)
|
||||
player_input.jumped.disconnect(on_jumped)
|
||||
|
||||
func physics_update(delta: float) -> void:
|
||||
if not is_multiplayer_authority():
|
||||
return
|
||||
if Input.is_action_just_pressed("plr_jump") and player.is_on_floor():
|
||||
player.velocity.y = JUMP_VELOCITY
|
||||
transition.emit("Fall")
|
||||
return
|
||||
|
||||
if not player.is_on_floor():
|
||||
transition.emit("Fall")
|
||||
|
|
@ -28,9 +29,13 @@ func physics_update(delta: float) -> void:
|
|||
|
||||
player_movement.process_movement(max_speed * weapon_system.get_speed_modifier(),acceleration,deceleration,delta)
|
||||
|
||||
func state_input(event: InputEvent) -> void:
|
||||
if event.is_action_released("plr_walk"):
|
||||
transition.emit("Stand")
|
||||
|
||||
if event.is_action_pressed("plr_crouch"):
|
||||
transition.emit("Crouch")
|
||||
func on_jumped() -> void:
|
||||
if player.is_on_floor():
|
||||
player_movement.jump()
|
||||
transition.emit("Fall")
|
||||
|
||||
func end_walk() -> void:
|
||||
transition.emit("Stand")
|
||||
|
||||
func begin_crouch() -> void:
|
||||
transition.emit("Crouch")
|
||||
|
|
|
|||
|
|
@ -5,8 +5,5 @@ extends Node
|
|||
@export var blue_team_texture: Texture2D
|
||||
|
||||
func _ready() -> void:
|
||||
get_tree().create_timer(1).timeout.connect(on_player_spawned)
|
||||
|
||||
func on_player_spawned() -> void:
|
||||
if player.team == Session.TEAMS.DEFENCE:
|
||||
material.albedo_texture = blue_team_texture
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue