Initial: playable 3-level Breakout with menus, audio, and power-ups

This commit is contained in:
2026-08-12 17:27:11 +08:00
commit 319e75447a
45 changed files with 1594 additions and 0 deletions
View File
+36
View File
@@ -0,0 +1,36 @@
extends CanvasLayer
## HUD:分数、生命(图标)、提示。接 Main 的方法直接更新。
## 命数图标用 ColorRect 排一排,比纯数字直观。
const LIFE_ICON_SIZE: Vector2 = Vector2(24, 8)
const LIFE_ICON_SPACING: float = 4.0
const LIFE_ICON_COLOR: Color = Color(0.4, 0.6, 1.0)
@onready var score_label: Label = $ScoreLabel
@onready var lives_label: Label = $LivesLabel
@onready var message_label: Label = $MessageLabel
@onready var lives_container: HBoxContainer = $LivesContainer
func _ready() -> void:
show_message("按 空格 发球")
func update_score(score: int) -> void:
score_label.text = "Score: %d" % score
func update_lives(lives: int) -> void:
lives_label.text = "Lives: %d" % lives
_refresh_life_icons(lives)
func show_message(text: String) -> void:
message_label.text = text
func _refresh_life_icons(lives: int) -> void:
# 清空旧图标
for child in lives_container.get_children():
child.queue_free()
# 重新生成 lives 个
for i in range(lives):
var icon := ColorRect.new()
icon.custom_minimum_size = LIFE_ICON_SIZE
icon.color = LIFE_ICON_COLOR
lives_container.add_child(icon)
+1
View File
@@ -0,0 +1 @@
uid://omfhu2gxpqt5
+12
View File
@@ -0,0 +1,12 @@
extends Control
## 主菜单:开始 / 退出。
## 按钮点击通过 signal 调用父节点(main.gd)的方法。
signal start_pressed
signal quit_pressed
func _on_start_pressed() -> void:
start_pressed.emit()
func _on_quit_pressed() -> void:
quit_pressed.emit()
+1
View File
@@ -0,0 +1 @@
uid://b8edba73ci6yf