diff --git a/game/project.godot b/game/project.godot index c456e2d..1c56468 100644 --- a/game/project.godot +++ b/game/project.godot @@ -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] diff --git a/game/src/Piece.gd b/game/src/Piece.gd new file mode 100644 index 0000000..027692f --- /dev/null +++ b/game/src/Piece.gd @@ -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) \ No newline at end of file diff --git a/game/src/Piece.tscn b/game/src/Piece.tscn new file mode 100644 index 0000000..9c185d8 --- /dev/null +++ b/game/src/Piece.tscn @@ -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 ) diff --git a/game/src/Taquin.gd b/game/src/Taquin.gd index 7073b85..c56f386 100644 --- a/game/src/Taquin.gd +++ b/game/src/Taquin.gd @@ -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) \ No newline at end of file diff --git a/game/src/Taquin.tscn b/game/src/Taquin.tscn index 6eebea6..7c06060 100644 --- a/game/src/Taquin.tscn +++ b/game/src/Taquin.tscn @@ -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 )