Second Prototype

This commit is contained in:
Exobyt 2024-08-18 21:59:35 +02:00
parent 885351b624
commit 632eeddc64
60 changed files with 680 additions and 1013 deletions

View file

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

View file

@ -1,13 +1,18 @@
extends Node2D
@onready var spawnpoint = $Spawnpoint
@onready var blocks = $Blocks
@onready var tickerTimer = $Ticker
@onready var patterns = $Patterns
@onready var turnTickTimer = $TurnTick
var nextBlocks = []
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
fillNextBlocks()
spawnBlock()
var currentPattern = null
var patternsArray = []
var blockSpeed = 0.4
func spawnBlock() -> void:
var block = nextBlocks[0]
@ -17,11 +22,37 @@ func spawnBlock() -> void:
if nextBlocks.size() < 2:
fillNextBlocks()
func _ready() -> void:
tickerTimer.start(blockSpeed)
getNewPatterns()
PlacePattern()
func _physics_process(delta: float) -> void:
if GLOBAL.currentBlock != null:
if GLOBAL.currentBlock.stopped:
spawnBlock()
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_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("left"):
moveUidGroup(GLOBAL.Direction.LEFT, GLOBAL.currentUID)
if Input.is_action_just_pressed("right"):
moveUidGroup(GLOBAL.Direction.RIGHT, GLOBAL.currentUID)
func fillNextBlocks():
@ -35,3 +66,142 @@ func fillNextBlocks():
newBlocks[0].setType(GLOBAL.BLOCKTYPES.HEAVY)
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 = {}
for i in blocks.get_children():
if not blockLists.has(i.UID):
blockLists[i.UID] = []
blockLists[i.UID].append(i)
return blockLists
func getBlockedDirection(direction : GLOBAL.Direction, uid : int) -> bool:
#var blockslist = getBlockGroupsList()
var isBlocked = false
#print(getBlockGroupsList())
if getBlockGroupsList().has(uid):
for i in getBlockGroupsList()[uid]:
if i.getCollider(direction) != null:
if i.getCollider(direction).is_in_group("Block"):
if i.getCollider(direction).UID != i.UID:
isBlocked = true
else:
isBlocked = true
return isBlocked
return true
func splitOphansUID(uid):
var compareList = {}
#print(uid)
#print(getBlockGroupsList()[uid])
var group = []
for i in getBlockGroupsList()[uid]:
compareList[i] = i.getNeighboursUID(uid)
#if i.getNeighboursUID(uid) == []:
# i.UID = GLOBAL.getNewUID()
#print(i.getNeighboursUID(uid))
if i.getNeighboursUID(uid) == []:
i.UID = GLOBAL.getNewUID()
for i in compareList:
group.insert(0, compareList[i])
group[0].append(i)
for j in group[0]:
if compareList[i].has(j) and not group[0].has(j):
group[0].append(j)
for i in group:
var newUID = GLOBAL.getNewUID()
for j in i:
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()
func PlacePattern():
patternsArray.pop_at(0)
for child in patterns.get_children():
child.queue_free()
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)
for i in patterns.get_children():
i.reset(Vector2())
if currentPattern != null:
for i in currentPattern.getPositions():
var block = load("res://scenes/Blocks/block.tscn").instantiate()
block.UID = newUID
block.modulate = newColor
block.position = spawnpoint.position + i.position
if i.turningPoint:
block.turningPoint = true
blocks.add_child(block)
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.shuffle()
patternsArray.append_array(newPatterns)
func turnBlocks():
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)
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)
if getBlockedDirection(GLOBAL.Direction.BOTTOM, GLOBAL.currentUID):
PlacePattern()
#print(getBlockGroupsList())
#print(getBlockGroupsList()[3])
#for i in getBlockGroupsList():
# splitOphansUID(i)
for i in getBlockGroupsList():
moveUidGroup(GLOBAL.Direction.BOTTOM, i)
tickerTimer.start(blockSpeed)

View file

@ -42,14 +42,13 @@ shape = SubResource("RectangleShape2D_flipi")
[node name="Bottom" parent="." instance=ExtResource("5_14njh")]
position = Vector2(320, 1312)
collision_layer = 8
collision_mask = 4
collision_mask = 2
[node name="CollisionShape2D" parent="Bottom" index="0"]
shape = SubResource("RectangleShape2D_rxd0s")
[node name="Spawnpoint" type="Marker2D" parent="."]
position = Vector2(320, -64)
position = Vector2(256, -128)
[node name="RowTests" type="Node2D" parent="."]
@ -113,6 +112,17 @@ position = Vector2(0, 96)
[node name="rowTest20" parent="RowTests" instance=ExtResource("4_si3v6")]
position = Vector2(0, 32)
[node name="Ticker" type="Timer" parent="."]
[node name="Patterns" type="Node2D" parent="."]
[node name="TurnTick" type="Timer" parent="."]
wait_time = 0.1
one_shot = true
[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="Bottom"]

View file

@ -1,7 +1,10 @@
extends Area2D
func _physics_process(delta: float) -> void:
if get_overlapping_areas().size() == 10 and GLOBAL.currentBlock.stopped:
for i in get_overlapping_areas():
GLOBAL.points += i.points
i.queue_free()#get_parent().get_parent().split()
#func _physics_process(delta: float) -> void:
#if get_overlapping_areas().size() == 10:
#for i in get_overlapping_areas():
#GLOBAL.points += i.points
#i.queue_free()#get_parent().get_parent().split()
func getRow():
return get_overlapping_areas()

View file

@ -7,4 +7,3 @@ func _physics_process(delta: float) -> void:
if Input.is_action_just_pressed("stop"):
GLOBAL.hasSelectedSpeed = true
GLOBAL.currentSpeed = GLOBAL.SPEED.MAX
print()