add piece scene

master
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

@ -8,9 +8,20 @@
config_version=4
_global_script_classes=[ ]
_global_script_classes=[ {
"base": "Node2D",
"class": "Piece",
"language": "GDScript",
"path": "res://src/Piece.gd"
}, {
"base": "Node2D",
"class": "Taquin",
"language": "GDScript",
"path": "res://src/Taquin.gd"
} ]
_global_script_class_icons={
"Piece": "",
"Taquin": ""
}
[application]

8
game/src/Piece.gd Normal file
View File

@ -0,0 +1,8 @@
extends Node2D
class_name Piece
tool
export var size: int = 64
func _draw() -> void:
draw_rect(Rect2(0, 0, size, size), Color.yellow)

6
game/src/Piece.tscn Normal file
View File

@ -0,0 +1,6 @@
[gd_scene load_steps=2 format=2]
[ext_resource path="res://src/Piece.gd" type="Script" id=1]
[node name="Node2D" type="Node2D"]
script = ExtResource( 1 )

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)

View File

@ -1,12 +1,6 @@
[gd_scene load_steps=3 format=2]
[gd_scene load_steps=2 format=2]
[ext_resource path="res://src/Taquin.gd" type="Script" id=1]
[sub_resource type="NoiseTexture" id=1]
[node name="Node2D" type="Node2D"]
script = ExtResource( 1 )
[node name="Sprite" type="Sprite" parent="."]
position = Vector2( 511, 311 )
texture = SubResource( 1 )