put a number on each piece
This commit is contained in:
parent
abaa1f0991
commit
0fe5cca646
|
@ -3,6 +3,13 @@ class_name Piece
|
|||
tool
|
||||
|
||||
export var size: int = 64
|
||||
var number: int = 0
|
||||
|
||||
func _draw() -> void:
|
||||
draw_rect(Rect2(0, 0, size, size), Color.yellow)
|
||||
|
||||
func set_number(num: int) -> void:
|
||||
number = num
|
||||
|
||||
func _ready() -> void:
|
||||
$Label.text = str(number)
|
||||
|
|
|
@ -2,5 +2,11 @@
|
|||
|
||||
[ext_resource path="res://src/Piece.gd" type="Script" id=1]
|
||||
|
||||
[node name="Node2D" type="Node2D"]
|
||||
[node name="Piece" type="Node2D"]
|
||||
script = ExtResource( 1 )
|
||||
|
||||
[node name="Label" type="Label" parent="."]
|
||||
margin_right = 40.0
|
||||
margin_bottom = 14.0
|
||||
custom_colors/font_color = Color( 0, 0, 0, 1 )
|
||||
text = "!"
|
||||
|
|
|
@ -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,10 +20,12 @@ 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:
|
||||
|
@ -31,4 +35,5 @@ func _ready() -> void:
|
|||
|
||||
add_child(piece)
|
||||
pieces_row.append(piece)
|
||||
|
||||
pieces.append(pieces_row)
|
|
@ -2,5 +2,5 @@
|
|||
|
||||
[ext_resource path="res://src/Taquin.gd" type="Script" id=1]
|
||||
|
||||
[node name="Node2D" type="Node2D"]
|
||||
[node name="Taquin" type="Node2D"]
|
||||
script = ExtResource( 1 )
|
||||
|
|
Loading…
Reference in a new issue