Skip to content

Commit a15a7b8

Browse files
committed
🧑‍💻 格式化代码
1 parent e123e6f commit a15a7b8

File tree

5 files changed

+30
-31
lines changed

5 files changed

+30
-31
lines changed

assets/fonts/unifont-16.0.02.otf.import

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ dest_files=["res://.godot/imported/unifont-16.0.02.otf-8ce69509e9a62ece8be3b25b5
1515
Rendering=null
1616
antialiasing=1
1717
generate_mipmaps=false
18+
disable_embedded_bitmaps=true
1819
multichannel_signed_distance_field=false
1920
msdf_pixel_range=8
2021
msdf_size=48

scripts/ball.gd

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
extends Node2D
22

33
# 定义一个自定义信号,用于通知主场景球被点击
4-
signal ball_expired # 自然消失扣分信号
5-
signal ball_clicked # 点击加分信号
4+
signal ball_expired # 自然消失扣分信号
5+
signal ball_clicked # 点击加分信号
66

7-
@export var shrink_speed: float = 0.2 # 缩小速度(可在 Inspector 调整)
8-
@export var attraction_strength: float = 100.0 # 引力强度
7+
@export var shrink_speed: float = 0.2 # 缩小速度(可在 Inspector 调整)
8+
@export var attraction_strength: float = 100.0 # 引力强度
99

1010

1111
func _physics_process(delta):
1212
# 吸引力影响
13-
var mouse_pos = get_viewport().get_mouse_position() # 获取鼠标位置
14-
var direction = (mouse_pos - position).normalized() # 计算方向向量
15-
position += direction * self.attraction_strength * delta # 根据引力更新位置
13+
var mouse_pos = get_viewport().get_mouse_position() # 获取鼠标位置
14+
var direction = (mouse_pos - position).normalized() # 计算方向向量
15+
position += direction * self.attraction_strength * delta # 根据引力更新位置
1616

1717
# 持续缩小
1818
scale -= Vector2.ONE * shrink_speed * delta

scripts/ball_expired.gd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ func _ready():
99

1010

1111
func _on_animation_finished():
12-
get_parent().queue_free() # 动画完成后自动销毁父节点
12+
get_parent().queue_free() # 动画完成后自动销毁父节点

scripts/ball_explosion_animate.gd

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,12 @@ extends AnimatedSprite2D
44
# Called when the node enters the scene tree for the first time.
55
func _ready():
66
connect("animation_finished", _on_animation_finished)
7-
play("explode", 1.0, false) # 如果未启用 Autoplay 时使用
7+
play("explode", 1.0, false) # 如果未启用 Autoplay 时使用
88

99
var audioNode = get_parent().get_node("AudioStreamPlayer2D");
1010
# 随机音高
1111
audioNode.pitch_scale = randf_range(0.6, 1.5)
1212
audioNode.play()
1313

1414
func _on_animation_finished():
15-
get_parent().queue_free() # 动画完成后自动销毁父节点
16-
15+
get_parent().queue_free() # 动画完成后自动销毁父节点

scripts/main.gd

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
extends Node
2-
var score = 0 # 分数
3-
var killed_count = 0 # 击毁石头的数量
4-
var game_active = true # 游戏状态标志
5-
var ball_scene = preload("res://scenes/ball.tscn") # 加载球对象场景
6-
var ball_explosion_scene = preload("res://scenes/ball_explosion.tscn") # 加载球爆炸对象场景
7-
var ball_expired_scene = preload("res://scenes/ball_expired.tscn") # 加载球自然消失对象场景
2+
var score = 0 # 分数
3+
var killed_count = 0 # 击毁石头的数量
4+
var game_active = true # 游戏状态标志
5+
var ball_scene = preload("res://scenes/ball.tscn") # 加载球对象场景
6+
var ball_explosion_scene = preload("res://scenes/ball_explosion.tscn") # 加载球爆炸对象场景
7+
var ball_expired_scene = preload("res://scenes/ball_expired.tscn") # 加载球自然消失对象场景
88
var split_scene = preload("res://scenes/split.tscn")
99

10-
const INIT_TIMER_INTERVAL = 1.0 # 初始生成间隔
11-
var timer_interval = INIT_TIMER_INTERVAL # 初始生成间隔
10+
const INIT_TIMER_INTERVAL = 1.0 # 初始生成间隔
11+
var timer_interval = INIT_TIMER_INTERVAL # 初始生成间隔
1212

1313
const INIT_BALL_SHRINK_SPEED = 0.15
1414

15-
var ball_shrink_speed = INIT_BALL_SHRINK_SPEED # 当前难度下,小球掉落速度
15+
var ball_shrink_speed = INIT_BALL_SHRINK_SPEED # 当前难度下,小球掉落速度
1616
const MAX_BALL_SHRINK_SPEED = 10
1717
"""最快小球缩减速度"""
1818

1919
@export var suction_level = 0
2020
@onready var score_label = $CanvasLayer/ScoreLabel
2121
@onready var history_label = $CanvasLayer/History
2222

23-
const GENERATE_PADDING = 100
23+
const GENERATE_PADDING = 100
2424
"""生成的边距"""
2525
const MIN_GENERATE_INTERVAL = 0.4
2626
"""最短生成间隔"""
@@ -35,19 +35,18 @@ func _ready():
3535
var theme = preload("res://assets/fonts/unifont-16.0.02.otf")
3636
$CanvasLayer/RestartButton.theme = theme
3737

38-
$Timer.start() # 开始生成球
38+
$Timer.start() # 开始生成球
3939
print("start!")
4040
var engine_version = Engine.get_version_info()
4141
var project_ver = ProjectSettings.get_setting("application/config/version")
4242
$CanvasLayer/Version.text = "engine_version: %d.%d.%d\nproject_ver: %s" % [
43-
engine_version.major,
44-
engine_version.minor,
43+
engine_version.major,
44+
engine_version.minor,
4545
engine_version.patch,
4646
project_ver
4747
]
4848

4949

50-
5150
# 生成一个随机位置的球
5251
func spawn_ball():
5352
var ball = ball_scene.instantiate()
@@ -83,7 +82,7 @@ func update_ui():
8382
]
8483
var history_label_text = "\n"
8584
for i in range(len(user_killed_history)):
86-
history_label_text += "%d: %d\n" % [i+1, user_killed_history[i]]
85+
history_label_text += "%d: %d\n" % [i + 1, user_killed_history[i]]
8786
history_label.text = "history: %s" % [history_label_text]
8887

8988

@@ -115,7 +114,7 @@ func _on_ball_clicked(ball_dead_position, ball_dead_scale):
115114
func _on_ball_expired(ball_dead_position):
116115
if !game_active:
117116
return
118-
score -= 2 # 扣分幅度大于加分
117+
score -= 2 # 扣分幅度大于加分
119118

120119
# 增加消失效果
121120
var ball_expired = ball_expired_scene.instantiate()
@@ -141,15 +140,15 @@ func game_over():
141140

142141
# 批量删除
143142
for ball in balls:
144-
ball.queue_free() # 安全删除节点
143+
ball.queue_free() # 安全删除节点
145144

146145
var animations = get_tree().get_nodes_in_group("ball_animations")
147146
for animation in animations:
148-
animation.queue_free() # 安全删除节点
147+
animation.queue_free() # 安全删除节点
149148

150149
# 可选:立即强制释放内存
151-
Engine.get_main_loop().process_frame # 等待一帧
152-
RenderingServer.force_draw() # 强制渲染刷新
150+
Engine.get_main_loop().process_frame # 等待一帧
151+
RenderingServer.force_draw() # 强制渲染刷新
153152

154153
$CanvasLayer/GameOverLabel.visible = true
155154
$CanvasLayer/RestartButton.visible = true

0 commit comments

Comments
 (0)