taqin/src/Piece.gd

40 lines
1.5 KiB
GDScript
Raw Permalink Normal View History

2020-01-12 18:51:07 +01:00
tool
2019-11-22 13:38:50 +01:00
class_name Piece
2020-02-23 23:08:16 +01:00
extends Node2D
2019-11-22 13:38:50 +01:00
2019-12-03 13:50:42 +01:00
export var size: int = 160
2020-06-10 17:15:33 +02:00
export var texture: Texture
2019-12-03 13:50:42 +01:00
2020-02-13 13:38:07 +01:00
var order: int = 0
2020-05-24 17:14:51 +02:00
var taquin_original_index := Vector2.ZERO
var taquin_original_position := Vector2.ZERO
var taquin_current_index := Vector2.ZERO # place inside the taquin as indices (i, j)
var taquin_current_position := Vector2.ZERO # place inside the taquin as coordinates (x, y)
# position inside the original taquin as normalized coordinates (x, y) (domain: [0, 1])
# used for offsetting the texture on pieces
var taquin_original_normalized_position := Vector2.ZERO
2020-02-13 13:38:07 +01:00
var piece_scale := Vector2(0.25, 0.25)
2019-11-25 01:16:06 +01:00
func _ready() -> void:
2019-12-03 13:50:42 +01:00
$ColorRect.rect_size = Vector2(size, size)
2020-02-13 13:38:07 +01:00
$ColorRect/Label.text = str(order)
2019-11-27 13:55:08 +01:00
2019-11-27 22:25:07 +01:00
# We need a dedicated material to have separate uniform,
# otherwise uniforms will be shared.
var mat = $ColorRect.material.duplicate() as ShaderMaterial
2020-06-10 17:15:33 +02:00
mat.set_shader_param("artwork", texture) # TODO: make it common to all pieces
2019-11-27 22:25:07 +01:00
mat.set_shader_param("scale", Vector3(piece_scale.x, piece_scale.y, 1.0))
2020-05-24 17:14:51 +02:00
mat.set_shader_param("offset", Vector3(taquin_original_normalized_position.x, taquin_original_normalized_position.y, 0.0))
2020-05-18 18:48:40 +02:00
mat.set_shader_param("reflection", false)
2019-11-27 22:25:07 +01:00
$ColorRect.material = mat
2020-02-13 13:51:14 +01:00
2020-05-18 18:48:40 +02:00
func set_reflection(value: bool) -> void:
var mat = $ColorRect.material as ShaderMaterial
mat.set_shader_param("reflection", value)
2020-02-13 13:51:14 +01:00
func debug_print(name: String):
print("%s order: %s" % [name, order])
2020-05-24 17:14:51 +02:00
print("%s taquin index: %s" % [name, taquin_current_index])
2020-02-13 13:51:14 +01:00
print("%s taquin position: %s" % [name, position])