Skip to content

Commit 07099b0

Browse files
committed
DONE with support for various gem sprites
1 parent 8dfd417 commit 07099b0

File tree

9 files changed

+77
-38
lines changed

9 files changed

+77
-38
lines changed

enums.gd

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

33
const APP_VER:String = "0.4.0"
4-
const APP_BLD:String = "20240513"
4+
const APP_BLD:String = "20240517"
55
const TWEEN_TIME:float = 0.25
66
const EXPLODE_DELAY:float = TWEEN_TIME*2.0
77
const SRPITE_POS:Vector2 = Vector2(64,64)
8-
var current_debug_level = DEBUG_LEVEL.DEBUG # Global variable to set the current debug level
8+
var current_debug_level = DEBUG_LEVEL.INFO # Global variable to set the current debug level
99

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

@@ -26,6 +26,13 @@ func get_color_name_by_value(value: int) -> String:
2626

2727
# =========================================================
2828

29+
enum GemDict {
30+
FOOD,
31+
GEMS
32+
}
33+
34+
# =========================================================
35+
2936
enum DEBUG_LEVEL {
3037
NONE, # No debug output
3138
ERROR, # Critical errors only

game_boards/all_common/cmn_gem_cell.gd

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,30 +15,40 @@ class_name CommonGemCell
1515
const SPRITE_SCALE:Vector2 = Vector2(0.5, 0.5)
1616
const DROP_OFFSET:int = 128 # (the sprite is centered in the 128x128 container, and uses a 64,64 position)
1717
var gem_color:Enums.GemColor
18+
var gem_dict:Enums.GemDict
1819
# Declare and preload textures
19-
var gem_textures: Dictionary = {
20+
const gem_textures_gems: Dictionary = {
2021
Enums.GemColor.WHITE: preload("res://assets/gems/space/gem1.png"),
2122
Enums.GemColor.RED: preload("res://assets/gems/space/gem2.png"),
2223
Enums.GemColor.YELLOW: preload("res://assets/gems/space/gem3.png"),
2324
Enums.GemColor.GREEN: preload("res://assets/gems/space/gem4.png"),
24-
Enums.GemColor.BROWN: preload("res://assets/gems/space/gem5.png"),
25-
Enums.GemColor.PURPLE: preload("res://assets/gems/space/gem6.png")
25+
Enums.GemColor.PURPLE: preload("res://assets/gems/space/gem5.png"),
26+
Enums.GemColor.BROWN: preload("res://assets/gems/space/gem6.png")
2627
}
27-
var gem_textures_food: Dictionary = {
28+
const gem_textures_food: Dictionary = {
2829
Enums.GemColor.WHITE: preload("res://assets/gems/characters_0001.png"),
2930
Enums.GemColor.RED: preload("res://assets/gems/characters_0002.png"),
3031
Enums.GemColor.YELLOW: preload("res://assets/gems/characters_0003.png"),
3132
Enums.GemColor.GREEN: preload("res://assets/gems/characters_0005.png"),
32-
Enums.GemColor.BROWN: preload("res://assets/gems/characters_0006.png"),
33-
Enums.GemColor.PURPLE: preload("res://assets/gems/characters_0007.png")
33+
Enums.GemColor.PURPLE: preload("res://assets/gems/characters_0007.png"),
34+
Enums.GemColor.BROWN: preload("res://assets/gems/characters_0006.png")
3435
}
36+
var gem_textures:Dictionary = {}
3537

36-
func initialize(colorIn: Enums.GemColor):
38+
func initialize(colorIn: Enums.GemColor, dictIn:Enums.GemDict):
3739
# A:
3840
gem_color = colorIn
41+
gem_dict = dictIn
3942
# B:
40-
update_texture()
43+
if dictIn == Enums.GemDict.FOOD:
44+
gem_textures = gem_textures_food
45+
elif dictIn == Enums.GemDict.GEMS:
46+
gem_textures = gem_textures_gems
47+
else:
48+
print("ERROR: Unknown `GemDict`!")
4149
# C:
50+
update_texture()
51+
# D:
4252
#panel_hover.visible = false
4353

4454
func explode_gem(colorIn: Enums.GemColor, pointsIn:int):
@@ -65,7 +75,7 @@ func replace_gem(colorIn: Enums.GemColor, rows_to_drop: int = 1):
6575
sprite.visible = true
6676

6777
# Initialize the gem with the new color and ensure it's visible
68-
initialize(colorIn)
78+
initialize(colorIn, gem_dict)
6979
sprite.visible = true # Make sure the sprite is visible if it was hidden after explosion
7080

7181
# Call the drop animation deferred to ensure it starts after other logic
@@ -81,7 +91,8 @@ func update_texture():
8191
sprite.texture = gem_textures[gem_color]
8292
#print("[gem_cell] loaded sprite.texture: ", gem_color)
8393
else:
84-
print("ERROR: Texture for gem color not found")
94+
print("ERROR: Texture for gem color not found!")
95+
print("gem_textures: ", gem_textures)
8596

8697
# =========================================================
8798

game_boards/all_common/cmn_gem_cell.tscn

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
[gd_scene load_steps=92 format=3 uid="uid://8rbpehubrrps"]
1+
[gd_scene load_steps=90 format=3 uid="uid://8rbpehubrrps"]
22

33
[ext_resource type="Script" path="res://game_boards/all_common/cmn_gem_cell.gd" id="1_taq7m"]
4-
[ext_resource type="Shader" path="res://game_boards/all_common/gem_cell.gdshader" id="2_5jui1"]
54
[ext_resource type="Texture2D" uid="uid://duau66qew6757" path="res://assets/gems/characters_0001.png" id="2_nap56"]
65
[ext_resource type="Texture2D" uid="uid://c4u0bdf7rh0u3" path="res://assets/gems/space/Overlay-Lock.png" id="3_ry8vu"]
76
[ext_resource type="Texture2D" uid="uid://cooat8cgq2rb4" path="res://assets/gems/space/Overlay-Ice.png" id="4_r411p"]
@@ -18,11 +17,6 @@
1817
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_lpbyf"]
1918
bg_color = Color(0, 0, 0, 0.533333)
2019

21-
[sub_resource type="ShaderMaterial" id="ShaderMaterial_geoqq"]
22-
shader = ExtResource("2_5jui1")
23-
shader_parameter/line_color = Color(1, 1, 1, 1)
24-
shader_parameter/line_thickness = 7.0
25-
2620
[sub_resource type="Animation" id="Animation_3mn62"]
2721
resource_name = "explode"
2822
length = 0.5
@@ -644,7 +638,6 @@ grow_vertical = 2
644638
theme_override_styles/panel = SubResource("StyleBoxFlat_lpbyf")
645639

646640
[node name="Sprite2D" type="Sprite2D" parent="."]
647-
material = SubResource("ShaderMaterial_geoqq")
648641
position = Vector2(64, 64)
649642
scale = Vector2(0.5, 0.5)
650643
texture = ExtResource("2_nap56")

game_boards/all_common/common.gd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ func fill_grid(hbox:HBoxContainer, grid:GridContainer):
2222
# Add the instantiated square to the grid container
2323
grid.add_child(brdsq)
2424

25-
func fill_hbox(hbox:HBoxContainer, on_cell_click):
25+
func fill_hbox(hbox:HBoxContainer, gem_dict:Enums.GemDict, on_cell_click):
2626
for col_idx in range(hbox.get_child_count()):
2727
for row_idx in range(8):
2828
# A: random gem
@@ -31,7 +31,7 @@ func fill_hbox(hbox:HBoxContainer, on_cell_click):
3131
var gem_cell_scene = load("res://game_boards/all_common/cmn_gem_cell.tscn")
3232
var gem_cell:CommonGemCell = gem_cell_scene.instantiate()
3333
hbox.get_child(col_idx).add_child(gem_cell)
34-
gem_cell.initialize(gem_type)
34+
gem_cell.initialize(gem_type, gem_dict)
3535
var control_node = gem_cell.get_node("GemControl")
3636
control_node.connect("cell_click", on_cell_click)
3737
#control_node.connect("drag_start", self._on_cell_click) # TODO:

game_boards/all_common/common_debug.gd

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,25 +63,25 @@ func debug_clear_debug_labels(hbox:HBoxContainer):
6363
#var debug_str = "[debug_clear_debug_labels] ["+debug_name+"] " + str(gem_cell.get_child(1).visible)
6464
#Enums.debug_print(debug_str, Enums.DEBUG_LEVEL.DEBUG)
6565

66-
func debug_make_match_col(hbox:HBoxContainer):
66+
func debug_make_match_col(hbox:HBoxContainer, gemDict:Enums.GemDict):
6767
var col0:VBoxContainer = hbox.get_child(0)
6868
var col0_child4:CommonGemCell = col0.get_child(4)
69-
col0_child4.initialize(Enums.GemColor.GREEN)
69+
col0_child4.initialize(Enums.GemColor.GREEN, gemDict)
7070
var col0_child5:CommonGemCell = col0.get_child(5)
71-
col0_child5.initialize(Enums.GemColor.GREEN)
71+
col0_child5.initialize(Enums.GemColor.GREEN, gemDict)
7272
var col0_child6:CommonGemCell = col0.get_child(6)
73-
col0_child6.initialize(Enums.GemColor.GREEN)
73+
col0_child6.initialize(Enums.GemColor.GREEN, gemDict)
7474
var col0_child7:CommonGemCell = col0.get_child(7)
75-
col0_child7.initialize(Enums.GemColor.GREEN)
75+
col0_child7.initialize(Enums.GemColor.GREEN, gemDict)
7676

77-
func debug_make_gem_grid(hbox:HBoxContainer):
77+
func debug_make_gem_grid(hbox:HBoxContainer, gemDict:Enums.GemDict):
7878
var size = hbox.get_child_count()
7979
for i in range(size):
8080
var vbox = hbox.get_child(i)
8181
for j in range(size):
8282
var gem = vbox.get_child(j)
8383
# Load the appropriate scene based on the checkerboard pattern
84-
gem.initialize(Enums.GemColor.GREEN)
84+
gem.initialize(Enums.GemColor.GREEN, gemDict)
8585
if (i + j) % 2 == 0:
86-
gem.initialize(Enums.GemColor.WHITE)
86+
gem.initialize(Enums.GemColor.WHITE, gemDict)
8787
gem.get_child(1).position = Enums.SRPITE_POS

game_boards/board_food/game/game.gd

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ func on_board_match_multi(match_cnt:int):
3434
func _on_newgame_button_pressed():
3535
game_board.new_game()
3636

37+
func _on_btn_quit_game():
38+
# TODO: 20240515: convert to `signal()` for Main.tscn to hide all boards, etc.
39+
visible = false
40+
3741
func _on_btn_clear_debug_labels_pressed():
3842
game_board.debug_clear_debug_labels()
3943

game_boards/board_food/game/game.tscn

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

33
[ext_resource type="Script" path="res://game_boards/board_food/game/game.gd" id="1_ewnxx"]
44
[ext_resource type="Texture2D" uid="uid://cnlqirgwr8d4" path="res://assets/bkgd/Background.png" id="1_h8otn"]
@@ -17,6 +17,7 @@
1717
[ext_resource type="Texture2D" uid="uid://27rcw10bp2xt" path="res://assets/gui/ButtonText_Large_Green_Round.png" id="10_qtl06"]
1818
[ext_resource type="Texture2D" uid="uid://bebhmcgujnoxc" path="res://assets/gui/ButtonText_Large_GreyOutline_Round.png" id="11_bw3je"]
1919
[ext_resource type="Texture2D" uid="uid://dcow071sb2a7i" path="res://assets/gui/ButtonText_Large_Orange_Round.png" id="12_4fgvl"]
20+
[ext_resource type="Texture2D" uid="uid://chrsqb6yhlqeq" path="res://assets/gui/ButtonText_Large_Blue_Round.png" id="16_d1duj"]
2021
[ext_resource type="Theme" uid="uid://c68uhjmxln8ao" path="res://themes/game_msg_top.tres" id="17_j7spk"]
2122
[ext_resource type="Theme" uid="uid://duftrpb020ewi" path="res://themes/game_msg_btm.tres" id="18_p5dta"]
2223

@@ -369,6 +370,26 @@ text = "NEW GAME"
369370
horizontal_alignment = 1
370371
vertical_alignment = 1
371372

373+
[node name="BtnQuitGame" type="TextureButton" parent="."]
374+
offset_left = 1659.0
375+
offset_top = 696.0
376+
offset_right = 2818.0
377+
offset_bottom = 1054.0
378+
scale = Vector2(0.25, 0.25)
379+
texture_normal = ExtResource("16_d1duj")
380+
381+
[node name="Label" type="Label" parent="BtnQuitGame"]
382+
layout_mode = 1
383+
anchors_preset = 15
384+
anchor_right = 1.0
385+
anchor_bottom = 1.0
386+
grow_horizontal = 2
387+
grow_vertical = 2
388+
theme_override_font_sizes/font_size = 120
389+
text = "Quit"
390+
horizontal_alignment = 1
391+
vertical_alignment = 1
392+
372393
[node name="BtnClearDebugLabels" type="TextureButton" parent="."]
373394
visible = false
374395
offset_left = 1657.0
@@ -486,5 +507,6 @@ autowrap_mode = 0
486507
shortcut_keys_enabled = false
487508

488509
[connection signal="pressed" from="BtnNewGame" to="." method="_on_newgame_button_pressed"]
510+
[connection signal="pressed" from="BtnQuitGame" to="." method="_on_btn_quit_game"]
489511
[connection signal="pressed" from="BtnClearDebugLabels" to="." method="_on_btn_clear_debug_labels_pressed"]
490512
[connection signal="pressed" from="BtnMatchCol" to="." method="_on_btn_make_vert_pressed"]

game_boards/board_food/game_board/Board.gd

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func _ready():
2727
randomize()
2828
# A: populate board
2929
CmnFunc.fill_grid(hbox_container, grid_container)
30-
CmnFunc.fill_hbox(hbox_container, self._on_cell_click)
30+
CmnFunc.fill_hbox(hbox_container, Enums.GemDict.FOOD, self._on_cell_click)
3131
# B: check board after init
3232
process_game_round()
3333

@@ -103,8 +103,8 @@ func swap_gem_cells(swap_cell_1:CommonGemCell, swap_cell_2:CommonGemCell):
103103
# C: logially swap
104104
var gem_cell_1 = swap_cell_1.gem_color
105105
var gem_cell_2 = swap_cell_2.gem_color
106-
swap_cell_1.initialize(gem_cell_2)
107-
swap_cell_2.initialize(gem_cell_1)
106+
swap_cell_1.initialize(gem_cell_2, Enums.GemDict.FOOD)
107+
swap_cell_2.initialize(gem_cell_1, Enums.GemDict.FOOD)
108108
#debug_print_ascii_table([swap_cell_1,swap_cell_2])
109109

110110
# D: get position to restore to after move so tween sets/flows smoothly

game_boards/board_space/game_board/GemBoard.gd

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func _ready():
2727
randomize()
2828
# A: populate board
2929
CmnFunc.fill_grid(hbox_container, grid_container)
30-
CmnFunc.fill_hbox(hbox_container, self._on_cell_click)
30+
CmnFunc.fill_hbox(hbox_container, Enums.GemDict.GEMS, self._on_cell_click)
3131
# B: check board after init
3232
process_game_round()
3333

@@ -103,8 +103,8 @@ func swap_gem_cells(swap_cell_1:CommonGemCell, swap_cell_2:CommonGemCell):
103103
# C: logially swap
104104
var gem_cell_1 = swap_cell_1.gem_color
105105
var gem_cell_2 = swap_cell_2.gem_color
106-
swap_cell_1.initialize(gem_cell_2)
107-
swap_cell_2.initialize(gem_cell_1)
106+
swap_cell_1.initialize(gem_cell_2, Enums.GemDict.GEMS)
107+
swap_cell_2.initialize(gem_cell_1, Enums.GemDict.GEMS)
108108

109109
# D: get position to restore to after move so tween sets/flows smoothly
110110
var orig_pos_cell_1 = swap_cell_1.sprite.global_position
@@ -286,8 +286,10 @@ func signal_game_props_count_gems():
286286
# Emit signal with the updated gems dictionary
287287
emit_signal("props_updated_gemsdict", gems_dict)
288288

289+
# === Following are for buttons that arent on Food-Board
290+
289291
func debug_make_gem_grid():
290-
CmnDbg.debug_make_gem_grid(hbox_container)
292+
CmnDbg.debug_make_gem_grid(hbox_container, Enums.GemDict.GEMS)
291293
signal_game_props_count_gems()
292294

293295
func debug_clear_debug_labels():

0 commit comments

Comments
 (0)