breadth-first traversal of grid is working!
an array of token groups is calculated successfully and it's probably fast enough.
This commit is contained in:
20
grid.gd
20
grid.gd
@@ -21,9 +21,13 @@ func _ready():
|
||||
var token_node = token.instantiate()
|
||||
add_child(token_node)
|
||||
token_node.position = Vector2(offset*column, offset*row)
|
||||
token_node.set_type(randi_range(0,3 ))
|
||||
token_node.set_debug_label(str(row) + "," + str(column))
|
||||
grid[row].append(token_node)
|
||||
|
||||
|
||||
func _process(_delta: float) -> void:
|
||||
if Input.is_action_just_pressed("activate"):
|
||||
calculate_token_groups()
|
||||
|
||||
func populate_grid():
|
||||
@@ -54,14 +58,20 @@ func calculate_token_groups():
|
||||
visited_nodes.append(current_coord)
|
||||
|
||||
var adjacent_token_coords = [
|
||||
[row - 1, col],
|
||||
[row, col + 1],
|
||||
[row + 1, col],
|
||||
[row, col - 1]
|
||||
[current_coord[0] - 1, current_coord[1]],
|
||||
[current_coord[0], current_coord[1] + 1],
|
||||
[current_coord[0] + 1, current_coord[1]],
|
||||
[current_coord[0], current_coord[1] - 1]
|
||||
]
|
||||
|
||||
var valid_coords = adjacent_token_coords.filter(
|
||||
func(coord_pair): return coord_pair[0] >= 0 and coord_pair[0] < rows and coord_pair[1] >= 0 and coord_pair[1] < cols
|
||||
func(coord_pair):
|
||||
return (
|
||||
coord_pair[0] >= 0 and
|
||||
coord_pair[0] < rows and
|
||||
coord_pair[1] >= 0 and
|
||||
coord_pair[1] < cols
|
||||
)
|
||||
)
|
||||
|
||||
for coord in valid_coords:
|
||||
|
||||
@@ -14,3 +14,16 @@ config/name="combo-car"
|
||||
run/main_scene="uid://bai2mcthexgm5"
|
||||
config/features=PackedStringArray("4.4", "GL Compatibility")
|
||||
config/icon="res://icon.svg"
|
||||
|
||||
[input]
|
||||
|
||||
activate={
|
||||
"deadzone": 0.2,
|
||||
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":32,"key_label":0,"unicode":32,"location":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
|
||||
[rendering]
|
||||
|
||||
renderer/rendering_method="gl_compatibility"
|
||||
renderer/rendering_method.mobile="gl_compatibility"
|
||||
|
||||
6
token.gd
6
token.gd
@@ -10,8 +10,10 @@ var debug_label: Label
|
||||
func _ready():
|
||||
color_polygon = $Color
|
||||
debug_label = $"Debug Label"
|
||||
type = randi_range(0, 3) as token_type
|
||||
match type:
|
||||
|
||||
func set_type(type: token_type):
|
||||
self.type = type
|
||||
match self.type:
|
||||
token_type.TYPE_1:
|
||||
color_polygon.color = Color.RED
|
||||
token_type.TYPE_2:
|
||||
|
||||
Reference in New Issue
Block a user