Loading...
Loading...
Build a coin pickup system with rotation animation, sound effects, and counter display.
Create a Coin scene. Add Area2D as root node (for detection). Add Sprite2D child with coin texture. Add CollisionShape2D with circle shape matching the coin. Add AudioStreamPlayer for pickup sound. Add a Rotation animation or animate in code.
Create Coin.gd script. Add animation in `_process(delta)`: `rotate(speed * delta)` where speed = 2.0 for gentle rotation. Add pickup detection: `func _on_body_entered(body): if body.name == 'Player': collect()`. Connect the Area2D's body_entered signal to this function.
Implement collect function: `func collect():`, `$AudioStreamPlayer.play()` (play sound), `queue_free()` (remove coin from scene), `body.add_coin()` (tell player they got a coin). Add visual feedback before disappearing: create a tween to scale down: `var tween = create_tween(); tween.tween_property($Sprite2D, 'scale', Vector2.ZERO, 0.2)`.
Create coin counter in HUD. Add a Label in your HUD scene: `@onready var coin_label = $CoinLabel`. Create a GameManager autoload or use player signal: `signal coins_collected(total)`. In player script: `var coins = 0`, `func add_coin(): coins += 1`, `coins_collected.emit(coins)`. Connect this to HUD: `player.coins_collected.connect(_on_coins_collected)`.
Update coin display: In HUD: `func _on_coins_collected(total): coin_label.text = 'Coins: ' + str(total) + '/20'` (if you have 20 total coins). Add animation when coin is collected: create a tween to briefly scale up the label, then back to normal. Save coin count to your save system for persistence.