37 lines
854 B
GDScript
37 lines
854 B
GDScript
extends Node2D
|
|
|
|
@onready var spawnpoint = $Spawnpoint
|
|
|
|
var nextBlocks = []
|
|
|
|
# Called when the node enters the scene tree for the first time.
|
|
func _ready() -> void:
|
|
fillNextBlocks()
|
|
spawnBlock()
|
|
|
|
func spawnBlock() -> void:
|
|
var block = nextBlocks[0]
|
|
GLOBAL.currentBlock = block
|
|
spawnpoint.add_child(block)
|
|
nextBlocks.pop_at(0)
|
|
if nextBlocks.size() < 2:
|
|
fillNextBlocks()
|
|
|
|
|
|
func _physics_process(delta: float) -> void:
|
|
if GLOBAL.currentBlock != null:
|
|
if GLOBAL.currentBlock.stopped:
|
|
spawnBlock()
|
|
|
|
|
|
func fillNextBlocks():
|
|
var newBlocks = []
|
|
for i in GLOBAL.BLOCKS:
|
|
var block = load(GLOBAL.BLOCKS[i]).instantiate()
|
|
block.setId(GLOBAL.getNewId())
|
|
block.setType(GLOBAL.BLOCKTYPES.LIGHT)
|
|
newBlocks.append(block)
|
|
newBlocks.shuffle()
|
|
newBlocks[0].setType(GLOBAL.BLOCKTYPES.HEAVY)
|
|
newBlocks.shuffle()
|
|
nextBlocks.append_array(newBlocks)
|