add piece scene
This commit is contained in:
parent
5503d1e735
commit
8a987c0b63
|
@ -8,9 +8,20 @@
|
||||||
|
|
||||||
config_version=4
|
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={
|
_global_script_class_icons={
|
||||||
|
"Piece": "",
|
||||||
|
"Taquin": ""
|
||||||
}
|
}
|
||||||
|
|
||||||
[application]
|
[application]
|
||||||
|
|
8
game/src/Piece.gd
Normal file
8
game/src/Piece.gd
Normal 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
6
game/src/Piece.tscn
Normal 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 )
|
|
@ -1,15 +1,26 @@
|
||||||
extends Node2D
|
extends Node2D
|
||||||
|
class_name Taquin
|
||||||
|
tool
|
||||||
|
|
||||||
# Declare member variables here. Examples:
|
|
||||||
# var a = 2
|
|
||||||
# var b = "text"
|
|
||||||
export var rows: int = 4
|
export var rows: int = 4
|
||||||
export var columns: 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.
|
var pieces: Array = []
|
||||||
func _ready():
|
|
||||||
pass # Replace with function body.
|
|
||||||
|
|
||||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
func _draw() -> void:
|
||||||
#func _process(delta):
|
draw_rect(Rect2(0, 0, width, height), Color.blue)
|
||||||
# pass
|
|
||||||
|
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)
|
|
@ -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]
|
[ext_resource path="res://src/Taquin.gd" type="Script" id=1]
|
||||||
|
|
||||||
[sub_resource type="NoiseTexture" id=1]
|
|
||||||
|
|
||||||
[node name="Node2D" type="Node2D"]
|
[node name="Node2D" type="Node2D"]
|
||||||
script = ExtResource( 1 )
|
script = ExtResource( 1 )
|
||||||
|
|
||||||
[node name="Sprite" type="Sprite" parent="."]
|
|
||||||
position = Vector2( 511, 311 )
|
|
||||||
texture = SubResource( 1 )
|
|
||||||
|
|
Loading…
Reference in a new issue