add piece scene

This commit is contained in:
Fabien Freling 2019-11-22 13:38:50 +01:00
parent 5503d1e735
commit 8a987c0b63
5 changed files with 48 additions and 18 deletions

View file

@ -1,15 +1,26 @@
extends Node2D
class_name Taquin
tool
# Declare member variables here. Examples:
# var a = 2
# var b = "text"
export var rows: int = 4
export var columns: int = 4
export var width: int = 512
export var height: int = 512
# Called when the node enters the scene tree for the first time.
func _ready():
pass # Replace with function body.
var pieces: Array = []
# Called every frame. 'delta' is the elapsed time since the previous frame.
#func _process(delta):
# pass
func _draw() -> void:
draw_rect(Rect2(0, 0, width, height), Color.blue)
func _ready() -> void:
for r in range(rows):
for c in range(columns):
if r == rows - 1 && c == columns - 1:
continue
var piece = Piece.new()
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.translate(initial_position)
add_child(piece)
pieces.append(piece)