Round system
This commit is contained in:
parent
bcb42f8d16
commit
3df8247a84
32 changed files with 573 additions and 123 deletions
36
scripts/player/dead_player_spectator.gd
Normal file
36
scripts/player/dead_player_spectator.gd
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
extends Camera3D
|
||||
|
||||
@export var SENSITIVITY = 0.02
|
||||
@export var SPEED = 10.0
|
||||
|
||||
var active: bool
|
||||
|
||||
func _ready() -> void:
|
||||
if not is_multiplayer_authority():
|
||||
return
|
||||
|
||||
func set_active() -> void:
|
||||
if not is_multiplayer_authority():
|
||||
return
|
||||
active = true
|
||||
current = true
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
if active == false or not is_multiplayer_authority():
|
||||
return
|
||||
var xz_plane = Input.get_vector("plr_strafe_l","plr_strafe_r","plr_forward","plr_back")
|
||||
var y = Input.get_axis("spc_down","spc_up")
|
||||
|
||||
var direction = Vector3(xz_plane.x,y,xz_plane.y)
|
||||
global_position += global_basis * direction * SPEED * delta
|
||||
|
||||
func rotate_camera(x,y) -> void:
|
||||
rotate_y(x)
|
||||
rotation.x = clamp(rotation.x + y,-PI/2,PI/2)
|
||||
orthonormalize()
|
||||
|
||||
func _input(event: InputEvent) -> void:
|
||||
if active == false or not is_multiplayer_authority():
|
||||
return
|
||||
if event is InputEventMouseMotion:
|
||||
rotate_camera(-event.relative.x * SENSITIVITY,-event.relative.y * SENSITIVITY)
|
||||
1
scripts/player/dead_player_spectator.gd.uid
Normal file
1
scripts/player/dead_player_spectator.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://bl8gfrrc512q2
|
||||
|
|
@ -7,6 +7,7 @@ class_name Player
|
|||
|
||||
signal spawned
|
||||
signal health_changed(to: int)
|
||||
signal died
|
||||
|
||||
const MAX_HP = 100
|
||||
|
||||
|
|
@ -23,8 +24,6 @@ const MAX_HP = 100
|
|||
get:
|
||||
return hp
|
||||
|
||||
var TEMP_start_pos
|
||||
|
||||
func _enter_tree() -> void:
|
||||
set_multiplayer_authority(str(name).to_int())
|
||||
|
||||
|
|
@ -37,9 +36,8 @@ func _physics_process(_delta: float) -> void:
|
|||
func die() -> void:
|
||||
if (not is_multiplayer_authority()):
|
||||
return
|
||||
|
||||
global_position = TEMP_start_pos
|
||||
hp = MAX_HP
|
||||
Session.add_dead.rpc(team)
|
||||
died.emit()
|
||||
|
||||
@rpc("any_peer","call_local","reliable")
|
||||
func kill_request() -> void:
|
||||
|
|
@ -51,7 +49,6 @@ func kill_request() -> void:
|
|||
@rpc("any_peer","call_local","reliable")
|
||||
func set_after_spawn(start_position: Vector3,new_team: int):
|
||||
global_position = start_position
|
||||
TEMP_start_pos = global_position
|
||||
team = new_team as Session.TEAMS
|
||||
spawned.emit()
|
||||
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ class_name PlayerCamera
|
|||
var vertical_compensation : float
|
||||
var compensation_tween: Tween
|
||||
var compensate: bool = false
|
||||
var disable: bool = false
|
||||
var compensation_speed: float
|
||||
@export var compensation_time: float = 1.0
|
||||
@export var compensation_delay: float = 0.5
|
||||
|
|
@ -20,6 +21,7 @@ func _ready() -> void:
|
|||
current = true
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
if disable: return
|
||||
if compensate:
|
||||
if abs(vertical_compensation) <= 0.001:
|
||||
vertical_compensation = 0
|
||||
|
|
@ -28,7 +30,7 @@ func _process(delta: float) -> void:
|
|||
rotate_camera(0,compensation_speed * delta)
|
||||
|
||||
func _input(event: InputEvent) -> void:
|
||||
if not is_multiplayer_authority():
|
||||
if not is_multiplayer_authority() or disable:
|
||||
return
|
||||
if event is InputEventMouseMotion:
|
||||
rotate_camera(-event.relative.x * SENSITIVITY,-event.relative.y * SENSITIVITY)
|
||||
|
|
|
|||
21
scripts/player/player_movement.gd
Normal file
21
scripts/player/player_movement.gd
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
extends Node
|
||||
|
||||
class_name PlayerMovement
|
||||
|
||||
@export var player: Player
|
||||
|
||||
func process_movement(max_speed: float,acceleration: float,deceleration: float,delta: float) -> void:
|
||||
if is_multiplayer_authority() == false:
|
||||
return
|
||||
if Session.round_state == Session.ROUND_STATES.BUY:
|
||||
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 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))
|
||||
player.velocity.z = clamp(player.velocity.z + direction.z * acceleration * delta,-max_speed*abs(direction.z),max_speed*abs(direction.z))
|
||||
else:
|
||||
player.velocity.x = move_toward(player.velocity.x, 0, deceleration*delta)
|
||||
player.velocity.z = move_toward(player.velocity.z, 0, deceleration*delta)
|
||||
1
scripts/player/player_movement.gd.uid
Normal file
1
scripts/player/player_movement.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://bs4y647h5rdfr
|
||||
|
|
@ -14,6 +14,8 @@ func _ready() -> void:
|
|||
current = true
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
if not is_multiplayer_authority():
|
||||
return
|
||||
var xz_plane = Input.get_vector("plr_strafe_l","plr_strafe_r","plr_forward","plr_back")
|
||||
var y = Input.get_axis("spc_down","spc_up")
|
||||
|
||||
|
|
@ -26,6 +28,8 @@ func rotate_camera(x,y) -> void:
|
|||
orthonormalize()
|
||||
|
||||
func _input(event: InputEvent) -> void:
|
||||
if not is_multiplayer_authority():
|
||||
return
|
||||
if event is InputEventMouseMotion:
|
||||
rotate_camera(-event.relative.x * SENSITIVITY,-event.relative.y * SENSITIVITY)
|
||||
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ extends State
|
|||
@export var toggle: bool = false
|
||||
@export var stand_up_area: Area3D
|
||||
@export var player: Player
|
||||
@export var player_movement: PlayerMovement
|
||||
@export var animation_player: AnimationPlayer
|
||||
@export var crouch_time: float = 0.1
|
||||
@export var weapon_system: WeaponSystem
|
||||
|
|
@ -28,15 +29,7 @@ func physics_update(delta: float) -> void:
|
|||
transition.emit("Fall")
|
||||
return
|
||||
|
||||
var input_dir := Input.get_vector("plr_strafe_r","plr_strafe_l", "plr_back","plr_forward")
|
||||
var direction := (player.transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized()
|
||||
var modified_max_speed = max_speed * weapon_system.get_speed_modifier()
|
||||
if direction:
|
||||
player.velocity.x = clamp(player.velocity.x + direction.x * acceleration * delta,-modified_max_speed*abs(direction.x),modified_max_speed*abs(direction.x))
|
||||
player.velocity.z = clamp(player.velocity.z + direction.z * acceleration * delta,-modified_max_speed*abs(direction.z),modified_max_speed*abs(direction.z))
|
||||
else:
|
||||
player.velocity.x = move_toward(player.velocity.x, 0, deceleration*delta)
|
||||
player.velocity.z = move_toward(player.velocity.z, 0, deceleration*delta)
|
||||
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")):
|
||||
|
|
|
|||
12
scripts/player/states/death.gd
Normal file
12
scripts/player/states/death.gd
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
extends State
|
||||
|
||||
@export var animation_player: AnimationPlayer
|
||||
|
||||
func on_death() -> void:
|
||||
transition.emit("Death")
|
||||
|
||||
func enter() -> void:
|
||||
animation_player.play("die")
|
||||
|
||||
func exit() -> void:
|
||||
pass
|
||||
1
scripts/player/states/death.gd.uid
Normal file
1
scripts/player/states/death.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://tb140f8fweug
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
extends State
|
||||
|
||||
@export var player: Player
|
||||
@export var player_movement: PlayerMovement
|
||||
@export var max_speed: float = 5.0
|
||||
@export var acceleration: float
|
||||
@export var weapon_system: WeaponSystem
|
||||
|
|
@ -20,11 +21,4 @@ func physics_update(delta: float) -> void:
|
|||
|
||||
player.velocity += player.get_gravity() * delta
|
||||
|
||||
var input_dir := Input.get_vector("plr_strafe_r","plr_strafe_l", "plr_back","plr_forward")
|
||||
var direction := (player.transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized()
|
||||
var modified_max_speed = max_speed * weapon_system.get_speed_modifier()
|
||||
if direction:
|
||||
if abs(player.velocity.x + direction.x * acceleration * delta) < abs(modified_max_speed * direction.x):
|
||||
player.velocity.x += direction.x * acceleration * delta
|
||||
if abs(player.velocity.z + direction.z * acceleration * delta) < abs(modified_max_speed * direction.z):
|
||||
player.velocity.z += direction.z * acceleration * delta
|
||||
player_movement.process_movement(max_speed * weapon_system.get_speed_modifier(),acceleration,0,delta)
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ extends State
|
|||
@export var deceleration: float = 200.0
|
||||
@export var JUMP_VELOCITY: float = 4.5
|
||||
@export var player: Player
|
||||
@export var player_movement: PlayerMovement
|
||||
@export var weapon_system: WeaponSystem
|
||||
|
||||
func enter() -> void:
|
||||
|
|
@ -17,7 +18,7 @@ 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
|
||||
player.velocity.y = JUMP_VELOCITY * sign(weapon_system.get_speed_modifier())
|
||||
transition.emit("Fall")
|
||||
return
|
||||
|
||||
|
|
@ -25,15 +26,7 @@ func physics_update(delta: float) -> void:
|
|||
transition.emit("Fall")
|
||||
return
|
||||
|
||||
var input_dir := Input.get_vector("plr_strafe_r","plr_strafe_l", "plr_back","plr_forward")
|
||||
var direction := (player.transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized()
|
||||
var modified_max_speed = max_speed * weapon_system.get_speed_modifier()
|
||||
if direction:
|
||||
player.velocity.x = clamp(player.velocity.x + direction.x * acceleration * delta,-modified_max_speed*abs(direction.x),modified_max_speed*abs(direction.x))
|
||||
player.velocity.z = clamp(player.velocity.z + direction.z * acceleration * delta,-modified_max_speed*abs(direction.z),modified_max_speed*abs(direction.z))
|
||||
else:
|
||||
player.velocity.x = move_toward(player.velocity.x, 0, deceleration*delta)
|
||||
player.velocity.z = move_toward(player.velocity.z, 0, deceleration*delta)
|
||||
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"):
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ extends State
|
|||
@export var deceleration: float = 100.0
|
||||
@export var JUMP_VELOCITY: float = 4.5
|
||||
@export var player: Player
|
||||
@export var player_movement: PlayerMovement
|
||||
@export var weapon_system: WeaponSystem
|
||||
|
||||
func enter() -> void:
|
||||
|
|
@ -25,15 +26,7 @@ func physics_update(delta: float) -> void:
|
|||
transition.emit("Fall")
|
||||
return
|
||||
|
||||
var input_dir := Input.get_vector("plr_strafe_r","plr_strafe_l", "plr_back","plr_forward")
|
||||
var direction := (player.transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized()
|
||||
var modified_max_speed = max_speed * weapon_system.get_speed_modifier()
|
||||
if direction:
|
||||
player.velocity.x = clamp(player.velocity.x + direction.x * acceleration * delta,-modified_max_speed*abs(direction.x),modified_max_speed*abs(direction.x))
|
||||
player.velocity.z = clamp(player.velocity.z + direction.z * acceleration * delta,-modified_max_speed*abs(direction.z),modified_max_speed*abs(direction.z))
|
||||
else:
|
||||
player.velocity.x = move_toward(player.velocity.x, 0, deceleration*delta)
|
||||
player.velocity.z = move_toward(player.velocity.z, 0, deceleration*delta)
|
||||
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"):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue