Second Prototype
This commit is contained in:
parent
885351b624
commit
632eeddc64
60 changed files with 680 additions and 1013 deletions
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue