Files
2026-video-game-project/Entities/Player/player_state_scripts/air_movement/jump_state.gd

97 lines
2.4 KiB
GDScript

extends NodeState
@export var player: Player
@export var animatedSprite2D: AnimatedSprite2D
@export var wallCheck: ShapeCast2D
@export var floorCheck: RayCast2D
@export var ledgeGrabBox: CollisionShape2D
@export var fallState: NodeState
const jumpGravity = player.GRAVITY
@onready var jumpHight = player.jumpHight
@onready var maxJumpCount = player.maxJumpCount
@onready var speed = player.speed
@onready var maxSpeed = player.maxSpeed
@onready var friction = player.friction
var currentJumpCount: int = 0
@warning_ignore("unused_parameter")
func _physics_process(delta: float) -> void:
await player.move
if player.is_on_floor():
currentJumpCount = 0
@warning_ignore("unused_parameter")
func on_process(delta: float) -> void:
pass
func on_phyisics_process(delta: float) -> void:
player.velocity.y += jumpGravity * delta
if player.is_on_floor():
currentJumpCount = 0
player.velocity.y = jumpHight
fallState.coyoteJump = false
currentJumpCount += 1
if fallState.coyoteJump and currentJumpCount <= maxJumpCount:
player.velocity.y = jumpHight
fallState.coyoteJump = false
currentJumpCount += 1
#multi jumps
multiJump()
#movment shit under here
var direction: float = GameInputEvents.movement_input()
if direction:
player.velocity.x += direction * speed * delta
player.velocity.x = clamp(player.velocity.x, -maxSpeed, maxSpeed)
if direction != 0:
animatedSprite2D.flip_h = false if direction > 0 else true
if direction == 0:
player.velocity.x = move_toward(player.velocity.x, 0, friction * delta)
await player.move
transition_states()
func enter() -> void:
ledgeGrabBox.disabled = false
animatedSprite2D.play("Jump")
if not fallState.coyoteJump:
currentJumpCount += 1
multiJump()
func exit() -> void:
ledgeGrabBox.disabled = true
fallState.coyoteJump = false
animatedSprite2D.stop()
func transition_states() -> void:
#transition states
#idle state
if player.is_on_floor():
transition.emit("idle")
#fall state
if player.velocity.y > 0:
transition.emit("fall")
if wallCheck.is_colliding() and not floorCheck.is_colliding() and player.velocity.y == 0 and player.is_on_floor():
transition.emit("Grab")
if GameInputEvents.dash_input() and player.canDash:
transition.emit("dash")
func multiJump():
if !player.is_on_floor() and currentJumpCount <= maxJumpCount and Input.is_action_just_pressed("move_jump"):
player.velocity.y = jumpHight
currentJumpCount += 1