Skip to content

Commit 52365ea

Browse files
committed
added game props and animated cloud
1 parent fa45346 commit 52365ea

File tree

6 files changed

+100
-33
lines changed

6 files changed

+100
-33
lines changed

animated_cloud.tscn

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
[gd_scene load_steps=5 format=3 uid="uid://d0yw6oyw3qib0"]
2+
3+
[ext_resource type="Texture2D" uid="uid://cnlqirgwr8d4" path="res://assets/bkgd/Background.png" id="1_p4wo5"]
4+
[ext_resource type="Texture2D" uid="uid://cfdjrsigqjjjk" path="res://assets/bkgd/Cloud_2.png" id="2_vo0va"]
5+
6+
[sub_resource type="Animation" id="Animation_0x8pj"]
7+
resource_name = "move_cloud"
8+
length = 30.0
9+
loop_mode = 2
10+
tracks/0/type = "value"
11+
tracks/0/imported = false
12+
tracks/0/enabled = true
13+
tracks/0/path = NodePath("Sprite2D:position")
14+
tracks/0/interp = 1
15+
tracks/0/loop_wrap = true
16+
tracks/0/keys = {
17+
"times": PackedFloat32Array(0, 30),
18+
"transitions": PackedFloat32Array(1, 1),
19+
"update": 0,
20+
"values": [Vector2(64, 90), Vector2(1936, 90)]
21+
}
22+
23+
[sub_resource type="AnimationLibrary" id="AnimationLibrary_5m8mq"]
24+
_data = {
25+
"move_cloud": SubResource("Animation_0x8pj")
26+
}
27+
28+
[node name="AnimatedCloud" type="Node2D"]
29+
30+
[node name="Debug-Background" type="TextureRect" parent="."]
31+
visible = false
32+
offset_right = 2000.0
33+
offset_bottom = 1390.0
34+
texture = ExtResource("1_p4wo5")
35+
expand_mode = 2
36+
37+
[node name="Debug-Panel" type="Panel" parent="."]
38+
visible = false
39+
offset_right = 2000.0
40+
offset_bottom = 180.0
41+
42+
[node name="Sprite2D" type="Sprite2D" parent="."]
43+
position = Vector2(64, 90)
44+
texture = ExtResource("2_vo0va")
45+
46+
[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
47+
libraries = {
48+
"": SubResource("AnimationLibrary_5m8mq")
49+
}
50+
autoplay = "move_cloud"

game.gd

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,20 @@
11
extends Node2D
22
# SCENES
3-
@onready var audio_gem_move:AudioStreamPlayer = $AudioGemMove
43
@onready var game_board:GameBoard = $Board
5-
@onready var game_stats = $GameStats
4+
@onready var game_stats:VBoxContainer = $GameStats
65

7-
func _on_board_gem_swapped():
8-
play_move_sound()
9-
#GameProps.get_props()
10-
update_game_props()
6+
func _ready():
7+
game_board.connect("props_updated_moves", self._on_props_updated_moves)
8+
game_board.connect("props_updated_score", self._on_props_updated_score)
119

12-
func play_move_sound():
13-
audio_gem_move.play()
14-
15-
func update_game_props():
16-
var brent = game_board.get_gem_props()
17-
print("brent: ", brent)
10+
func _on_props_updated_moves(moves:int):
1811
# TODO: name labels, then update base on this
19-
game_stats.get_child(0).get_child(1).text = "99"
12+
game_stats.get_child(0).get_child(1).text = str(moves)
13+
14+
func _on_props_updated_score(score:int):
15+
# TODO: name labels, then update base on this
16+
game_stats.get_child(1).get_child(1).text = str(score)
17+
game_stats.get_child(2).get_child(1).text = str(score)
2018

2119
func _on_newgame_button_pressed():
2220
game_board.new_game()

game.tscn

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
[gd_scene load_steps=18 format=3 uid="uid://b5bfm2244ywxk"]
1+
[gd_scene load_steps=19 format=3 uid="uid://b5bfm2244ywxk"]
22

33
[ext_resource type="Script" path="res://game.gd" id="1_ewnxx"]
44
[ext_resource type="Texture2D" uid="uid://cnlqirgwr8d4" path="res://assets/bkgd/Background.png" id="1_h8otn"]
55
[ext_resource type="PackedScene" uid="uid://x4qq2j3l7nvb" path="res://game_board/board.tscn" id="2_2ltbx"]
6+
[ext_resource type="PackedScene" uid="uid://d0yw6oyw3qib0" path="res://animated_cloud.tscn" id="3_a1y13"]
67
[ext_resource type="Texture2D" uid="uid://b8biy2iputyhe" path="res://assets/gems/characters_0002.png" id="3_qywvx"]
78
[ext_resource type="Texture2D" uid="uid://duau66qew6757" path="res://assets/gems/characters_0001.png" id="3_sh4xh"]
89
[ext_resource type="Texture2D" uid="uid://vu6oui2n7024" path="res://assets/gems/characters_0003.png" id="4_2reex"]
@@ -33,6 +34,8 @@ offset_bottom = 1390.0
3334
texture = ExtResource("1_h8otn")
3435
expand_mode = 2
3536

37+
[node name="AnimatedCloud" parent="." instance=ExtResource("3_a1y13")]
38+
3639
[node name="BkgdDimmer" type="Panel" parent="."]
3740
visible = false
3841
anchors_preset = 15
@@ -46,16 +49,16 @@ theme_override_styles/panel = SubResource("StyleBoxFlat_103kv")
4649

4750
[node name="GameStatsBkgd" type="Panel" parent="."]
4851
offset_left = 75.0
49-
offset_top = 150.0
52+
offset_top = 183.0
5053
offset_right = 425.0
51-
offset_bottom = 1174.0
54+
offset_bottom = 1207.0
5255
theme_override_styles/panel = SubResource("StyleBoxFlat_k3sk6")
5356

5457
[node name="GameStats" type="VBoxContainer" parent="."]
5558
offset_left = 100.0
56-
offset_top = 175.0
59+
offset_top = 203.0
5760
offset_right = 425.0
58-
offset_bottom = 1199.0
61+
offset_bottom = 1227.0
5962
theme_override_constants/separation = 40
6063

6164
[node name="HBoxContainer1" type="HBoxContainer" parent="GameStats"]
@@ -186,13 +189,13 @@ text = "0"
186189
[node name="BoardTextRect" type="Panel" parent="."]
187190
visible = false
188191
offset_left = 500.0
189-
offset_top = 150.0
192+
offset_top = 183.0
190193
offset_right = 1524.0
191-
offset_bottom = 1174.0
194+
offset_bottom = 1207.0
192195
theme_override_styles/panel = SubResource("StyleBoxFlat_103kv")
193196

194197
[node name="Board" parent="." instance=ExtResource("2_2ltbx")]
195-
position = Vector2(500, 150)
198+
position = Vector2(500, 183)
196199

197200
[node name="Panel" type="Panel" parent="."]
198201
visible = false
@@ -272,7 +275,6 @@ text = "CHECKERED"
272275
horizontal_alignment = 1
273276
vertical_alignment = 1
274277

275-
[connection signal="gem_swapped" from="Board" to="." method="_on_board_gem_swapped"]
276278
[connection signal="pressed" from="BtnNewGame" to="." method="_on_newgame_button_pressed"]
277279
[connection signal="pressed" from="BtnClearDebugLabels" to="." method="_on_btn_clear_debug_labels_pressed"]
278280
[connection signal="pressed" from="BtnMatchCol" to="." method="_on_btn_make_vert_pressed"]

game_board/GameBoard.gd

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
extends Node2D
44
class_name GameBoard
55
# SIGNALS
6-
signal gem_swapped()
6+
signal props_updated_moves(moves:int)
7+
signal props_updated_score(score:int)
78
# SCENES
89
@onready var grid_container:GridContainer = $GridContainer
910
@onready var hbox_container:HBoxContainer = $HBoxContainer
@@ -13,7 +14,9 @@ var selected_cell_1:GemCell = null
1314
var selected_cell_2:GemCell = null
1415
var undo_cell_1:GemCell = null
1516
var undo_cell_2:GemCell = null
16-
var tweens_running:int = 0
17+
var tweens_running_cnt:int = 0
18+
var board_props_moves:int = 0
19+
var board_props_score:int = 0
1720

1821
# Called when the node enters the scene tree for the first time.
1922
func _ready():
@@ -55,16 +58,15 @@ func fill_hbox():
5558
for row_idx in range(8):
5659
# A: random gem
5760
var gem_type = GEM_COLOR_NAMES[randi() % GEM_COLOR_NAMES.size()]
58-
#var gem_type = Enums.GemColor.WHITE
5961
# B: create/add
6062
var gem_cell_scene = load("res://game_board/gem_cell.tscn")
6163
var gem_cell:GemCell = gem_cell_scene.instantiate()
6264
hbox_container.get_child(col_idx).add_child(gem_cell)
6365
gem_cell.initialize(gem_type)
6466
var control_node = gem_cell.get_node("GemControl")
65-
#control_node.connect("drag_start", self._on_cell_click)
6667
control_node.connect("cell_click", self._on_cell_click)
67-
#control_node.connect("drag_ended", self._on_cell_click)
68+
#control_node.connect("drag_start", self._on_cell_click) # TODO:
69+
#control_node.connect("drag_ended", self._on_cell_click) # TODO:
6870

6971
# =========================================================
7072

@@ -217,7 +219,10 @@ func swap_gem_cells(swap_cell_1:GemCell, swap_cell_2:GemCell):
217219
return
218220

219221
# A: signal game controller
220-
emit_signal("gem_swapped") # notify controller (play sound, increase moves counter, etc.)
222+
swap_cell_1.play_audio_gem_move()
223+
swap_cell_2.play_audio_gem_move()
224+
board_props_moves += 1
225+
emit_signal("props_updated_moves", board_props_moves)
221226

222227
# B: turn off anim/effects before moving
223228
swap_cell_1.play_selected_anim(false)
@@ -240,17 +245,17 @@ func swap_gem_cells(swap_cell_1:GemCell, swap_cell_2:GemCell):
240245

241246
func setup_tween(gem_cell:GemCell, start_pos:Vector2, end_pos:Vector2):
242247
gem_cell.sprite.global_position = start_pos # NOTE: Set initial position right before tweening
243-
tweens_running += 1
248+
tweens_running_cnt += 1
244249
var tween = get_tree().create_tween()
245250
tween.tween_property(gem_cell.sprite, "global_position", end_pos, Enums.TWEEN_TIME)
246251
tween.tween_callback(tween_completed)
247252

248253
# STEP 3: Tween complete: clear vars/scan board
249254

250255
func tween_completed():
251-
Enums.debug_print("[tween_completed]: (counter="+str(tweens_running)+")", Enums.DEBUG_LEVEL.INFO)
256+
Enums.debug_print("[tween_completed]: (counter="+str(tweens_running_cnt)+")", Enums.DEBUG_LEVEL.INFO)
252257
# A: update counter
253-
tweens_running -= 1
258+
tweens_running_cnt -= 1
254259

255260
# B: clear selections
256261
if selected_cell_1:
@@ -261,7 +266,7 @@ func tween_completed():
261266
selected_cell_2 = null
262267

263268
# C: once all tweens complete, check board
264-
if tweens_running == 0:
269+
if tweens_running_cnt == 0:
265270
check_board_explode_matches()
266271

267272
# STEP 4: Check board, then explode first match found... (repeat until exhausted)
@@ -271,6 +276,10 @@ func check_board_explode_matches():
271276
Enums.debug_print("[check_board_explode_matches]: CHECKING BOARD... ", Enums.DEBUG_LEVEL.INFO)
272277
Enums.debug_print("[check_board_explode_matches]: =====================================", Enums.DEBUG_LEVEL.INFO)
273278

279+
# TDDO: WIP: this will change once we start exploding all at once
280+
board_props_score += 10
281+
emit_signal("props_updated_score", board_props_score)
282+
274283
var gem_matches = get_first_match_gems()
275284
if gem_matches.size() > 0:
276285
debug_print_ascii_table(gem_matches)

game_board/GemCell.gd

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ class_name GemCell
77
@onready var debug_label_sel_num:Label = $DebugLabelSelNum
88
@onready var debug_ui_panel:Panel = $DebugUIPanel
99
@onready var audio_gem_explode:AudioStreamPlayer = $AudioGemExplode
10+
@onready var audio_gem_move:AudioStreamPlayer = $AudioGemMove
1011
# PROPS
1112
const SPRITE_SCALE:Vector2 = Vector2(0.5, 0.5)
1213
const DROP_OFFSET:int = 128 # (the sprite is centered in the 128x128 container, and uses a 64,64 position)
@@ -76,6 +77,9 @@ func update_texture():
7677

7778
# =========================================================
7879

80+
func play_audio_gem_move():
81+
audio_gem_move.play()
82+
7983
func play_selected_anim(selected:bool):
8084
if selected:
8185
anim_player_fx.play("selected")

game_board/gem_cell.tscn

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
[gd_scene load_steps=25 format=3 uid="uid://clfnptdc2tu5l"]
1+
[gd_scene load_steps=26 format=3 uid="uid://clfnptdc2tu5l"]
22

33
[ext_resource type="Script" path="res://game_board/GemCell.gd" id="1_rhspx"]
44
[ext_resource type="Texture2D" uid="uid://duau66qew6757" path="res://assets/gems/characters_0001.png" id="2_33s7h"]
@@ -7,6 +7,7 @@
77
[ext_resource type="FontFile" uid="uid://dlhwrp5jwkrll" path="res://assets/fonts/Acme-Regular.ttf" id="5_lb5dp"]
88
[ext_resource type="Theme" uid="uid://hahh0mrfx2q1" path="res://debug_label_theme.tres" id="6_hn3w3"]
99
[ext_resource type="AudioStream" uid="uid://ca0jp78fn0bi1" path="res://assets/audio/bfh1_glass_breaking_02.ogg" id="7_50xdd"]
10+
[ext_resource type="AudioStream" uid="uid://ds53xomd2ha1b" path="res://assets/audio/Abstract2.ogg" id="8_cgn1d"]
1011

1112
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_lpbyf"]
1213
bg_color = Color(0, 0, 0, 0.533333)
@@ -273,3 +274,6 @@ horizontal_alignment = 2
273274

274275
[node name="AudioGemExplode" type="AudioStreamPlayer" parent="."]
275276
stream = ExtResource("7_50xdd")
277+
278+
[node name="AudioGemMove" type="AudioStreamPlayer" parent="."]
279+
stream = ExtResource("8_cgn1d")

0 commit comments

Comments
 (0)