Skip to content

Commit 2477c9b

Browse files
authored
Merge pull request #7 from gitbrent/version-0.3.0
Version 0.3.0
2 parents 90b563f + d620bec commit 2477c9b

File tree

6 files changed

+223
-91
lines changed

6 files changed

+223
-91
lines changed

enums.gd

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
extends Node
22

3-
const APP_VER:String = "0.1.0"
4-
const APP_BLD:String = "20240510"
3+
const APP_VER:String = "0.3.0"
4+
const APP_BLD:String = "20240511"
55
const TWEEN_TIME:float = 0.25
6-
const EXPLODE_DELAY:int = 1
6+
const EXPLODE_DELAY:float = TWEEN_TIME*2.0
77
const SRPITE_POS:Vector2 = Vector2(64,64)
8-
var current_debug_level = DEBUG_LEVEL.INFO # Global variable to set the current debug level
8+
var current_debug_level = DEBUG_LEVEL.DEBUG # Global variable to set the current debug level
99

1010
# =========================================================
1111

game/animated_cloud.tscn

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ tracks/0/keys = {
1717
"times": PackedFloat32Array(0, 30),
1818
"transitions": PackedFloat32Array(1, 1),
1919
"update": 0,
20-
"values": [Vector2(64, 220), Vector2(1936, 220)]
20+
"values": [Vector2(64, 75), Vector2(1936, 75)]
2121
}
2222

2323
[sub_resource type="AnimationLibrary" id="AnimationLibrary_5m8mq"]
@@ -43,7 +43,7 @@ offset_bottom = 150.0
4343
grow_horizontal = 2
4444

4545
[node name="Sprite2D" type="Sprite2D" parent="."]
46-
position = Vector2(64, 220)
46+
position = Vector2(64, 75)
4747
texture = ExtResource("2_vo0va")
4848

4949
[node name="AnimationPlayer" type="AnimationPlayer" parent="."]

game/game.tscn

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,13 @@ offset_bottom = 1390.0
3232
texture = ExtResource("1_h8otn")
3333
expand_mode = 2
3434

35-
[node name="AnimatedCloud" parent="." instance=ExtResource("3_a1y13")]
35+
[node name="AnimatedCloud1" parent="." instance=ExtResource("3_a1y13")]
36+
37+
[node name="AnimatedCloud2" parent="." instance=ExtResource("3_a1y13")]
38+
position = Vector2(1000, 75)
39+
40+
[node name="AnimatedCloud3" parent="." instance=ExtResource("3_a1y13")]
41+
position = Vector2(-1000, 100)
3642

3743
[node name="BkgdDimmer" type="Panel" parent="."]
3844
visible = false
@@ -101,9 +107,9 @@ theme_override_styles/panel = SubResource("StyleBoxFlat_k3sk6")
101107

102108
[node name="GameStats" type="VBoxContainer" parent="."]
103109
offset_left = 120.0
104-
offset_top = 250.0
110+
offset_top = 280.0
105111
offset_right = 370.0
106-
offset_bottom = 1274.0
112+
offset_bottom = 1304.0
107113
theme_override_constants/separation = 40
108114

109115
[node name="HBoxContainer1" type="HBoxContainer" parent="GameStats"]
@@ -257,10 +263,10 @@ position = Vector2(500, 250)
257263
stream = ExtResource("8_7jpwb")
258264

259265
[node name="BtnNewGame" type="TextureButton" parent="."]
260-
offset_left = 1608.0
261-
offset_top = 255.0
262-
offset_right = 2767.0
263-
offset_bottom = 613.0
266+
offset_left = 1600.0
267+
offset_top = 250.0
268+
offset_right = 2759.0
269+
offset_bottom = 608.0
264270
scale = Vector2(0.3, 0.3)
265271
texture_normal = ExtResource("10_qtl06")
266272

@@ -298,7 +304,6 @@ horizontal_alignment = 1
298304
vertical_alignment = 1
299305

300306
[node name="BtnMatchCol" type="TextureButton" parent="."]
301-
visible = false
302307
offset_left = 1656.0
303308
offset_top = 519.0
304309
offset_right = 2815.0

game_board/GameBoard.gd

Lines changed: 112 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ signal props_updated_gemsdict(gems_dict:Dictionary)
1111
@onready var hbox_container:HBoxContainer = $HBoxContainer
1212
#VARS
1313
const GEM_COLOR_NAMES = [Enums.GemColor.WHITE, Enums.GemColor.RED, Enums.GemColor.YELLOW, Enums.GemColor.GREEN, Enums.GemColor.PURPLE, Enums.GemColor.BROWN]
14+
const GEM_POINTS:int = 25
1415
var selected_cell_1:GemCell = null
1516
var selected_cell_2:GemCell = null
1617
var undo_cell_1:GemCell = null
@@ -27,14 +28,7 @@ func _ready():
2728
fill_grid()
2829
fill_hbox()
2930
# B: check board after init
30-
check_board_explode_matches()
31-
32-
# TODO: feed props to parent controller for display
33-
func get_gem_props():
34-
var brent:Dictionary = {
35-
"GREEN": 99
36-
}
37-
return brent
31+
process_game_round()
3832

3933
# =========================================================
4034

@@ -113,10 +107,10 @@ func are_cells_adjacent(gemcell1:GemCell, gemcell2:GemCell) -> bool:
113107
# Cells are not adjacent
114108
return false
115109

116-
func get_first_match_gems() -> Array:
110+
func get_all_matches() -> Array:
117111
var num_columns: int = hbox_container.get_child_count()
118112
var num_rows: int = hbox_container.get_child(0).get_child_count()
119-
var match_cells: Array = []
113+
var matches = []
120114

121115
# Horizontal Check (check each row)
122116
for row in range(num_rows):
@@ -129,19 +123,24 @@ func get_first_match_gems() -> Array:
129123
streak += 1
130124
else:
131125
if streak >= 3:
132-
# Collect matching GemCells
133-
match_cells = []
126+
var match_cells = []
134127
for i in range(match_start, column):
135128
match_cells.append(hbox_container.get_child(i).get_child(row))
136-
return match_cells
129+
matches.append({
130+
"cells": match_cells,
131+
"count": streak
132+
})
137133
streak = 1
138134
match_start = column
139135
last_color = gem_cell.gem_color
140136
if streak >= 3:
141-
match_cells = []
137+
var match_cells = []
142138
for i in range(match_start, num_columns):
143139
match_cells.append(hbox_container.get_child(i).get_child(row))
144-
return match_cells
140+
matches.append({
141+
"cells": match_cells,
142+
"count": streak
143+
})
145144

146145
# Vertical Check (check each column)
147146
for column in range(num_columns):
@@ -154,21 +153,51 @@ func get_first_match_gems() -> Array:
154153
streak += 1
155154
else:
156155
if streak >= 3:
157-
# Collect matching GemCells
158-
match_cells = []
156+
var match_cells = []
159157
for i in range(match_start, row):
160158
match_cells.append(hbox_container.get_child(column).get_child(i))
161-
return match_cells
159+
matches.append({
160+
"cells": match_cells,
161+
"count": streak
162+
})
162163
streak = 1
163164
match_start = row
164165
last_color = gem_cell.gem_color
165166
if streak >= 3:
166-
match_cells = []
167+
var match_cells = []
167168
for i in range(match_start, num_rows):
168169
match_cells.append(hbox_container.get_child(column).get_child(i))
169-
return match_cells
170-
171-
return [] # No matches found
170+
matches.append({
171+
"cells": match_cells,
172+
"count": streak
173+
})
174+
175+
return matches
176+
177+
func extract_gem_cells_from_matches(matches: Array) -> Array:
178+
var all_gem_cells = []
179+
for match in matches:
180+
# `match["cells"]` is the array of gem cells for this particular match
181+
all_gem_cells += match["cells"] # Append all cells in this match to the master list
182+
return all_gem_cells
183+
184+
func calculate_score_for_matches(matches: Array) -> int:
185+
var score = 0
186+
for match in matches:
187+
var match_length = match["count"]
188+
# Define scoring logic, e.g., exponential growth for larger matches
189+
var match_score = match_length * match_length # Example: score grows quadratically with match length
190+
score += match_score * GEM_POINTS
191+
return score
192+
193+
func calculate_scores_for_each_match(matches: Array) -> Dictionary:
194+
var scores = {}
195+
for match in matches:
196+
var count = match["count"]
197+
var score = count * GEM_POINTS
198+
for cell in match["cells"]:
199+
scores[cell] = score
200+
return scores
172201

173202
# STEP 1: Handle input (=capture first & second selection), swap gems
174203
# @desc: calls `swap_gem_cells()` when 2 cells selected and are adjacent
@@ -271,27 +300,43 @@ func tween_completed():
271300

272301
# C: once all tweens complete, check board
273302
if tweens_running_cnt == 0:
274-
check_board_explode_matches()
303+
process_game_round()
275304

276305
# STEP 4: Check board, then explode first match found... (repeat until exhausted)
277306

278-
func check_board_explode_matches():
279-
Enums.debug_print("[check_board_explode_matches]: =====================================", Enums.DEBUG_LEVEL.INFO)
280-
Enums.debug_print("[check_board_explode_matches]: CHECKING BOARD... ", Enums.DEBUG_LEVEL.INFO)
281-
Enums.debug_print("[check_board_explode_matches]: =====================================", Enums.DEBUG_LEVEL.INFO)
307+
func process_game_round():
308+
Enums.debug_print("[process_game_round]: =====================================", Enums.DEBUG_LEVEL.INFO)
309+
Enums.debug_print("[process_game_round]: CHECKING BOARD... ", Enums.DEBUG_LEVEL.INFO)
310+
Enums.debug_print("[process_game_round]: =====================================", Enums.DEBUG_LEVEL.INFO)
282311

283-
# TDDO: WIP: this will change once we start exploding all at once
284-
board_props_score += 10
312+
# A:
313+
# EX:
314+
# matches[
315+
# {
316+
# "cells":["@Control@112:<Control#89338678177>","@Control@113:<Control#90143984570>","@Control@114:<Control#90949290963>"],
317+
# "count":3},
318+
# {
319+
# "cells":["@Control@119:<Control#95781129321>","@Control@120:<Control#96586435714>","@Control@121:<Control#97391742107>"],
320+
# "count":3
321+
# }
322+
#]
323+
var matches = get_all_matches()
324+
var gem_cells = extract_gem_cells_from_matches(matches)
325+
Enums.debug_print("[process_game_round]: matches.. = "+JSON.stringify(matches), Enums.DEBUG_LEVEL.DEBUG)
326+
Enums.debug_print("[process_game_round]: gem_cells = "+str(gem_cells), Enums.DEBUG_LEVEL.DEBUG)
327+
if matches.size() > 0 and Enums.current_debug_level == Enums.DEBUG_LEVEL.DEBUG:
328+
debug_print_ascii_table(gem_cells)
329+
330+
# B:
331+
var score = calculate_score_for_matches(matches)
332+
board_props_score += score
285333
emit_signal("props_updated_score", board_props_score)
286334

287-
# A:
335+
# C: Update UI or game state as necessary
288336
signal_game_props_count_gems()
289337

290-
# B:
291-
var gem_matches = get_first_match_gems()
292-
if gem_matches.size() > 0:
293-
debug_print_ascii_table(gem_matches)
294-
if gem_matches.size() == 0:
338+
# D: Handle resuolts: explode matches, or halt
339+
if matches.size() == 0:
295340
Enums.debug_print("[check_board_explode_matches]: No more matches. Board stable.", Enums.DEBUG_LEVEL.INFO)
296341
# A:
297342
# B: TODO: check for "NO MORE MOVES"
@@ -305,38 +350,49 @@ func check_board_explode_matches():
305350
undo_cell_1 = null
306351
undo_cell_2 = null
307352
# B: explode matched gems
308-
explode_refill_gems(gem_matches)
353+
var match_scores = calculate_scores_for_each_match(matches)
354+
explode_refill_gems(matches, match_scores)
309355

310-
func explode_refill_gems(gem_cells: Array):
311-
Enums.debug_print("[explode_refill_gems........]: =====================================", Enums.DEBUG_LEVEL.INFO)
312-
Enums.debug_print("[explode_refill_gems........]: *EXPLODING* gem_cell count: "+str(gem_cells.size()), Enums.DEBUG_LEVEL.INFO)
313-
Enums.debug_print("[explode_refill_gems........]: =====================================", Enums.DEBUG_LEVEL.INFO)
356+
func explode_refill_gems(matches: Array, match_scores: Dictionary):
357+
Enums.debug_print("[explode_refill_gems]: !!!!!!!!!!!=====================================", Enums.DEBUG_LEVEL.INFO)
358+
Enums.debug_print("[explode_refill_gems]: *EXPLODING* gem_cell count: "+str(matches.size()), Enums.DEBUG_LEVEL.INFO)
359+
Enums.debug_print("[explode_refill_gems]: !!!!!!!!!!!=====================================", Enums.DEBUG_LEVEL.INFO)
314360
if Enums.current_debug_level == Enums.DEBUG_LEVEL.DEBUG:
315-
debug_print_ascii_table(gem_cells)
361+
debug_print_ascii_table(extract_gem_cells_from_matches(matches))
316362

317363
# A: explode selected
318-
for gem_cell in gem_cells:
319-
gem_cell.explode_gem(gem_cell.gem_color)
320-
await get_tree().create_timer(Enums.EXPLODE_DELAY).timeout
364+
for match in matches:
365+
for gem_cell in match["cells"]:
366+
var score = match_scores[gem_cell]
367+
gem_cell.explode_gem(gem_cell.gem_color, score)
368+
369+
# TODO: FIXME: gem counts need to update faster (they currently update after the animation completes)!!
370+
# seemingly, this would work fine located here but its not - the UI update requires a frame update i guess?
371+
signal_game_props_count_gems()
321372

322-
# B: Dictionary to track columns and the number of gems to add in each column
373+
# B: let explode animation run
374+
await get_tree().create_timer(Enums.TWEEN_TIME).timeout
375+
376+
# C: Dictionary to track columns and the number of gems to add in each column
323377
var columns_to_refill = {}
324-
for gem_cell in gem_cells:
325-
var column_index = gem_cell.get_parent().get_index()
326-
var row_index = gem_cell.get_index()
327-
if column_index in columns_to_refill:
328-
columns_to_refill[column_index]["count"] += 1
329-
columns_to_refill[column_index]["highest"] = max(columns_to_refill[column_index]["highest"], row_index)
330-
else:
331-
columns_to_refill[column_index] = {"highest": row_index, "count": 1}
378+
for match in matches:
379+
for gem_cell in match["cells"]:
380+
var column_index = gem_cell.get_parent().get_index()
381+
var row_index = gem_cell.get_index()
382+
if column_index in columns_to_refill:
383+
columns_to_refill[column_index]["count"] += 1
384+
columns_to_refill[column_index]["highest"] = max(columns_to_refill[column_index]["highest"], row_index)
385+
else:
386+
columns_to_refill[column_index] = {"highest": row_index, "count": 1}
332387

333388
# C: Process each column that needs refilling
334389
for column_index in columns_to_refill.keys():
335390
var details = columns_to_refill[column_index]
336391
refill_column(column_index, details["highest"], details["count"])
337392

338393
# D:
339-
check_board_explode_matches()
394+
await get_tree().create_timer(Enums.EXPLODE_DELAY).timeout # let refill animations above complete (otherwise new, matching gems would start exploding before they're even in place!)
395+
process_game_round()
340396

341397
func refill_column(column_index: int, highest_exploded_row: int, count_exploded: int):
342398
var column = hbox_container.get_child(column_index)
@@ -444,7 +500,7 @@ func new_game():
444500
gem_cell.get_child(1).visible = true
445501
gem_cell.get_child(1).position = Enums.SRPITE_POS
446502
# B:
447-
check_board_explode_matches()
503+
process_game_round()
448504

449505
func debug_clear_debug_labels():
450506
for vbox in hbox_container.get_children():
@@ -477,4 +533,5 @@ func debug_make_gem_grid():
477533
gem.initialize(Enums.GemColor.GREEN)
478534
if (i + j) % 2 == 0:
479535
gem.initialize(Enums.GemColor.WHITE)
536+
gem.get_child(1).position = Enums.SRPITE_POS
480537
signal_game_props_count_gems()

0 commit comments

Comments
 (0)