FaC random placement
This commit is contained in:
parent
3232182a9f
commit
dbdb9a7bf2
10 changed files with 106 additions and 7 deletions
|
|
@ -29,8 +29,15 @@ vertical_alignment = 1
|
|||
justification_flags = 162
|
||||
|
||||
[node name="GridContainer" parent="ColorRect" instance=ExtResource("1_85msg")]
|
||||
layout_mode = 0
|
||||
offset_left = 515.0
|
||||
offset_top = 217.0
|
||||
offset_right = 765.0
|
||||
offset_bottom = 467.0
|
||||
layout_mode = 1
|
||||
anchors_preset = 8
|
||||
anchor_left = 0.5
|
||||
anchor_top = 0.5
|
||||
anchor_right = 0.5
|
||||
anchor_bottom = 0.5
|
||||
offset_left = -125.0
|
||||
offset_top = -125.0
|
||||
offset_right = 125.0
|
||||
offset_bottom = 125.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
|
|
|
|||
67
scenes/find_a_couple/tile_grid.gd
Normal file
67
scenes/find_a_couple/tile_grid.gd
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
extends GridContainer
|
||||
|
||||
@export var pair_count: int = 3 # Количество пар
|
||||
@export var tile_textures: Array[Texture2D] # Массив изображений
|
||||
@export var tile_size: Vector2 = Vector2(100, 100)
|
||||
|
||||
var tiles_array: Array = []
|
||||
|
||||
func _ready() -> void:
|
||||
generate_tiles()
|
||||
|
||||
func generate_tiles():
|
||||
# Очищаем предыдущие плитки
|
||||
for child in get_children():
|
||||
child.queue_free()
|
||||
tiles_array.clear()
|
||||
|
||||
# Проверяем достаточно ли изображений
|
||||
if tile_textures.size() < pair_count:
|
||||
push_error("Not enough textures for pairs! Need: ", pair_count, ", Have: ", tile_textures.size())
|
||||
return
|
||||
|
||||
# Создаем пары индексов
|
||||
var pairs_indices = create_pairs_indices()
|
||||
|
||||
# Перемешиваем порядок
|
||||
pairs_indices.shuffle()
|
||||
|
||||
# Настраиваем GridContainer
|
||||
setup_grid_container(pairs_indices.size())
|
||||
|
||||
# Создаем плитки
|
||||
for i in range(pairs_indices.size()):
|
||||
var texture_index = pairs_indices[i]
|
||||
var tile = preload("res://scenes/find_a_couple/tile_btn.tscn").instantiate()
|
||||
|
||||
# Передаем данные в плитку
|
||||
tile.front_texture = tile_textures[texture_index]
|
||||
tile.back_texture = preload("res://assets/find_a_couple/back.png") # Рубашка
|
||||
tile.tile_id = texture_index # ID для сравнения пар
|
||||
tile.custom_minimum_size = tile_size
|
||||
|
||||
#tile.tile_clicked.connect(_on_tile_clicked)
|
||||
add_child(tile)
|
||||
tiles_array.append(tile)
|
||||
|
||||
func create_pairs_indices() -> Array:
|
||||
var indices = []
|
||||
# Создаем пары (каждое изображение повторяется 2 раза)
|
||||
for i in range(pair_count):
|
||||
indices.append(i)
|
||||
indices.append(i)
|
||||
return indices
|
||||
|
||||
func setup_grid_container(total_tiles: int):
|
||||
# Вычисляем оптимальное количество колонок
|
||||
columns = ceil(sqrt(total_tiles))
|
||||
|
||||
# Вычисляем количество строк
|
||||
var rows = ceil(float(total_tiles) / columns)
|
||||
|
||||
# Устанавливаем минимальный размер контейнера
|
||||
custom_minimum_size = Vector2(columns * tile_size.x, rows * tile_size.y)
|
||||
|
||||
#func _on_tile_clicked(clicked_tile):
|
||||
# Логика обработки клика на плитке
|
||||
#process_tile_click(clicked_tile)
|
||||
1
scenes/find_a_couple/tile_grid.gd.uid
Normal file
1
scenes/find_a_couple/tile_grid.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://c2427cp8ana1g
|
||||
|
|
@ -1,11 +1,17 @@
|
|||
[gd_scene load_steps=2 format=3 uid="uid://exbrdfhk0bou"]
|
||||
[gd_scene load_steps=6 format=3 uid="uid://exbrdfhk0bou"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://c2427cp8ana1g" path="res://scenes/find_a_couple/tile_grid.gd" id="1_j4vmv"]
|
||||
[ext_resource type="PackedScene" uid="uid://lu353vx1qhnw" path="res://scenes/find_a_couple/tile_btn.tscn" id="1_l5jho"]
|
||||
[ext_resource type="Texture2D" uid="uid://bsj2xqsrkncfw" path="res://assets/find_a_couple/envelope.png" id="2_ey8fv"]
|
||||
[ext_resource type="Texture2D" uid="uid://dkhosb3l014nu" path="res://assets/find_a_couple/home.png" id="2_j4vmv"]
|
||||
[ext_resource type="Texture2D" uid="uid://bakxisrbvoy3e" path="res://assets/find_a_couple/user.png" id="4_0oft7"]
|
||||
|
||||
[node name="GridContainer" type="GridContainer"]
|
||||
theme_override_constants/h_separation = 50
|
||||
theme_override_constants/v_separation = 50
|
||||
columns = 2
|
||||
script = ExtResource("1_j4vmv")
|
||||
tile_textures = Array[Texture2D]([ExtResource("2_ey8fv"), ExtResource("2_j4vmv"), ExtResource("4_0oft7")])
|
||||
|
||||
[node name="TextureButton" parent="." instance=ExtResource("1_l5jho")]
|
||||
custom_minimum_size = Vector2(100, 100)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue