Files
sidescroller-project/sidescroller/scripts/playerfall.gd

66 lines
1.8 KiB
GDScript

extends State
class_name PlayerFall
var initgrav = 0
func get_state_name():
return str(self).split(":")[0]
func enter():
initgrav = player.grav
player.grav = player.fallgrav
func exit():
player.grav = initgrav
player.fallroll_timer = 0.0
player.fallroll_input_timer = 0.0
player.land_delay_timer = 0.0
player.can_fallroll = true
player.fallrolling = false
player.jump_buffered = false
func update(delta):
player.ap.play("fall")
player.coyote_timer += delta
fallrollcheck(delta)
player.jumpbuffer(delta)
if player.transitionledgegrab():
Transitioned.emit(self, "PlayerLedgeGrab")
if player.fallroll_timer <= player.fallroll_time or player.land_delay_timer >= player.land_delay_time:
if player.transitioncoyotejump() or player.transitionjump():
Transitioned.emit(self, "PlayerJump")
elif player.transitiondoublejump():
Transitioned.emit(self, "PlayerDoubleJump")
elif player.is_on_floor() and player.fallroll_timer >= player.fallroll_time and player.fallrolling:
print("fallroll")
Transitioned.emit(self, "PlayerFallRoll") #ersetzen durch state: PlayerFallRoll
elif player.transitionidle():
Transitioned.emit(self, "PlayerIdle")
elif player.transitionrun():
Transitioned.emit(self, "PlayerRun")
#elif player.transitiondash():
#Transitioned.emit(self, "PlayerDash")
func physics_update(delta):
pass
func fallrollcheck(delta):
player.fallroll_timer += delta
if Input.is_action_just_pressed("sprint") and player.can_fallroll:
player.fallrolling = true
player.can_fallroll = false
if player.fallrolling == true:
player.fallroll_input_timer += delta
if player.fallroll_input_timer >= player.fallroll_input_time:
player.fallrolling = false
if player.is_on_floor():
player.land_delay_timer += delta