RopeElevatorPlatform.gd 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. class_name RopeElevatorPlatform
  2. extends Node2D
  3. @export var linked_platform: Node2D = null
  4. @onready var platform: AnimatableBody2D = $Platform
  5. @onready var player_detection: Area2D = $Platform/PlayerDetection
  6. @export var rope_top := -160
  7. var velocity := 0.0
  8. var dropped := false
  9. var player_stood_on := false
  10. var sample_colour: Texture = null
  11. func _ready() -> void:
  12. $Platform/ScoreNoteSpawner.owner = $Platform
  13. func _process(_delta: float) -> void:
  14. if not dropped:
  15. $Rope.size.y = platform.global_position.y - rope_top
  16. $Rope.global_position.y = rope_top
  17. func _physics_process(delta: float) -> void:
  18. player_stood_on = player_detection.get_overlapping_areas().any(is_player)
  19. if dropped:
  20. velocity += (5 / delta) * delta
  21. platform.position.y += velocity * delta
  22. return
  23. else:
  24. if platform.global_position.y <= rope_top or linked_platform.dropped:
  25. dropped = true
  26. if linked_platform.dropped:
  27. if Settings.file.audio.extra_sfx == 1:
  28. AudioManager.play_sfx("lift_fall", global_position)
  29. $Platform/ScoreNoteSpawner.spawn_note(1000)
  30. if player_stood_on:
  31. velocity += (2 / delta) * delta
  32. else:
  33. velocity = lerpf(velocity, 0, delta * 2)
  34. linked_platform.velocity = -velocity
  35. platform.position.y += velocity * delta
  36. func is_player(area: Area2D) -> bool:
  37. if area.owner is Player:
  38. return area.owner.is_on_floor()
  39. return false