From 6d71780f36667d2fb2bb5a7606fddd8d77550750 Mon Sep 17 00:00:00 2001 From: Exobyt Date: Tue, 20 Aug 2024 12:17:51 +0200 Subject: [PATCH] Fixed Bugs; Added Score overview --- Theme/labelBig.tres | 6 ++ project.godot | 5 ++ scenes/Blocks/block.gd | 2 + scenes/Globals/global.gd | 5 +- scenes/Grid/grid.gd | 48 +++++++++------- scenes/Main/main.gd | 17 +++++- scenes/Main/main.tscn | 11 +--- scenes/ScoreOverview/score_overview.gd | 19 +++++++ scenes/ScoreOverview/score_overview.tscn | 72 ++++++++++++++++++++++++ 9 files changed, 152 insertions(+), 33 deletions(-) create mode 100644 Theme/labelBig.tres create mode 100644 scenes/ScoreOverview/score_overview.gd create mode 100644 scenes/ScoreOverview/score_overview.tscn diff --git a/Theme/labelBig.tres b/Theme/labelBig.tres new file mode 100644 index 0000000..d0b6677 --- /dev/null +++ b/Theme/labelBig.tres @@ -0,0 +1,6 @@ +[gd_resource type="LabelSettings" format=3 uid="uid://5mlweyjje7c4"] + +[resource] +font_size = 128 +outline_size = 10 +outline_color = Color(0, 0, 0, 1) diff --git a/project.godot b/project.godot index a4d8f12..d87b7ae 100644 --- a/project.godot +++ b/project.godot @@ -111,3 +111,8 @@ textures/canvas_textures/default_texture_filter=0 renderer/rendering_method="gl_compatibility" renderer/rendering_method.mobile="gl_compatibility" textures/vram_compression/import_etc2_astc=true +anti_aliasing/quality/msaa_2d=1 +anti_aliasing/quality/msaa_3d=1 +anti_aliasing/quality/screen_space_aa=1 +anti_aliasing/quality/use_taa=true +anti_aliasing/quality/use_debanding=true diff --git a/scenes/Blocks/block.gd b/scenes/Blocks/block.gd index 6969e90..a78ca0d 100644 --- a/scenes/Blocks/block.gd +++ b/scenes/Blocks/block.gd @@ -13,6 +13,8 @@ var turningPoint = false var type = GLOBAL.BLOCKTYPES.LIGHT +var expand = false + func _ready() -> void: secretPosition = position diff --git a/scenes/Globals/global.gd b/scenes/Globals/global.gd index 906c73f..aba9705 100644 --- a/scenes/Globals/global.gd +++ b/scenes/Globals/global.gd @@ -28,7 +28,7 @@ var lastUID = 1 var currentUID = lastUID -var time = 0 +var time = 60 var lost = false @@ -38,10 +38,11 @@ func getNewUID() -> int: func resetGame(): + lost = false points = 0 lastUID = 0 currentUID = lastUID - time = 0 + time = 60 lost = false func _ready() -> void: diff --git a/scenes/Grid/grid.gd b/scenes/Grid/grid.gd index 9846de7..ea26574 100644 --- a/scenes/Grid/grid.gd +++ b/scenes/Grid/grid.gd @@ -36,9 +36,7 @@ func _ready() -> void: func _physics_process(delta: float) -> void: - for i in getBlockGroupsList(): - if i != GLOBAL.currentUID: - moveUidGroup(GLOBAL.Direction.BOTTOM, i) + var blockGroups = getBlockGroupsList() #if Input.is_action_pressed("down"): @@ -53,10 +51,10 @@ func _physics_process(delta: float) -> void: 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)) + if not stopped: + currentPattern.turn(GLOBAL.Direction.RIGHT,i.position-spawnpoint.position + Vector2(GLOBAL.GRID/2, GLOBAL.GRID/2)) #turnBlocks() if turnTickTimer.is_stopped(): - print(5*delta) turnTickTimer.start(9*delta) if Input.is_action_just_pressed("rotate_left") and not stopped: @@ -64,10 +62,10 @@ func _physics_process(delta: float) -> void: 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)) + if not stopped: + currentPattern.turn(GLOBAL.Direction.LEFT,i.position-spawnpoint.position + Vector2(GLOBAL.GRID/2, GLOBAL.GRID/2)) #turnBlocks() if turnTickTimer.is_stopped(): - print(5*delta) turnTickTimer.start(9*delta) if Input.is_action_just_pressed("left"): @@ -174,6 +172,7 @@ func PlacePattern(): block.modulate = newColor block.position = spawnpoint.position + i.position block.type = currentPattern.type + block.expand = currentPattern.expand if i.turningPoint: block.turningPoint = true blocks.add_child(block) @@ -188,8 +187,6 @@ func getNewPatterns(): newPatterns.shuffle() newPatterns[0].expand = true newPatterns.shuffle() - for i in newPatterns: - i.expand = true patternsArray.append_array(newPatterns) func turnBlocks(): @@ -209,7 +206,7 @@ func _on_turn_tick_timeout() -> void: func _on_ticker_timeout() -> void: stopped = true if getBlockedDirection(GLOBAL.Direction.BOTTOM, GLOBAL.currentUID): - coyoteTimer.start(0.1) + coyoteTimer.start(0.08) for i in getBlockGroupsList(): @@ -220,21 +217,21 @@ func _on_ticker_timeout() -> void: func _on_game_timer_timeout() -> void: - if GLOBAL.time + 1 > 0: - GLOBAL.time += 1 - #else: - #GLOBAL.lose() + if GLOBAL.time - 1 > 0: + GLOBAL.time -= 1 + else: + GLOBAL.lose() gameTimer.start(1) func _on_coyote_timer_timeout() -> void: + if loseArea.get_overlapping_areas() != []: + GLOBAL.lose() for i in $RowTests.get_children(): for j in getBlockGroupsList(): if j != GLOBAL.currentUID: moveUidGroup(GLOBAL.Direction.BOTTOM, i) stopped = true - if loseArea.get_overlapping_areas() != []: - GLOBAL.lose() if currentPattern.expand: if currentPattern.get_scale() != Vector2(2,2): for i in getBlockGroupsList()[GLOBAL.currentUID]: @@ -243,9 +240,12 @@ func _on_coyote_timer_timeout() -> void: currentPattern.moveToPosition(i.global_position-spawnpoint.position - Vector2(64,64*4)) #if await currentPattern.getCollidingBorder() != []: for i in await currentPattern.getCollidingBorder(): - if i.is_in_group("Floor"): - currentPattern.position.y -= 64 - elif i.is_in_group("LeftBorder"): + #if i.is_in_group("Floor"): + #for j in range(1,3): + #if not await currentPattern.getCollidingBorder() == []: + #break + #currentPattern.position.y -= 64 + if i.is_in_group("LeftBorder"): for j in range(1,8): if await currentPattern.getCollidingBorder() == []: break @@ -295,6 +295,14 @@ func _on_coyote_timer_timeout() -> void: if i.isCompleted(): for j in i.getRow(): splitOphansUID(j.UID) - GLOBAL.points += j.type + if j.expand: + GLOBAL.points += j.type * 2 + GLOBAL.time += j.type * 2 + elif not j.expand: + GLOBAL.points += j.type + GLOBAL.time += j.type j.queue_free() + for j in getBlockGroupsList(): + if j != GLOBAL.currentUID: + moveUidGroup(GLOBAL.Direction.BOTTOM, j) PlacePattern() diff --git a/scenes/Main/main.gd b/scenes/Main/main.gd index b489a64..084d4a5 100644 --- a/scenes/Main/main.gd +++ b/scenes/Main/main.gd @@ -2,4 +2,19 @@ extends Node # Called when the node enters the scene tree for the first time. func _ready() -> void: - pass # Replace with function body. + loadGrid() + +func _physics_process(delta: float) -> void: + if get_children() != []: + if GLOBAL.lost and get_child(0).name == "Grid": + scoreOverview() + +func loadGrid(): + if $ScoreOverview != null: + $ScoreOverview.queue_free() + add_child(load("res://scenes/Grid/grid.tscn").instantiate()) + +func scoreOverview(): + if $Grid != null: + $Grid.queue_free() + add_child(load("res://scenes/ScoreOverview/score_overview.tscn").instantiate()) diff --git a/scenes/Main/main.tscn b/scenes/Main/main.tscn index 1ef11e0..57d4f99 100644 --- a/scenes/Main/main.tscn +++ b/scenes/Main/main.tscn @@ -1,15 +1,6 @@ -[gd_scene load_steps=4 format=3 uid="uid://bq5hrqgv0f6hp"] +[gd_scene load_steps=2 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"] [node name="main" type="Node"] script = ExtResource("1_dtde6") - -[node name="Grid" parent="." instance=ExtResource("1_88eap")] -position = Vector2(128, 256) - -[node name="Node2D" parent="." instance=ExtResource("2_mnoeo")] -visible = false -position = Vector2(960, 896) diff --git a/scenes/ScoreOverview/score_overview.gd b/scenes/ScoreOverview/score_overview.gd new file mode 100644 index 0000000..b707949 --- /dev/null +++ b/scenes/ScoreOverview/score_overview.gd @@ -0,0 +1,19 @@ +extends Control + +@onready var score = $VBoxContainer3/VBoxContainer2/ScoreValue +@onready var time = $VBoxContainer3/VBoxContainer/TimeValue + +# Called when the node enters the scene tree for the first time. +func _ready() -> void: + score.text = str(GLOBAL.points) + time.text = str(GLOBAL.time) + GLOBAL.resetGame() + + +# Called every frame. 'delta' is the elapsed time since the previous frame. +func _process(delta: float) -> void: + pass + + +func _on_left_button_pressed() -> void: + get_parent().loadGrid() diff --git a/scenes/ScoreOverview/score_overview.tscn b/scenes/ScoreOverview/score_overview.tscn new file mode 100644 index 0000000..95fd4ad --- /dev/null +++ b/scenes/ScoreOverview/score_overview.tscn @@ -0,0 +1,72 @@ +[gd_scene load_steps=6 format=3 uid="uid://crnamktl6ltt"] + +[ext_resource type="Theme" uid="uid://1nebbd65iyce" path="res://Theme/main.tres" id="1_pyjb5"] +[ext_resource type="LabelSettings" uid="uid://cd783ubpcytc8" path="res://Theme/label.tres" id="2_4dys4"] +[ext_resource type="Script" path="res://scenes/ScoreOverview/score_overview.gd" id="2_vv54r"] +[ext_resource type="LabelSettings" uid="uid://5mlweyjje7c4" path="res://Theme/labelBig.tres" id="4_dfemu"] +[ext_resource type="Texture2D" uid="uid://ct4dkk00pyv6v" path="res://assets/Buttons/RotationLeft.png" id="5_xkigm"] + +[node name="ScoreOverview" type="Control"] +layout_mode = 3 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +size_flags_horizontal = 6 +size_flags_vertical = 6 +theme = ExtResource("1_pyjb5") +script = ExtResource("2_vv54r") + +[node name="VBoxContainer3" type="VBoxContainer" parent="."] +layout_mode = 1 +anchors_preset = 8 +anchor_left = 0.5 +anchor_top = 0.5 +anchor_right = 0.5 +anchor_bottom = 0.5 +offset_left = -166.0 +offset_top = -182.0 +offset_right = 166.0 +offset_bottom = 182.0 +grow_horizontal = 2 +grow_vertical = 2 + +[node name="VBoxContainer2" type="VBoxContainer" parent="VBoxContainer3"] +layout_mode = 2 +alignment = 1 + +[node name="Score" type="Label" parent="VBoxContainer3/VBoxContainer2"] +layout_mode = 2 +text = "Your Score" +label_settings = ExtResource("2_4dys4") +horizontal_alignment = 1 + +[node name="ScoreValue" type="Label" parent="VBoxContainer3/VBoxContainer2"] +layout_mode = 2 +label_settings = ExtResource("4_dfemu") +horizontal_alignment = 1 + +[node name="VBoxContainer" type="VBoxContainer" parent="VBoxContainer3"] +layout_mode = 2 +alignment = 1 + +[node name="Time" type="Label" parent="VBoxContainer3/VBoxContainer"] +layout_mode = 2 +text = "Time Left" +label_settings = ExtResource("2_4dys4") +horizontal_alignment = 1 + +[node name="TimeValue" type="Label" parent="VBoxContainer3/VBoxContainer"] +layout_mode = 2 +label_settings = ExtResource("4_dfemu") +horizontal_alignment = 1 + +[node name="left_Button" type="Button" parent="VBoxContainer3"] +layout_mode = 2 +action_mode = 0 +text = "Play Again" +icon = ExtResource("5_xkigm") +expand_icon = true + +[connection signal="pressed" from="VBoxContainer3/left_Button" to="." method="_on_left_button_pressed"]