Fixed many Bugy and added Labels for Time and Score

This commit is contained in:
Exobyt 2024-08-20 00:34:24 +02:00
parent 632eeddc64
commit ee5e17c3e0
14 changed files with 430 additions and 179 deletions

View file

@ -12,7 +12,9 @@ var currentPattern = null
var patternsArray = []
var blockSpeed = 0.4
var blockSpeed = 0.5
var stopped = false
func spawnBlock() -> void:
var block = nextBlocks[0]
@ -28,26 +30,39 @@ func _ready() -> void:
PlacePattern()
func _physics_process(delta: float) -> void:
for i in getBlockGroupsList():
if i != GLOBAL.currentUID:
moveUidGroup(GLOBAL.Direction.BOTTOM, i)
#for i in $Borders.get_children():
#for j in i.get_overlapping_areas():
#if j.is_in_group("Block"):
#if j.get_parent().UID == GLOBAL.currentUID:
#for s in getBlockGroupsList()[j.get_parent().UID]:
#s.queue_free()
#else:
#j.get_parent().queue_free()
#for i in getBlockGroupsList():
#if i != GLOBAL.currentUID:
#moveUidGroup(GLOBAL.Direction.BOTTOM, i)
var blockGroups = getBlockGroupsList()
if Input.is_action_just_pressed("rotate_right"):
for i in blockGroups[GLOBAL.currentUID]:
if i.turningPoint:
if currentPattern != null:
currentPattern.turn(GLOBAL.Direction.RIGHT,i.position + Vector2(GLOBAL.GRID/2, GLOBAL.GRID/2))
if turnTickTimer.is_stopped():
turnTickTimer.start(0.18)
if Input.is_action_just_pressed("rotate_right") and not stopped:
if blockGroups.has(GLOBAL.currentUID):
for i in blockGroups[GLOBAL.currentUID]:
if i.turningPoint:
if currentPattern != null:
currentPattern.turn(GLOBAL.Direction.RIGHT,i.position-spawnpoint.position + Vector2(GLOBAL.GRID/2, GLOBAL.GRID/2))
#turnBlocks()
if turnTickTimer.is_stopped():
turnTickTimer.start(0.3)
if Input.is_action_just_pressed("rotate_left"):
for i in blockGroups[GLOBAL.currentUID]:
if i.turningPoint:
if currentPattern != null:
currentPattern.turn(GLOBAL.Direction.LEFT,i.position + Vector2(GLOBAL.GRID/2, GLOBAL.GRID/2))
if turnTickTimer.is_stopped():
turnTickTimer.start(0.18)
if Input.is_action_just_pressed("rotate_left") and not stopped:
if blockGroups.has(GLOBAL.currentUID):
for i in blockGroups[GLOBAL.currentUID]:
if i.turningPoint:
if currentPattern != null:
currentPattern.turn(GLOBAL.Direction.LEFT,i.position-spawnpoint.position + Vector2(GLOBAL.GRID/2, GLOBAL.GRID/2))
#turnBlocks()
if turnTickTimer.is_stopped():
turnTickTimer.start(0.3)
if Input.is_action_just_pressed("left"):
moveUidGroup(GLOBAL.Direction.LEFT, GLOBAL.currentUID)
@ -67,9 +82,6 @@ func fillNextBlocks():
newBlocks.shuffle()
nextBlocks.append_array(newBlocks)
## returns a Dictionary with the UIDs as the Key and a List of the Blocks as the content
func getBlockGroupsList():
var blockLists : Dictionary = {}
@ -121,27 +133,29 @@ func splitOphansUID(uid):
j.UID = newUID
func moveUidGroup(direction, uid):
match direction:
GLOBAL.Direction.BOTTOM:
for i in getBlockGroupsList()[uid]:
if not getBlockedDirection(GLOBAL.Direction.BOTTOM, i.UID):
i.moveDown()
GLOBAL.Direction.LEFT:
for i in getBlockGroupsList()[uid]:
if not getBlockedDirection(GLOBAL.Direction.LEFT, i.UID):
i.moveLeft()
GLOBAL.Direction.RIGHT:
for i in getBlockGroupsList()[uid]:
if not getBlockedDirection(GLOBAL.Direction.RIGHT, i.UID):
i.moveRight()
if getBlockGroupsList().has(uid):
match direction:
GLOBAL.Direction.BOTTOM:
for i in getBlockGroupsList()[uid]:
if not getBlockedDirection(GLOBAL.Direction.BOTTOM, i.UID):
i.moveDown()
GLOBAL.Direction.LEFT:
for i in getBlockGroupsList()[uid]:
if not getBlockedDirection(GLOBAL.Direction.LEFT, i.UID):
i.moveLeft()
GLOBAL.Direction.RIGHT:
for i in getBlockGroupsList()[uid]:
if not getBlockedDirection(GLOBAL.Direction.RIGHT, i.UID):
i.moveRight()
func PlacePattern():
patternsArray.pop_at(0)
for child in patterns.get_children():
child.queue_free()
if patternsArray.size() <= 1:
getNewPatterns()
currentPattern = patternsArray[0]
patterns.add_child(currentPattern)
getNewPatterns()
var newUID = GLOBAL.getNewUID()
GLOBAL.currentUID = newUID
var newColor = Color.from_hsv((randi() % 12) / 12.0, 1, 1)
@ -152,8 +166,8 @@ func PlacePattern():
var block = load("res://scenes/Blocks/block.tscn").instantiate()
block.UID = newUID
block.modulate = newColor
block.position = spawnpoint.position + i.position
block.position = spawnpoint.position + i.position
block.type = currentPattern.type
if i.turningPoint:
block.turningPoint = true
blocks.add_child(block)
@ -162,10 +176,10 @@ func PlacePattern():
func getNewPatterns():
var newPatterns = []
for i in GLOBAL.BLOCKSPATTERS:
print(i)
newPatterns.append(load(GLOBAL.BLOCKSPATTERS[i]).instantiate())
newPatterns.shuffle()
#newPatterns[0].type = GLOBAL.BLOCKTYPES.HEAVY
newPatterns[0].type = GLOBAL.BLOCKTYPES.HEAVY
newPatterns[0].expand = true
newPatterns.shuffle()
patternsArray.append_array(newPatterns)
@ -178,30 +192,63 @@ func turnBlocks():
turningPointBlock = getBlockGroupsList()[GLOBAL.currentUID][g]
for g in currentPattern.getPositions():
if g.turningPoint:
turningPointBlock.global_position = g.global_position- Vector2(32,32)
turningPointBlock.global_position = g.global_position- Vector2(32,32)
func _on_turn_tick_timeout() -> void:
turnBlocks()
func _on_ticker_timeout() -> void:
for i in $RowTests.get_children():
#print(i.getRow())
#print(i.get_name(), ": ", i.getRow().size(), ": ",i.getRow())
if i.getRow().size() >= 10:
for j in i.getRow():
splitOphansUID(j.UID)
GLOBAL.points += j.type
j.queue_free()
#for i in getBlockGroupsList():
# splitOphansUID(i)
stopped = true
if getBlockedDirection(GLOBAL.Direction.BOTTOM, GLOBAL.currentUID):
PlacePattern()
#print(getBlockGroupsList())
#print(getBlockGroupsList()[3])
#for i in getBlockGroupsList():
# splitOphansUID(i)
if currentPattern.expand:
if currentPattern.get_scale() != Vector2(2,2):
for i in getBlockGroupsList()[GLOBAL.currentUID]:
if i.turningPoint:
currentPattern.set_scale(Vector2(2,2))
currentPattern.moveToPosition(i.global_position-spawnpoint.position - Vector2(64,64*4))
if await currentPattern.getCollidingBorder() != []:
currentPattern.position.y -= 64
for i in range(1,8):
if await currentPattern.getCollidingBorder() == []:
break
currentPattern.position.x -= 64
#if await currentPattern.getCollidingBorder() != []:
#currentPattern.position.y += 64
#if await currentPattern.getCollidingBorder() != []:
#currentPattern.position.x -= 64
for i in getBlockGroupsList()[GLOBAL.currentUID].size():
getBlockGroupsList()[GLOBAL.currentUID][i].global_position = currentPattern.getPositions()[i].global_position - Vector2(GLOBAL.GRID, GLOBAL.GRID)
getBlockGroupsList()[GLOBAL.currentUID][i].set_scale(Vector2(2,2))
for i in await currentPattern.getCollidingBlocks():
i.queue_free()
#for i in blocks.get_children():
#if i.get_scale() != Vector2(2,2):
#i.set_scale(Vector2(2,2))
#i.move(-64,-64)
#var turningPointBlock
#for g in currentPattern.getPositions().size():
#if not getBlockGroupsList()[GLOBAL.currentUID][g].turningPoint:
#getBlockGroupsList()[GLOBAL.currentUID][g].global_position = currentPattern.getPositions()[g].global_position- Vector2(32,32)
#else:
#turningPointBlock = getBlockGroupsList()[GLOBAL.currentUID][g]
#for g in currentPattern.getPositions():
#if g.turningPoint:
#turningPointBlock.global_position = g.global_position- Vector2(32,32)
#if i.turningPoint:
#currentPattern.global_position = i.global_position- Vector2(32,32)
for i in $RowTests.get_children():
if i.isCompleted():
for j in i.getRow():
splitOphansUID(j.UID)
GLOBAL.points += j.type
j.queue_free()
PlacePattern()
for i in getBlockGroupsList():
moveUidGroup(GLOBAL.Direction.BOTTOM, i)
tickerTimer.start(blockSpeed)
stopped = false