DiscoBg.gd 971 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. extends Parallax2D
  2. var level_bpm := 120
  3. @export var level := 0.5
  4. var is_star := false
  5. var beats := -1
  6. var tween: Tween = null
  7. func _ready() -> void:
  8. modulate.a = 0
  9. AudioManager.music_beat.connect(on_timeout)
  10. on_timeout()
  11. func _physics_process(delta: float) -> void:
  12. scroll_offset.y = lerpf(scroll_offset.y, lerpf(128, 0, level), delta * 5)
  13. modulate.a = lerpf(modulate.a, lerpf(0, 1, level), delta * 5)
  14. $TextureRect.position.y = move_toward($TextureRect.position.y, -64, delta * (level_bpm / 10))
  15. func on_timeout(idx := 0) -> void:
  16. beats = idx
  17. if is_star == false:
  18. tween_back()
  19. if beats % 4 == 0:
  20. $AudioStreamPlayer.pitch_scale = 2
  21. else:
  22. $AudioStreamPlayer.pitch_scale = 1
  23. $AudioStreamPlayer.play()
  24. func tween_back() -> void:
  25. if tween != null:
  26. tween.kill()
  27. tween = create_tween().set_trans(Tween.TRANS_CUBIC)
  28. tween.tween_property($TextureRect, "position:y", -160, 0.05)
  29. func on_starttimeout() -> void:
  30. if is_star:
  31. tween_back()