Bumper.gd 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. extends Node2D
  2. const LOW_STRENGTH := -300
  3. const HIGH_STRENGTH := -450
  4. func bounce_player(player: Player) -> void:
  5. $Sprite.play("Bounce")
  6. $AnimationPlayer.stop()
  7. if player.global_position.y + 8 < global_position.y:
  8. player.velocity.x *= 0.8
  9. if Global.player_action_pressed("jump", player.player_id):
  10. player.gravity = player.JUMP_GRAVITY
  11. player.jump_cancelled = false
  12. player.velocity.y = HIGH_STRENGTH
  13. player.has_jumped = true
  14. AudioManager.play_sfx("bumper_high", global_position)
  15. else:
  16. AudioManager.play_sfx("bumper", global_position)
  17. player.velocity.y = LOW_STRENGTH
  18. else:
  19. player.velocity = global_position.direction_to(player.global_position) * 200
  20. if Global.player_action_pressed("jump", player.player_id):
  21. player.gravity = player.JUMP_GRAVITY
  22. player.velocity.y = LOW_STRENGTH
  23. player.has_jumped = true
  24. AudioManager.play_sfx("bumper_high", global_position)
  25. else:
  26. AudioManager.play_sfx("bumper", global_position)
  27. refresh_hitbox()
  28. $AnimationPlayer.play("Bounce")
  29. await $AnimationPlayer.animation_finished
  30. $Sprite.play("Idle")
  31. func refresh_hitbox() -> void:
  32. $Hitbox/CollisionShape2D.set_deferred("disabled", true)
  33. await get_tree().physics_frame
  34. $Hitbox/CollisionShape2D.set_deferred("disabled", false)