Climb.gd 1.1 KB

12345678910111213141516171819202122232425262728293031323334
  1. extends PlayerState
  2. var climb_direction := 0
  3. var vine: Vine = null
  4. const CLIMB_SPEED := 50
  5. var cutscene := false
  6. var auto_climb := false
  7. func enter(msg := {}) -> void:
  8. vine = msg.get("Vine")
  9. cutscene = msg.has("Cutscene")
  10. func physics_update(_delta: float) -> void:
  11. player.velocity.x = 0
  12. if player.input_direction != 0 and climb_direction == 0 and not cutscene:
  13. player.direction = -player.input_direction
  14. player.sprite.scale.x = player.direction
  15. player.global_position.x = vine.global_position.x - (8 * player.direction)
  16. if not cutscene and not auto_climb:
  17. climb_direction = sign(Input.get_axis("move_up" + "_" + str(player.player_id),"move_down" + "_" + str(player.player_id)))
  18. if vine.can_tele and player.global_position.y - 64 < vine.top_point and climb_direction == -1:
  19. climb_direction = -1
  20. auto_climb = true
  21. player.velocity.y = CLIMB_SPEED * climb_direction
  22. player.sprite.play("Climb")
  23. player.sprite.speed_scale = abs(climb_direction * 1.5)
  24. player.move_and_slide()
  25. if Global.player_action_just_pressed("jump", player.player_id) and not cutscene:
  26. state_machine.transition_to("Normal")
  27. player.jump()