26 lines
652 B
GDScript3
26 lines
652 B
GDScript3
|
|
class_name SM extends Node2D
|
||
|
|
@onready var game: Node2D = $".."
|
||
|
|
@onready var cube_container: Node2D = $"../cube container"
|
||
|
|
|
||
|
|
|
||
|
|
func _ready() -> void:
|
||
|
|
print("hey it's working!")
|
||
|
|
game.destroySignal.connect(destroy)
|
||
|
|
buildLevel()
|
||
|
|
func buildLevel()->void:
|
||
|
|
updateCube()
|
||
|
|
func destroy(body)->void:
|
||
|
|
if body is Cube:
|
||
|
|
body.queue_free()
|
||
|
|
func updateCube()->void:
|
||
|
|
# make sure there are crates
|
||
|
|
var _CubeTotal:int= 0
|
||
|
|
if cube_container:
|
||
|
|
for obj in cube_container.get_children():
|
||
|
|
if obj is Cube:
|
||
|
|
if not obj.tree_exited.is_connected(updateCube):
|
||
|
|
obj.tree_exited.connect(updateCube)
|
||
|
|
_CubeTotal +=1
|
||
|
|
print ("Number of cubes: "+str(_CubeTotal))
|
||
|
|
|