35 lines
835 B
GDScript3
35 lines
835 B
GDScript3
extends Sprite
|
|
|
|
|
|
# Declare member variables here.
|
|
export var width = 64
|
|
export var height = 64
|
|
export var nb_lines = 2
|
|
export var nb_columns = 1
|
|
var col = 0
|
|
var hit = 0
|
|
var nb_hits = 1
|
|
|
|
# Called when the node enters the scene tree for the first time.
|
|
func _ready():
|
|
pass # Replace with function body.
|
|
|
|
|
|
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
|
#func _process(delta):
|
|
# pass
|
|
|
|
func _on_color_set(color, max_hits):
|
|
col = color
|
|
nb_hits = max_hits
|
|
self.texture.region.position = computeRegionPosition()
|
|
|
|
func _on_brick_hit():
|
|
hit = hit + 1
|
|
self.texture.region.position = computeRegionPosition()
|
|
|
|
func computeRegionPosition():
|
|
var x = (col % nb_columns) + (nb_columns * (nb_hits - 1 - hit))
|
|
var y = (col / nb_columns) % nb_lines
|
|
return Vector2(width * x, height * y)
|