9dffacd938
Player: move/jump (Space), test flight (F, debug builds only). Key: pickup, hold S to aim with live trajectory preview, release to throw, W to warp to the thrown key. Spring bounce. Spikes deal damage. 3-heart health, Z consumes a heal item for +1 heart and a 5s shield. HUD with hearts and item count. Death screen with fade-to-black and restart. Hidden passages. Assets: Kenney Pixel Platformer (CC0).
46 lines
1.3 KiB
GDScript
46 lines
1.3 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 _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")
|
|
_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 _shield_label != null:
|
|
var shield: float = float(_player.shield_left)
|
|
if shield > 0.0:
|
|
_shield_label.text = "SHIELD %.1fs" % shield
|
|
else:
|
|
_shield_label.text = ""
|