From ee5e17c3e0c10624165a2afb9a25c937816bda91 Mon Sep 17 00:00:00 2001 From: Exobyt Date: Tue, 20 Aug 2024 00:34:24 +0200 Subject: [PATCH] Fixed many Bugy and added Labels for Time and Score --- Theme/label.tres | 6 + project.godot | 12 +- .../Patterns/2x2/2x2_block_pattern.tscn | 1 + scenes/Blocks/Patterns/block_pattern.gd | 207 +++++++++++++----- scenes/Blocks/block.gd | 38 +--- scenes/Blocks/block.tscn | 25 ++- scenes/Globals/global.gd | 6 +- scenes/Grid/border.tscn | 1 + scenes/Grid/grid.gd | 157 ++++++++----- scenes/Grid/grid.tscn | 48 ++-- scenes/Grid/row_test.gd | 13 ++ scenes/Main/main.gd | 17 ++ scenes/Main/main.tscn | 67 +++++- scenes/Main/score_value.gd | 11 + 14 files changed, 430 insertions(+), 179 deletions(-) create mode 100644 Theme/label.tres create mode 100644 scenes/Main/main.gd create mode 100644 scenes/Main/score_value.gd diff --git a/Theme/label.tres b/Theme/label.tres new file mode 100644 index 0000000..364344d --- /dev/null +++ b/Theme/label.tres @@ -0,0 +1,6 @@ +[gd_resource type="LabelSettings" format=3 uid="uid://cd783ubpcytc8"] + +[resource] +font_size = 64 +outline_size = 10 +outline_color = Color(0, 0, 0, 1) diff --git a/project.godot b/project.godot index b87d690..d378d97 100644 --- a/project.godot +++ b/project.godot @@ -14,7 +14,7 @@ config/name="GmtkGameJam2024" config/tags=PackedStringArray("game_jam") run/main_scene="res://scenes/Main/main.tscn" config/features=PackedStringArray("4.3", "GL Compatibility") -run/max_fps=120 +run/max_fps=60 config/icon="res://icon.svg" [autoload] @@ -24,10 +24,11 @@ GLOBAL="*res://scenes/Globals/global.gd" [display] -window/size/viewport_width=440 +window/size/viewport_width=1080 window/size/viewport_height=1080 -window/stretch/aspect="keep_height" -window/stretch/scale=0.5 +window/stretch/mode="viewport" +window/stretch/aspect="expand" +window/stretch/scale=0.8 window/handheld/orientation=1 [editor] @@ -42,6 +43,7 @@ enabled=PackedStringArray("res://addons/debug_menu/plugin.cfg") [global_group] Block="Block" +ExpandBlock="" [input] @@ -95,6 +97,8 @@ locale/locale_filter_mode=0 2d_physics/layer_2="block" 2d_physics/layer_3="rowTest" 2d_physics/layer_4="TurnTest" +2d_physics/layer_5="oneBlock" +2d_physics/layer_6="expandBlock" [rendering] diff --git a/scenes/Blocks/Patterns/2x2/2x2_block_pattern.tscn b/scenes/Blocks/Patterns/2x2/2x2_block_pattern.tscn index b92458b..3b4840f 100644 --- a/scenes/Blocks/Patterns/2x2/2x2_block_pattern.tscn +++ b/scenes/Blocks/Patterns/2x2/2x2_block_pattern.tscn @@ -7,6 +7,7 @@ [node name="BlockPattern" instance=ExtResource("1_sj41y")] [node name="PositionMarker" parent="Positions" index="0" instance=ExtResource("2_csenr")] +turningPoint = true [node name="PositionMarker2" parent="Positions" index="1" instance=ExtResource("2_csenr")] position = Vector2(0, -64) diff --git a/scenes/Blocks/Patterns/block_pattern.gd b/scenes/Blocks/Patterns/block_pattern.gd index bf5a205..b06a32f 100644 --- a/scenes/Blocks/Patterns/block_pattern.gd +++ b/scenes/Blocks/Patterns/block_pattern.gd @@ -5,67 +5,113 @@ extends Node2D var lastDirection = null +var type = GLOBAL.BLOCKTYPES.LIGHT +var expand = false + func getPositions(): return positions.get_children() func checkDirection(): - var leftCollision = true - var rightCollision = true - positions.position.x = 0 - collision.position.x = 0 - if await getCollidingAreas() != []: - positions.position.x += GLOBAL.GRID - collision.position.x += GLOBAL.GRID - if await getCollidingAreas() == []: - rightCollision = false - else: - rightCollision = true - positions.position.x = 0 - collision.position.x = 0 - if await getCollidingAreas() != []: - positions.position.x -= GLOBAL.GRID - collision.position.x -= GLOBAL.GRID - if await getCollidingAreas() == []: - leftCollision = false - else: - leftCollision = true - positions.position.x = 0 - collision.position.x = 0 - if not rightCollision: - positions.position.x += GLOBAL.GRID - collision.position.x += GLOBAL.GRID - elif not leftCollision: - positions.position.x -= GLOBAL.GRID - collision.position.x -= GLOBAL.GRID - else: - positions.position.x = 0 - collision.position.x = 0 + print("xfsdfdsfd") + var leftCollision = false + var rightCollision = false -func turn(direction,newPosition): - positions.position.x = 0 - collision.position.x = 0 - position = newPosition - match direction: - GLOBAL.Direction.LEFT: - positions.rotation_degrees += 90 - collision.rotation_degrees += 90 - if await getCollidingAreas() != []: - checkDirection() - if await getCollidingAreas() != []: - positions.rotation_degrees += 90 - collision.rotation_degrees += 90 - - GLOBAL.Direction.RIGHT: - positions.rotation_degrees -= 90 - collision.rotation_degrees -= 90 - if await getCollidingAreas() != []: - checkDirection() - if await getCollidingAreas() != []: - positions.rotation_degrees -= 90 - collision.rotation_degrees -= 90 - #positions.rotation_degrees += 90 - #collision.rotation_degrees += 90 + movePattern(GLOBAL.Direction.RIGHT) + print("0: ", await isColliding()) + if await isColliding(): + movePattern(GLOBAL.Direction.LEFT) + print("1: ", await isColliding()) + #if await isColliding(): + #movePattern(GLOBAL.Direction.RIGHT, 2) + #print("2: ", await isColliding()) + #if await isColliding(): + #movePattern(GLOBAL.Direction.LEFT, 2) + #print("3: ", await isColliding()) + #if await isColliding(): + #resetPosition() + #print("4: ", await isColliding()) + #if await isColliding(): + #rightCollision = true + #resetPosition() + #movePattern(GLOBAL.Direction.LEFT) + #if await isColliding(): + #leftCollision = true + #print(" LEFT: ", leftCollision, "\n RIGHT: ", rightCollision) + #resetPosition() + #if await getCollidingAreas() != []: + #rightCollision = true + #resetPosition() + #movePattern(GLOBAL.Direction.LEFT) + #if await getCollidingAreas() != []: + #leftCollision = true + #resetPosition() + # + #if leftCollision: + #movePattern(GLOBAL.Direction.RIGHT) + #elif rightCollision: + #movePattern(GLOBAL.Direction.LEFT) + + #else: + + #resetPosition() + +func moveToPosition(newPosition): + resetPosition() + position = newPosition + +func turn(direction, newPosition): + reset(newPosition) + #moveToPosition(newPosition) + rotatePattern(direction) + + #if await isColliding(): + #print(1) + #movePattern(GLOBAL.Direction.RIGHT, 1) + #if await isColliding(): + #print(2) + #movePattern(GLOBAL.Direction.LEFT,2) + #if await isColliding(): + #print(3) + #movePattern(GLOBAL.Direction.RIGHT, 3) + #if await isColliding(): + #print(4) + #movePattern(GLOBAL.Direction.LEFT, 4) + + #if await isColliding(): + #print(1) + #movePattern(GLOBAL.Direction.RIGHT, 2) + #if await isColliding(): + #print(2) + #movePattern(GLOBAL.Direction.LEFT,4) + # + if await isColliding(): + movePattern(GLOBAL.Direction.RIGHT, 1) + if await isColliding(): + movePattern(GLOBAL.Direction.RIGHT, 1) + if await isColliding(): + movePattern(GLOBAL.Direction.LEFT,3) + if await isColliding(): + movePattern(GLOBAL.Direction.LEFT,1) + + #if await isColliding(): + #print(2) + #movePattern(GLOBAL.Direction.RIGHT, 1) + #if await isColliding(): + #print(3) + #movePattern(GLOBAL.Direction.LEFT,3) + #if await isColliding(): + #print(4) + #movePattern(GLOBAL.Direction.LEFT,1) + #if await isColliding(): + #print(3) + #movePattern(GLOBAL.Direction.LEFT, 1) + #movePattern(GLOBAL.Direction.RIGHT, 3) + #if await isColliding(): + #movePattern(GLOBAL.Direction.LEFT, 2) + if await isColliding(): + resetPosition() + func getCollidingAreas(): @@ -81,7 +127,31 @@ func getCollidingAreas(): else: collidingAreas.append(i) return collidingAreas + +func isColliding(): + return await getCollidingAreas() != [] +func getCollidingBorder(): + await get_tree().process_frame + await get_tree().process_frame + await get_tree().process_frame + await get_tree().process_frame + var collidingAreas = [] + for i in collision.get_overlapping_areas(): + if not i.is_in_group("Block"): + collidingAreas.append(i) + return collidingAreas + +func getCollidingBlocks(): + await get_tree().process_frame + await get_tree().process_frame + await get_tree().process_frame + var collidingAreas = [] + for i in collision.get_overlapping_areas(): + if i.is_in_group("Block"): + if i.UID != GLOBAL.currentUID: + collidingAreas.append(i) + return collidingAreas #func _on_collision_test_area_entered(area: Area2D) -> void: #if lastDirection == null: @@ -102,3 +172,30 @@ func reset(newPosition): positions.position.x = 0 collision.position.x = 0 rotation_degrees = 0 + +func movePattern(direction, steps = 1): + match direction: + GLOBAL.Direction.LEFT: + positions.position.x -= GLOBAL.GRID * steps + collision.position.x -= GLOBAL.GRID * steps + #print("Left") + #print(positions.position) + GLOBAL.Direction.RIGHT: + positions.position.x += GLOBAL.GRID * steps + collision.position.x += GLOBAL.GRID * steps + #print("Right") + #print(positions.position) + +func resetPosition(): + #print("RESET") + positions.position.x = 0 + collision.position.x = 0 + +func rotatePattern(direction): + match direction: + GLOBAL.Direction.LEFT: + positions.rotation_degrees += 90 + collision.rotation_degrees += 90 + GLOBAL.Direction.RIGHT: + positions.rotation_degrees -= 90 + collision.rotation_degrees -= 90 diff --git a/scenes/Blocks/block.gd b/scenes/Blocks/block.gd index 1928af9..6969e90 100644 --- a/scenes/Blocks/block.gd +++ b/scenes/Blocks/block.gd @@ -3,6 +3,7 @@ extends Area2D @onready var floorRaycast = $RaycastFloor @onready var raycastLeft = $RaycastLeft @onready var raycastRight = $RaycastRight +@onready var raycastTop = $RaycastTop @export var UID = 1 @@ -15,40 +16,6 @@ var type = GLOBAL.BLOCKTYPES.LIGHT func _ready() -> void: secretPosition = position -#func _physics_process(delta: float) -> void: - #print(secretPosition) - #print(getNeighbours()) - #print(getNeighboursUID(UID)) -# Called every frame. 'delta' is the elapsed time since the previous frame. -#func _physics_process(delta: float) -> void: - #if not getIsOnFloor(): - # position = secretPosition.snapped(Vector2(64,64)) - #if Input.is_action_just_pressed("left"): - # if not raycastLeft.is_colliding(): - # secretPosition.x -= GLOBAL.GRID - #if Input.is_action_just_pressed("right"): - # if not raycastRight.is_colliding(): - # secretPosition.x += GLOBAL.GRID - #secretPosition.y += GLOBAL.currentSpeed * delta * 30 - -func getIsOnFloor() -> bool: - return floorRaycast.is_colliding() - -#func getFloorCollider(): - #return floorRaycast.get_collider() - # -#func getLeftCollider(): - #return raycastLeft.get_collider() - # -#func getRightCollider(): - #return raycastRight.get_collider() - -func getLeftColliding() -> bool: - return raycastLeft.is_colliding() - -func getRightColliding() -> bool: - return raycastRight.is_colliding() - func getCollider(direction : GLOBAL.Direction): match direction: GLOBAL.Direction.BOTTOM: @@ -57,7 +24,8 @@ func getCollider(direction : GLOBAL.Direction): return raycastLeft.get_collider() GLOBAL.Direction.RIGHT: return raycastRight.get_collider() - + GLOBAL.Direction.TOP: + return raycastTop.get_collider() func getNeighbours(): var neighbours = [] diff --git a/scenes/Blocks/block.tscn b/scenes/Blocks/block.tscn index 5ef5f20..54609b9 100644 --- a/scenes/Blocks/block.tscn +++ b/scenes/Blocks/block.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=4 format=3 uid="uid://do8gr42oq2a0y"] +[gd_scene load_steps=5 format=3 uid="uid://do8gr42oq2a0y"] [ext_resource type="Script" path="res://scenes/Blocks/block.gd" id="1_t1hpt"] @@ -7,6 +7,9 @@ [sub_resource type="RectangleShape2D" id="RectangleShape2D_gvev2"] size = Vector2(80, 80) +[sub_resource type="RectangleShape2D" id="RectangleShape2D_ti23g"] +size = Vector2(48, 48) + [node name="Block" type="Area2D" groups=["Block"]] collision_layer = 2 collision_mask = 14 @@ -19,21 +22,28 @@ mesh = SubResource("QuadMesh_lsuac") [node name="RaycastFloor" type="RayCast2D" parent="."] position = Vector2(32, 72) -target_position = Vector2(0, 32) +target_position = Vector2(0, 8) collision_mask = 3 hit_from_inside = true collide_with_areas = true [node name="RaycastLeft" type="RayCast2D" parent="."] position = Vector2(-8, 32) -target_position = Vector2(-32, 0) +target_position = Vector2(-8, 0) collision_mask = 3 hit_from_inside = true collide_with_areas = true [node name="RaycastRight" type="RayCast2D" parent="."] position = Vector2(72, 32) -target_position = Vector2(32, 0) +target_position = Vector2(8, 0) +collision_mask = 3 +hit_from_inside = true +collide_with_areas = true + +[node name="RaycastTop" type="RayCast2D" parent="."] +position = Vector2(32, -8) +target_position = Vector2(0, -8) collision_mask = 3 hit_from_inside = true collide_with_areas = true @@ -41,3 +51,10 @@ collide_with_areas = true [node name="CollisionShape2D" type="CollisionShape2D" parent="."] position = Vector2(32, 32) shape = SubResource("RectangleShape2D_gvev2") + +[node name="Area2D" type="Area2D" parent="." groups=["Block"]] +collision_layer = 16 + +[node name="CollisionShape2D" type="CollisionShape2D" parent="Area2D"] +position = Vector2(32, 32) +shape = SubResource("RectangleShape2D_ti23g") diff --git a/scenes/Globals/global.gd b/scenes/Globals/global.gd index 37e20f4..2b9dac2 100644 --- a/scenes/Globals/global.gd +++ b/scenes/Globals/global.gd @@ -10,7 +10,7 @@ var hasSelectedSpeed = false const GRID := 64 -enum BLOCKTYPES {LIGHT, HEAVY} +enum BLOCKTYPES {LIGHT=1, HEAVY=3} const BLOCKSPATTERS : Dictionary = { "Z": "res://scenes/Blocks/Patterns/Z/Z_block_pattern.tscn", @@ -22,12 +22,14 @@ const BLOCKSPATTERS : Dictionary = { "I": "res://scenes/Blocks/Patterns/I/I_block_pattern.tscn", "1x3": "res://scenes/Blocks/Patterns/1x3/1x3_block_pattern.tscn" } -enum Direction {BOTTOM, LEFT, RIGHT} +enum Direction {BOTTOM, LEFT, RIGHT, TOP} var lastUID = 1 var currentUID = lastUID +var time = 0 + func getNewUID() -> int: lastUID += 1 return lastUID diff --git a/scenes/Grid/border.tscn b/scenes/Grid/border.tscn index 76db480..a03dabb 100644 --- a/scenes/Grid/border.tscn +++ b/scenes/Grid/border.tscn @@ -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="."] diff --git a/scenes/Grid/grid.gd b/scenes/Grid/grid.gd index 030fc22..9266f76 100644 --- a/scenes/Grid/grid.gd +++ b/scenes/Grid/grid.gd @@ -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 diff --git a/scenes/Grid/grid.tscn b/scenes/Grid/grid.tscn index c33b22e..1948e51 100644 --- a/scenes/Grid/grid.tscn +++ b/scenes/Grid/grid.tscn @@ -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"] diff --git a/scenes/Grid/row_test.gd b/scenes/Grid/row_test.gd index 39b310f..bd467f7 100644 --- a/scenes/Grid/row_test.gd +++ b/scenes/Grid/row_test.gd @@ -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 diff --git a/scenes/Main/main.gd b/scenes/Main/main.gd new file mode 100644 index 0000000..7068f02 --- /dev/null +++ b/scenes/Main/main.gd @@ -0,0 +1,17 @@ +extends Node + +@onready var gameTimer = $GameTimer +@onready var scoreLabel = $Camera2D/CanvasLayer/Control/HBoxContainer/ScoreValue +@onready var timeLabel = $Camera2D/CanvasLayer/Control/HBoxContainer2/TimeValue + +# Called when the node enters the scene tree for the first time. +func _ready() -> void: + pass # Replace with function body. + +func _physics_process(delta: float) -> void: + scoreLabel.text = str(GLOBAL.points) + timeLabel.text = str(GLOBAL.time) + +func _on_game_timer_timeout() -> void: + GLOBAL.time += 1 + gameTimer.start(1) diff --git a/scenes/Main/main.tscn b/scenes/Main/main.tscn index c440ba8..7ee4ce1 100644 --- a/scenes/Main/main.tscn +++ b/scenes/Main/main.tscn @@ -1,9 +1,13 @@ -[gd_scene load_steps=3 format=3 uid="uid://bq5hrqgv0f6hp"] +[gd_scene load_steps=6 format=3 uid="uid://bq5hrqgv0f6hp"] [ext_resource type="PackedScene" uid="uid://dwl4lotl1d3ij" path="res://scenes/Grid/grid.tscn" id="1_88eap"] +[ext_resource type="Script" path="res://scenes/Main/main.gd" id="1_dtde6"] [ext_resource type="PackedScene" uid="uid://c03h0nwewolfx" path="res://scenes/Grid/SpeedScale.tscn" id="2_mnoeo"] +[ext_resource type="LabelSettings" uid="uid://cd783ubpcytc8" path="res://Theme/label.tres" id="3_jopb4"] +[ext_resource type="Script" path="res://scenes/Main/score_value.gd" id="3_vtvng"] [node name="main" type="Node"] +script = ExtResource("1_dtde6") [node name="Grid" parent="." instance=ExtResource("1_88eap")] position = Vector2(128, 256) @@ -13,4 +17,63 @@ visible = false position = Vector2(960, 896) [node name="Camera2D" type="Camera2D" parent="."] -position = Vector2(448, 800) +position = Vector2(448, 896) + +[node name="CanvasLayer" type="CanvasLayer" parent="Camera2D"] + +[node name="Control" type="Control" parent="Camera2D/CanvasLayer"] +layout_mode = 3 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 + +[node name="HBoxContainer" type="HBoxContainer" parent="Camera2D/CanvasLayer/Control"] +layout_mode = 1 +offset_left = 56.0 +offset_top = 64.0 +offset_right = 266.0 +offset_bottom = 152.0 + +[node name="Score" type="Label" parent="Camera2D/CanvasLayer/Control/HBoxContainer"] +layout_mode = 2 +text = "Score: " +label_settings = ExtResource("3_jopb4") +horizontal_alignment = 1 +vertical_alignment = 1 + +[node name="ScoreValue" type="Label" parent="Camera2D/CanvasLayer/Control/HBoxContainer"] +layout_mode = 2 +label_settings = ExtResource("3_jopb4") +horizontal_alignment = 1 +script = ExtResource("3_vtvng") + +[node name="HBoxContainer2" type="HBoxContainer" parent="Camera2D/CanvasLayer/Control"] +layout_mode = 1 +anchors_preset = 1 +anchor_left = 1.0 +anchor_right = 1.0 +offset_left = -376.0 +offset_top = 64.0 +offset_right = -128.0 +offset_bottom = 152.0 +grow_horizontal = 0 + +[node name="Time" type="Label" parent="Camera2D/CanvasLayer/Control/HBoxContainer2"] +layout_mode = 2 +text = "Time: " +label_settings = ExtResource("3_jopb4") +horizontal_alignment = 1 +vertical_alignment = 1 + +[node name="TimeValue" type="Label" parent="Camera2D/CanvasLayer/Control/HBoxContainer2"] +layout_mode = 2 +label_settings = ExtResource("3_jopb4") +horizontal_alignment = 1 +vertical_alignment = 1 + +[node name="GameTimer" type="Timer" parent="."] +autostart = true + +[connection signal="timeout" from="GameTimer" to="." method="_on_game_timer_timeout"] diff --git a/scenes/Main/score_value.gd b/scenes/Main/score_value.gd new file mode 100644 index 0000000..b909c30 --- /dev/null +++ b/scenes/Main/score_value.gd @@ -0,0 +1,11 @@ +extends Label + + +# Called when the node enters the scene tree for the first time. +func _ready() -> void: + pass # Replace with function body. + + +# Called every frame. 'delta' is the elapsed time since the previous frame. +func _process(delta: float) -> void: + text = str(GLOBAL.points)