Trampoline.gd 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. extends AnimatableBody2D
  2. @export var bounce_height := -500
  3. var players := []
  4. func on_area_entered(area: Area2D) -> void:
  5. pass
  6. func _physics_process(_delta: float) -> void:
  7. for i in $Hitbox.get_overlapping_areas():
  8. if i.owner is Player and i.owner.is_on_floor():
  9. if i.owner.spring_bouncing or i.owner.velocity.y < 0:
  10. continue
  11. i.owner.velocity.x = 0
  12. if players.has(i.owner) == false:
  13. players.append(i.owner)
  14. $Animation.play("Bounce")
  15. i.owner.spring_bouncing = true
  16. for i in players:
  17. i.global_position.y = $PlayerCollision/PlayerJoint.global_position.y
  18. func bounce_players() -> void:
  19. var high_bounce := false
  20. for player in players:
  21. if Global.player_action_pressed("jump", player.player_id):
  22. high_bounce = true
  23. player.velocity.y = bounce_height
  24. player.gravity = player.JUMP_GRAVITY
  25. player.has_jumped = true
  26. else:
  27. player.velocity.y = -300
  28. if high_bounce:
  29. AudioManager.play_sfx("spring", global_position)
  30. else:
  31. AudioManager.play_sfx("bump", global_position)
  32. players.clear()
  33. func on_area_exited(area: Area2D) -> void:
  34. if area.owner is Player:
  35. area.owner.spring_bouncing = false