2024-12-12 17:48:21 -07:00
|
|
|
class_name Item extends Node3D
|
|
|
|
## Base class for item pick-ups in the world.
|
|
|
|
|
|
|
|
signal on_collect(player: WorldPlayer)
|
|
|
|
|
|
|
|
@onready var explosion_player: AnimationPlayer = %ExplosionPlayer
|
|
|
|
|
|
|
|
|
2024-12-13 12:06:41 -07:00
|
|
|
func collect(player: WorldPlayer) -> void:
|
2024-12-12 17:48:21 -07:00
|
|
|
# Note that this animation will call `queue_free` in 5 seconds!
|
|
|
|
explosion_player.play("explode")
|
2024-12-13 12:06:41 -07:00
|
|
|
_collect(player)
|
2024-12-12 17:48:21 -07:00
|
|
|
on_collect.emit(player)
|
|
|
|
|
|
|
|
|
2024-12-13 12:06:41 -07:00
|
|
|
func _collect(_player: WorldPlayer) -> void:
|
|
|
|
pass # Defined in derived type
|
|
|
|
|
|
|
|
|
2024-12-12 17:48:21 -07:00
|
|
|
func _on_collection_area_body_entered(body: Node3D) -> void:
|
|
|
|
if body is GameBall:
|
|
|
|
var ball: GameBall = body
|
|
|
|
if ball.player:
|
2024-12-13 12:06:41 -07:00
|
|
|
collect(ball.player)
|