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

@ -1,5 +1,6 @@
[gd_scene format=3 uid="uid://bm7rshwf6pjb"]
[node name="Border" type="Area2D"]
collision_mask = 16
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]

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

View file

@ -11,7 +11,7 @@
size = Vector2(128, 1536)
[sub_resource type="RectangleShape2D" id="RectangleShape2D_rxd0s"]
size = Vector2(896, 64)
size = Vector2(896, 128)
[node name="Grid" type="Node2D"]
script = ExtResource("1_vie5m")
@ -28,25 +28,6 @@ mesh = SubResource("QuadMesh_qfjsc")
[node name="Blocks" type="Node2D" parent="."]
[node name="Border" parent="." instance=ExtResource("4_3j08q")]
[node name="CollisionShape2D" parent="Border" index="0"]
position = Vector2(-64, 512)
shape = SubResource("RectangleShape2D_flipi")
[node name="Border2" parent="." instance=ExtResource("4_3j08q")]
[node name="CollisionShape2D" parent="Border2" index="0"]
position = Vector2(704, 512)
shape = SubResource("RectangleShape2D_flipi")
[node name="Bottom" parent="." instance=ExtResource("5_14njh")]
position = Vector2(320, 1312)
collision_mask = 2
[node name="CollisionShape2D" parent="Bottom" index="0"]
shape = SubResource("RectangleShape2D_rxd0s")
[node name="Spawnpoint" type="Marker2D" parent="."]
position = Vector2(256, -128)
@ -115,14 +96,37 @@ position = Vector2(0, 32)
[node name="Ticker" type="Timer" parent="."]
[node name="Patterns" type="Node2D" parent="."]
position = Vector2(256, -128)
[node name="TurnTick" type="Timer" parent="."]
wait_time = 0.1
one_shot = true
[node name="Borders" type="Node2D" parent="."]
[node name="Border" parent="Borders" instance=ExtResource("4_3j08q")]
[node name="CollisionShape2D" parent="Borders/Border" index="0"]
position = Vector2(-64, 512)
shape = SubResource("RectangleShape2D_flipi")
[node name="Border2" parent="Borders" instance=ExtResource("4_3j08q")]
[node name="CollisionShape2D" parent="Borders/Border2" index="0"]
position = Vector2(704, 512)
shape = SubResource("RectangleShape2D_flipi")
[node name="Bottom" parent="." instance=ExtResource("5_14njh")]
position = Vector2(320, 1312)
collision_mask = 2
[node name="CollisionShape2D" parent="Bottom" index="0"]
position = Vector2(0, 32)
shape = SubResource("RectangleShape2D_rxd0s")
[connection signal="timeout" from="Ticker" to="." method="_on_ticker_timeout"]
[connection signal="timeout" from="TurnTick" to="." method="_on_turn_tick_timeout"]
[editable path="Border"]
[editable path="Border2"]
[editable path="Borders/Border"]
[editable path="Borders/Border2"]
[editable path="Bottom"]

View file

@ -8,3 +8,16 @@ extends Area2D
func getRow():
return get_overlapping_areas()
func isCompleted():
var amount = 0
for i in get_overlapping_areas():
if i.get_scale() == Vector2(2,2):
amount += 2
else:
amount += 1
if amount >= 10:
return true
else:
return false