39 lines
891 B
GDScript3
39 lines
891 B
GDScript3
extends Node
|
|
|
|
signal color_set(color, max_hits) # emitted at start to broadcast the color to children
|
|
signal brick_hit() # emitted when block is hit but not broken
|
|
signal brick_broken(score)
|
|
|
|
# Declare member variables here.
|
|
export var score = 100
|
|
export var max_hits = 1
|
|
export var color = 0
|
|
var nb_hits = 0
|
|
var is_hit = false
|
|
var broken = false
|
|
|
|
# Called when the node enters the scene tree for the first time.
|
|
func _ready():
|
|
emit_signal("color_set", color, max_hits)
|
|
|
|
|
|
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
|
#func _process(delta):
|
|
# pass
|
|
|
|
func hit():
|
|
nb_hits = nb_hits + 1
|
|
if (nb_hits < max_hits):
|
|
emit_signal("brick_hit")
|
|
else:
|
|
broken = true
|
|
emit_signal("brick_broken", score)
|
|
queue_free()
|
|
|
|
func is_broken():
|
|
return broken
|
|
|
|
|
|
func _on_brick_broken(_score):
|
|
pass # Replace with function body.
|