Global refactor
This commit is contained in:
parent
3868af29e3
commit
0589ca4e23
180 changed files with 249 additions and 401 deletions
36
systems/player/states/crouching.gd
Normal file
36
systems/player/states/crouching.gd
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
extends State
|
||||
|
||||
@export var max_speed: float = 2.5
|
||||
@export var acceleration: float = 1.0
|
||||
@export var deceleration: float = 100.0
|
||||
|
||||
@export var toggle: bool = false
|
||||
@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 not player.is_on_floor():
|
||||
transition.emit("Fall")
|
||||
return
|
||||
|
||||
player_movement.process_movement(max_speed * weapon_system.get_speed_modifier(),acceleration,deceleration,delta)
|
||||
|
||||
func try_end_crouch() -> void:
|
||||
if player.is_on_floor() and stand_up_area.has_overlapping_bodies() == false:
|
||||
transition.emit("Stand")
|
||||
1
systems/player/states/crouching.gd.uid
Normal file
1
systems/player/states/crouching.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://bv8sgx78s8hwn
|
||||
12
systems/player/states/death.gd
Normal file
12
systems/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
systems/player/states/death.gd.uid
Normal file
1
systems/player/states/death.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://tb140f8fweug
|
||||
32
systems/player/states/falling.gd
Normal file
32
systems/player/states/falling.gd
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
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
|
||||
@export var land_sound: MultiplayerAudio3D
|
||||
|
||||
func enter() -> void:
|
||||
pass
|
||||
|
||||
func exit() -> void:
|
||||
pass
|
||||
|
||||
|
||||
func physics_update(delta: float) -> void:
|
||||
if not is_multiplayer_authority():
|
||||
return
|
||||
if player.is_on_floor():
|
||||
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
|
||||
|
||||
player_movement.process_movement(max_speed * weapon_system.get_speed_modifier(),acceleration,0,delta)
|
||||
1
systems/player/states/falling.gd.uid
Normal file
1
systems/player/states/falling.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://cq4i0afwesdm3
|
||||
51
systems/player/states/standing.gd
Normal file
51
systems/player/states/standing.gd
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
extends State
|
||||
|
||||
@export var max_speed: float = 5.0
|
||||
@export var acceleration: float = 2.0
|
||||
@export var deceleration: float = 200.0
|
||||
@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
|
||||
@export var step_speed_curve: Curve
|
||||
|
||||
var step_time: float
|
||||
|
||||
func enter() -> void:
|
||||
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 not player.is_on_floor():
|
||||
transition.emit("Fall")
|
||||
return
|
||||
|
||||
step_time += delta * step_speed_curve.sample((player.velocity * Vector3(1,0,1)).length_squared()/(max_speed*max_speed))
|
||||
if step_time >= step_delay:
|
||||
step_time = 0
|
||||
audio.multiplayer_play()
|
||||
|
||||
player_movement.process_movement(max_speed * weapon_system.get_speed_modifier(),acceleration,deceleration,delta)
|
||||
|
||||
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")
|
||||
1
systems/player/states/standing.gd.uid
Normal file
1
systems/player/states/standing.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://u0e2b2mvij1k
|
||||
41
systems/player/states/walk.gd
Normal file
41
systems/player/states/walk.gd
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
extends State
|
||||
|
||||
@export var max_speed: float = 2.5
|
||||
@export var acceleration: float = 1.0
|
||||
@export var deceleration: float = 100.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
|
||||
|
||||
func enter() -> void:
|
||||
player_input.crouch_begin.connect(begin_crouch)
|
||||
player_input.walk_end.connect(end_walk)
|
||||
player_input.jumped.connect(on_jumped)
|
||||
|
||||
func exit() -> void:
|
||||
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 not player.is_on_floor():
|
||||
transition.emit("Fall")
|
||||
return
|
||||
|
||||
player_movement.process_movement(max_speed * weapon_system.get_speed_modifier(),acceleration,deceleration,delta)
|
||||
|
||||
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")
|
||||
1
systems/player/states/walk.gd.uid
Normal file
1
systems/player/states/walk.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://cwasvwhm5yg0o
|
||||
Loading…
Add table
Add a link
Reference in a new issue