Tales-of-PKMN/game/player/states/player_state.gd
TheThomaas 250976d170 Squashed commit of the following:
commit 8e7da96bfcd52b230feaf40fbc6d4a42b80c5723
Author: TheThomaas <thethomaas@protonmail.ch>
Date:   Sat Oct 17 18:55:14 2026 +0200

    Make state machine more reusable

commit 37da7248b8c33ce95cff7ef9332c5ccf6e3cd418
Author: TheThomaas <thethomaas@protonmail.ch>
Date:   Sat Oct 17 18:44:34 2026 +0200

    Change aim state into flag

commit fbb3a84a12e2cabff9b36390da7483b8de7e9379
Author: TheThomaas <thethomaas@protonmail.ch>
Date:   Sat Oct 17 18:33:08 2026 +0200

    Replace fixed references with ui references

commit 913955b13e9980780ac88761845d9e1f165f0d0e
Author: TheThomaas <thethomaas@protonmail.ch>
Date:   Fri Oct 16 13:32:21 2026 +0200

    Update camera action handling

commit 4ce0ac13ffea473cf62c2fefd1571e9df1fbbcaa
Author: TheThomaas <thethomaas@protonmail.ch>
Date:   Fri Oct 16 13:04:39 2026 +0200

    Update mounting system

commit e410eca38760955b2866eecd6ac0281e2041e76d
Author: TheThomaas <thethomaas@protonmail.ch>
Date:   Fri Oct 16 12:57:25 2026 +0200

    Update aiming system

commit 4c788df485ccbff5f91fd51d9f480e495f11da5f
Author: TheThomaas <thethomaas@protonmail.ch>
Date:   Thu Oct 15 21:50:26 2026 +0200

    Centralize states names into constants

commit 6059479c87d749e986a48adb520ef33121104da5
Author: TheThomaas <thethomaas@protonmail.ch>
Date:   Thu Oct 15 21:25:32 2026 +0200

    Refator Crouch state into flag

commit 08faec70e770042d36eed6f173a63f3aac1f67c6
Author: TheThomaas <thethomaas@protonmail.ch>
Date:   Wed Oct 14 10:19:35 2026 +0200

    Update player input management and state machine

commit 11a0aecc58c50c5862a03b4fd0b55e8db024031f
Author: TheThomaas <thethomaas@protonmail.ch>
Date:   Wed Oct 14 10:17:06 2026 +0200

    Delete charizard.tres

commit 399eac2b6c64f242a1c2e12360d811127f87681c
Author: TheThomaas <thethomaas@protonmail.ch>
Date:   Tue Oct 13 18:20:45 2026 +0200

    Remove unused MountedState

commit 42a3668c52fe96a7509a74290a94fc5a8084b713
Author: TheThomaas <thethomaas@protonmail.ch>
Date:   Tue Oct 13 18:18:08 2026 +0200

    Group grounded states under common class
2026-10-17 18:56:13 +02:00

49 lines
2.1 KiB
GDScript

extends State
class_name PlayerState
#etat du joueur : ajoute a State le PlayerCharacter, l'input, les hints du HUD et les helpers de mouvement.
#les hints sont publiees par StateHints (un composant du joueur) : la StateMachine n'en sait rien.
signal hints_changed #a emettre quand get_hints() change alors que l'etat est actif
@export var hints : Array[Hint] = [] #cas simple : se regle dans l'inspecteur
@export var keep_previous_hints : bool = false #etats transitoires (Dodge...) : on ne touche pas aux hints affiches
var player : PlayerCharacter #renseigne par enter() : les etats n'ont plus besoin de le stocker eux-memes
var input : InputManagementComponent #lecture de l'input du joueur (raccourci vers player.player_input)
func enter(new_actor : Node) -> void:
player = new_actor as PlayerCharacter
input = player.player_input
super(new_actor)
func get_hints() -> Array[Hint]:
return hints #a surcharger seulement quand les hints dependent d'une condition
#---------- transitions du joueur ----------
func fall() -> bool:
#quitter le sol : la posture accroupie est annulee (on retombe debout), puis passage en InairState
player.is_crouching = false
return request_transition(States.INAIR)
func request_locomotion() -> bool:
#vers Walk ou Run, selon la derniere allure choisie (player.locomotion)
return request_transition(player.get_locomotion_state())
func request_ground_state(moving : bool) -> bool:
#retour au sol : Idle si le joueur est immobile, sinon Walk ou Run selon la derniere allure
return request_locomotion() if moving else request_transition(States.IDLE)
#---------- helpers de mouvement ----------
func accelerate(target_speed : float, accel : float, delta : float) -> void:
#vers la vitesse voulue dans la direction de move_dir
player.velocity.x = lerpf(player.velocity.x, player.move_dir.x * target_speed, accel * delta)
player.velocity.z = lerpf(player.velocity.z, player.move_dir.y * target_speed, accel * delta)
func slow_down(delta : float) -> void:
player.velocity.x = lerpf(player.velocity.x, 0.0, player.move_deccel * delta)
player.velocity.z = lerpf(player.velocity.z, 0.0, player.move_deccel * delta)