Files
sijcdu 7c78a088a0 Add diamond collection and a level-clear door
The three diamonds and both doors were painted as tiles in TerrainBase, which cannot act as pickups or triggers. Replaced them with real prefabs that reuse the same atlas tiles (diamond = (7,3), doors = (10,6) and (11,5)) and erase their placeholder tile on ready. Collecting all three diamonds unlocks the door; touching it fades to black, pauses the tree and shows the level-clear screen with a next-level button (currently reloads the level, as there is only one). HUD now shows the diamond count.
2026-10-07 21:04:58 +08:00

54 lines
1.7 KiB
GDScript

extends CanvasLayer
## 左上角的状态显示:3 颗心 + 回血道具数量 + 钻石数量 + 护盾剩余时间。
## 每帧从场景里找带 "player" 组的玩家读取状态。
@export var full_heart_texture: Texture2D
@export var empty_heart_texture: Texture2D
var _player: Node = null
var _hearts: Array = []
var _count_label: Label = null
var _diamond_label: Label = null
var _shield_label: Label = null
func _ready() -> void:
for i in range(1, 4):
var heart := get_node_or_null("Heart%d" % i)
if heart != null:
_hearts.append(heart)
_count_label = get_node_or_null("CountLabel")
_diamond_label = get_node_or_null("DiamondLabel")
_shield_label = get_node_or_null("ShieldLabel")
func _process(_delta: float) -> void:
if _player == null or not is_instance_valid(_player):
_player = get_tree().get_first_node_in_group("player")
if _player == null:
return
var health: int = int(_player.health)
for i in _hearts.size():
var heart: TextureRect = _hearts[i]
heart.texture = full_heart_texture if i < health else empty_heart_texture
var items: int = int(_player.heal_items)
if _count_label != null:
_count_label.text = "x%d" % items
_count_label.modulate = Color.WHITE if items > 0 else Color(1.0, 1.0, 1.0, 0.4)
if _diamond_label != null:
var got: int = int(_player.diamonds)
var total: int = maxi(int(_player.diamond_total), got)
_diamond_label.text = "%d / %d" % [got, total]
if total > 0 and got >= total:
_diamond_label.modulate = Color(1.0, 0.9, 0.35)
else:
_diamond_label.modulate = Color.WHITE
if _shield_label != null:
var shield: float = float(_player.shield_left)
_shield_label.text = ("SHIELD %.1fs" % shield) if shield > 0.0 else ""