Ok, well, this should kind of work, except you can end up with a situation where it's all of the same shapes...
extends Node2D
export (int) var width = 5;
export (int) var height = 1;
export (int) var x_start = 420;
export (int) var y_start = 270;
export (int) var offset = 48;
var possible_pieces = [
preload("res://Scenes/piece_1.tscn"),
preload("res://Scenes/piece_2.tscn"),
preload("res://Scenes/piece_3.tscn"),
preload("res://Scenes/piece_4.tscn"),
preload("res://Scenes/piece_5.tscn")
];
var all_pieces = [];
# Called when the node enters the scene tree for the first time.
func _ready():
randomize();
spawn_pieces();
func spawn_pieces():
var rand
var piece
for i in width:
if i < 2:
for j in height:
rand = floor(rand_range(0, possible_pieces.size()));
piece = possible_pieces[rand].instance();
self.add_child(piece);
piece.position = grid_to_pixel(i, j);
elif i >= 2:
for j in height:
piece = possible_pieces[rand].instance();
self.add_child(piece);
piece.position = grid_to_pixel(i, j);
func grid_to_pixel(column, row):
var new_x = x_start + offset * column;
var new_y = y_start + -offset *row;
return Vector2(new_x, new_y);
edit: oh, and the first one is always the correct answer...