put a number on each piece

This commit is contained in:
Fabien Freling 2019-11-25 01:16:06 +01:00
parent abaa1f0991
commit 0fe5cca646
4 changed files with 23 additions and 5 deletions

View file

@ -2,6 +2,8 @@ extends Node2D
class_name Taquin
tool
var Piece = preload("res://src/Piece.tscn")
export var rows: int = 4
export var columns: int = 4
export var width: int = 512
@ -18,17 +20,20 @@ func _ready() -> void:
var pieces_row: Array = []
for r in range(rows):
var piece = Piece.new()
var piece = Piece.instance()
var padding_w = (width - (piece.size * columns)) / (columns + 1)
var padding_h = (height - (piece.size * rows)) / (rows + 1)
var initial_position = Vector2(padding_w + c * (piece.size + padding_w), padding_h + r * (piece.size + padding_h))
piece.set_number(1 + c + r * columns)
piece.translate(initial_position)
if r == rows - 1 && c == columns - 1:
piece.visible = false
missing_piece.x = c
missing_piece.y = r
add_child(piece)
pieces_row.append(piece)
pieces.append(pieces_row)