1
0

power_up.gd 750 B

12345678910111213141516171819202122232425262728293031323334
  1. class_name PowerUp
  2. extends RigidBody2D
  3. ## A small dot that falls from the top. Catch it with the paddle to collect it.
  4. signal collected(power_up: PowerUp)
  5. enum Kind { SAVE, TRIPLE_BALLS, PADDLE, SUPERBALL }
  6. const RADIUS := 5.0
  7. const COLORS := {
  8. Kind.SAVE: Params.COLOR_GREEN,
  9. Kind.TRIPLE_BALLS: Params.COLOR_PINK,
  10. Kind.PADDLE: Params.COLOR_BLUE,
  11. Kind.SUPERBALL: Params.COLOR_ORANGE,
  12. }
  13. var kind := Kind.SAVE
  14. func _ready() -> void:
  15. add_to_group("power_ups")
  16. body_entered.connect(_on_body_entered)
  17. func _on_body_entered(body: Node) -> void:
  18. if body is Paddle:
  19. collected.emit(self)
  20. queue_free()
  21. elif body.is_in_group("bottom"):
  22. queue_free()
  23. func _draw() -> void:
  24. draw_circle(Vector2.ZERO, RADIUS, COLORS[kind], true, -1.0, true)