Skip to content

Commit

Permalink
feat(dynamic_bg)!: 添加背景色和更改配色功能
Browse files Browse the repository at this point in the history
将 DynamicBg 改为 ColorRect 类型,作为游戏场景的背景色。

将 DynamicBgPattern 的透明度设置为不透明,并添加更改配色功能。

BREAKING CHANGE: DynamicBg 现改为 ColorRect 类型。
  • Loading branch information
cutekibry committed Feb 16, 2024
1 parent ecfddb6 commit 7951dd6
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 9 deletions.
6 changes: 4 additions & 2 deletions bg/dynamic_bg/dynamic_bg.gd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
extends Node2D
extends ColorRect

signal victory_change(v: bool)

Expand All @@ -24,8 +24,8 @@ func spawn(x_offset, y_offset):
new_pattern.position = Vector2(pat_x, pat_y)
new_pattern.velocity = VELOCITY
victory_change.connect(new_pattern._on_victory_change)
new_pattern._on_victory_change(is_victory)
add_child(new_pattern)
new_pattern._on_victory_change(is_victory)

pat_x += W_STEP
pat_y += H_STEP
Expand All @@ -38,6 +38,8 @@ func set_victory(v: bool):
func _ready():
var x_offset = 0
var y_offset = 0
self.color = ImageLib.get_palette_color_by_name("darkest")

while HEIGHT + y_offset + (WIDTH / W_STEP) * H_STEP > -50:
spawn(x_offset, y_offset)
x_offset += $Timer.wait_time * VELOCITY.x
Expand Down
13 changes: 11 additions & 2 deletions bg/dynamic_bg/dynamic_bg.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,17 @@

[ext_resource type="Script" path="res://bg/dynamic_bg/dynamic_bg.gd" id="1_g3cph"]

[node name="DynamicBg" type="Node2D"]
z_index = -4096
[node name="DynamicBg" type="ColorRect"]
z_index = -50
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
offset_right = -1440.0
offset_bottom = -810.0
grow_horizontal = 2
grow_vertical = 2
mouse_filter = 2
color = Color(0.141176, 0.223529, 0.4, 1)
script = ExtResource("1_g3cph")

[node name="Timer" type="Timer" parent="."]
Expand Down
10 changes: 6 additions & 4 deletions bg/dynamic_bg/dynamic_bg_pattern/dynamic_bg_pattern.gd
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ func _ready():
else:
$Word1.set_word("qd<"[randi_range(0, 2)])
$Word2.set_word("=*"[randi_range(0, 1)])
$Word1.set_color(ImageLib.get_palette_color_by_name("mid"))
$Word2.set_color(ImageLib.get_palette_color_by_name("mid"))

func _process(delta):
position += velocity * delta
Expand All @@ -19,9 +21,9 @@ func _process(delta):

func _on_victory_change(v: bool):
if v:
$Word1.set_color(ImageLib.PALETTE["golden"])
$Word2.set_color(ImageLib.PALETTE["golden"])
$Word1.set_color(ImageLib.get_palette_color_by_name("light"))
$Word2.set_color(ImageLib.get_palette_color_by_name("light"))
else:
$Word1.set_color(ImageLib.PALETTE["default"])
$Word2.set_color(ImageLib.PALETTE["default"])
$Word1.set_color(ImageLib.get_palette_color_by_name("mid"))
$Word2.set_color(ImageLib.get_palette_color_by_name("mid"))

5 changes: 4 additions & 1 deletion bg/dynamic_bg/dynamic_bg_pattern/dynamic_bg_pattern.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@
[ext_resource type="PackedScene" uid="uid://cvx7wowcbfo0r" path="res://objects/word/word.tscn" id="2_7jm3n"]

[node name="DynamicBgPattern" type="Node2D"]
modulate = Color(1, 1, 1, 0.12549)
script = ExtResource("1_hrrmh")

[node name="Word1" parent="." instance=ExtResource("2_7jm3n")]
position = Vector2(-6, 0)
text_id = null
color = null

[node name="Word2" parent="." instance=ExtResource("2_7jm3n")]
position = Vector2(6, 0)
text_id = null
color = null

0 comments on commit 7951dd6

Please sign in to comment.