Skip to content

Commit dc20c6a

Browse files
committed
added common script
1 parent d72d671 commit dc20c6a

File tree

3 files changed

+32
-13
lines changed

3 files changed

+32
-13
lines changed

game_boards/board_space/game_board/GemBoard.gd

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# WORKLIST:
2-
# 1. all gems need to explode at once (get_first_match_gems) needs to become return_all_matches!
31
extends Node2D
42
class_name GemBoardSpace
53
# SIGNALS
@@ -11,6 +9,7 @@ signal board_match_multi(match_cnt:int)
119
@onready var grid_container:GridContainer = $GridContainer
1210
@onready var hbox_container:HBoxContainer = $HBoxContainer
1311
#VARS
12+
var common = preload("res://game_boards/common.gd").new()
1413
const GEM_COLOR_NAMES = [Enums.GemColor.WHITE, Enums.GemColor.RED, Enums.GemColor.YELLOW, Enums.GemColor.GREEN, Enums.GemColor.PURPLE, Enums.GemColor.BROWN]
1514
const GEM_POINTS:int = 25
1615
var selected_cell_1:GemCellSpace = null
@@ -502,14 +501,7 @@ func new_game():
502501
board_props_moves = 0
503502
board_props_score = 0
504503
# B:
505-
for vbox in hbox_container.get_children():
506-
for gem_cell in vbox.get_children():
507-
gem_cell.explode_gem(gem_cell.gem_color, 0)
508-
await get_tree().create_timer(Enums.EXPLODE_DELAY).timeout
509-
# B:
510-
for vbox in hbox_container.get_children():
511-
for gem_cell in vbox.get_children():
512-
gem_cell.replace_gem(GEM_COLOR_NAMES[randi() % GEM_COLOR_NAMES.size()], 1)
504+
common.new_game_explode_replace(hbox_container, GEM_COLOR_NAMES, Enums.EXPLODE_DELAY)
513505
# C:
514506
process_game_round()
515507

game_boards/board_space/game_board/GemCell.gd

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,11 @@ func replace_gem(colorIn: Enums.GemColor, rows_to_drop: int = 1):
6161
sprite.visible = true # Make sure the sprite is visible if it was hidden after explosion
6262

6363
# Call the drop animation deferred to ensure it starts after other logic
64-
call_deferred("drop_in_gem", drop_height)
64+
call_deferred("drop_in_gem")
6565

66-
func drop_in_gem(drop_height: float):
67-
# Tween the "fall" animation from the starting point to the final position
66+
func drop_in_gem():
6867
var tween = get_tree().create_tween()
68+
# DESIGN: final position should *always* be its default [relative] position
6969
tween.tween_property(sprite, "position", Enums.SRPITE_POS, Enums.TWEEN_TIME)
7070

7171
func update_texture():

game_boards/common.gd

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
extends Node
2+
class_name Common
3+
4+
func new_game_explode_replace(hbox:HBoxContainer, colors:Array, delay:float):
5+
# A:
6+
for vbox in hbox.get_children():
7+
for gem_cell in vbox.get_children():
8+
gem_cell.explode_gem(gem_cell.gem_color, 0)
9+
10+
# B:
11+
await delay_time(hbox, delay)
12+
13+
# C:
14+
for vbox in hbox.get_children():
15+
for gem_cell in vbox.get_children():
16+
gem_cell.replace_gem(colors[randi() % colors.size()], 1)
17+
18+
func delay_time(node: Node, delay: float) -> void:
19+
var tnode = node.get_parent()
20+
var timer = Timer.new()
21+
timer.wait_time = delay
22+
timer.one_shot = true
23+
tnode.add_child(timer)
24+
timer.start()
25+
await timer.timeout
26+
tnode.remove_child(timer)
27+
timer.queue_free()

0 commit comments

Comments
 (0)