Fixed Bugs; Added Mobile Support

This commit is contained in:
Exobyt 2024-08-20 12:17:01 +02:00
parent 956b719e62
commit fdfb6a7d39
35 changed files with 709 additions and 150 deletions

14
scenes/Grid/camera_2d.gd Normal file
View file

@ -0,0 +1,14 @@
extends Camera2D
@onready var scoreLabel = $CanvasLayer/Control/HBoxContainer/ScoreValue
@onready var timeLabel = $CanvasLayer/Control/HBoxContainer2/TimeValue
# 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:
scoreLabel.text = str(GLOBAL.points)
timeLabel.text = str(GLOBAL.time)

View file

@ -5,6 +5,10 @@ extends Node2D
@onready var tickerTimer = $Ticker
@onready var patterns = $Patterns
@onready var turnTickTimer = $TurnTick
@onready var loseArea = $LoseArea
@onready var gameTimer = $GameTimer
@onready var coyoteTimer = $CoyoteTimer
var nextBlocks = []
@ -16,6 +20,7 @@ var blockSpeed = 0.5
var stopped = false
func spawnBlock() -> void:
var block = nextBlocks[0]
GLOBAL.currentBlock = block
@ -31,18 +36,18 @@ func _ready() -> void:
func _physics_process(delta: float) -> void:
#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)
for i in getBlockGroupsList():
if i != GLOBAL.currentUID:
moveUidGroup(GLOBAL.Direction.BOTTOM, i)
var blockGroups = getBlockGroupsList()
#if Input.is_action_pressed("down"):
if Input.is_action_pressed("down") and not stopped and not Input.is_action_just_released("down"):
if not tickerTimer.is_stopped():
blockSpeed = GLOBAL.maxSpeed
else:
if not tickerTimer.is_stopped():
blockSpeed = GLOBAL.minSpeed
if Input.is_action_just_pressed("rotate_right") and not stopped:
if blockGroups.has(GLOBAL.currentUID):
for i in blockGroups[GLOBAL.currentUID]:
@ -54,7 +59,6 @@ func _physics_process(delta: float) -> void:
print(5*delta)
turnTickTimer.start(9*delta)
if Input.is_action_just_pressed("rotate_left") and not stopped:
if blockGroups.has(GLOBAL.currentUID):
for i in blockGroups[GLOBAL.currentUID]:
@ -181,8 +185,11 @@ func getNewPatterns():
newPatterns.append(load(GLOBAL.BLOCKSPATTERS[i]).instantiate())
newPatterns.shuffle()
newPatterns[0].type = GLOBAL.BLOCKTYPES.HEAVY
newPatterns.shuffle()
newPatterns[0].expand = true
newPatterns.shuffle()
for i in newPatterns:
i.expand = true
patternsArray.append_array(newPatterns)
func turnBlocks():
@ -202,60 +209,92 @@ func _on_turn_tick_timeout() -> void:
func _on_ticker_timeout() -> void:
stopped = true
if getBlockedDirection(GLOBAL.Direction.BOTTOM, GLOBAL.currentUID):
coyoteTimer.start(0.1)
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
currentPattern.position.x = 0
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
func _on_game_timer_timeout() -> void:
if GLOBAL.time + 1 > 0:
GLOBAL.time += 1
#else:
#GLOBAL.lose()
gameTimer.start(1)
func _on_coyote_timer_timeout() -> void:
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]:
if i.turningPoint:
currentPattern.set_scale(Vector2(2,2))
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"):
for j in range(1,8):
if await currentPattern.getCollidingBorder() == []:
break
currentPattern.position.x += 64
elif i.is_in_group("RightBorder"):
for j in range(1,8):
if await currentPattern.getCollidingBorder() == []:
break
currentPattern.position.x -= 64
#for i in range(1,8):
#print(await currentPattern.getCollidingBorder())
#if await currentPattern.getCollidingBorder() == []:
#break
#currentPattern.position.x -= 64
#currentPattern.position.x = 0
#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()

View file

@ -1,9 +1,19 @@
[gd_scene load_steps=8 format=3 uid="uid://dwl4lotl1d3ij"]
[gd_scene load_steps=19 format=3 uid="uid://dwl4lotl1d3ij"]
[ext_resource type="Script" path="res://scenes/Grid/grid.gd" id="1_vie5m"]
[ext_resource type="PackedScene" uid="uid://bm7rshwf6pjb" path="res://scenes/Grid/border.tscn" id="4_3j08q"]
[ext_resource type="PackedScene" uid="uid://duubii5uu3lgq" path="res://scenes/Grid/row_test.tscn" id="4_si3v6"]
[ext_resource type="PackedScene" uid="uid://dvrotjxom4u6d" path="res://scenes/Grid/bottom.tscn" id="5_14njh"]
[ext_resource type="PackedScene" uid="uid://d2m5xvw4ucwfw" path="res://scenes/Grid/lose_area.tscn" id="5_u5wlg"]
[ext_resource type="Script" path="res://scenes/Grid/camera_2d.gd" id="6_mbeib"]
[ext_resource type="Theme" uid="uid://1nebbd65iyce" path="res://Theme/main.tres" id="7_38u5s"]
[ext_resource type="Script" path="res://scenes/Main/control.gd" id="8_4bfjb"]
[ext_resource type="LabelSettings" uid="uid://cd783ubpcytc8" path="res://Theme/label.tres" id="9_i2h5u"]
[ext_resource type="Texture2D" uid="uid://bfji7a4suq6a1" path="res://assets/Buttons/LeftArrow.png" id="10_vgg21"]
[ext_resource type="Texture2D" uid="uid://dsg7p035f3g52" path="res://assets/Buttons/RightArrow.png" id="11_pa3jp"]
[ext_resource type="Texture2D" uid="uid://ct4dkk00pyv6v" path="res://assets/Buttons/RotationLeft.png" id="12_qk3ju"]
[ext_resource type="Texture2D" uid="uid://5gbnb7gtwww3" path="res://assets/Buttons/RotationRight.png" id="13_kls78"]
[ext_resource type="Texture2D" uid="uid://cevua7g7nsrfj" path="res://assets/Buttons/DownArrow.png" id="14_i1yud"]
[sub_resource type="QuadMesh" id="QuadMesh_qfjsc"]
@ -13,6 +23,9 @@ size = Vector2(128, 1536)
[sub_resource type="RectangleShape2D" id="RectangleShape2D_rxd0s"]
size = Vector2(896, 128)
[sub_resource type="RectangleShape2D" id="RectangleShape2D_m21a1"]
size = Vector2(640, 256)
[node name="Grid" type="Node2D"]
script = ExtResource("1_vie5m")
@ -104,19 +117,19 @@ one_shot = true
[node name="Borders" type="Node2D" parent="."]
[node name="Border" parent="Borders" instance=ExtResource("4_3j08q")]
[node name="Border" parent="Borders" groups=["LeftBorder"] 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="Border2" parent="Borders" groups=["RightBorder"] 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")]
[node name="Bottom" parent="." groups=["Floor"] instance=ExtResource("5_14njh")]
position = Vector2(320, 1312)
collision_mask = 2
@ -124,8 +137,167 @@ collision_mask = 2
position = Vector2(0, 32)
shape = SubResource("RectangleShape2D_rxd0s")
[node name="LoseArea" parent="." instance=ExtResource("5_u5wlg")]
[node name="CollisionShape2D" type="CollisionShape2D" parent="LoseArea"]
position = Vector2(320, -128)
shape = SubResource("RectangleShape2D_m21a1")
[node name="GameTimer" type="Timer" parent="."]
autostart = true
[node name="Camera2D" type="Camera2D" parent="."]
position = Vector2(320, 640)
script = ExtResource("6_mbeib")
[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
theme = ExtResource("7_38u5s")
script = ExtResource("8_4bfjb")
[node name="HBoxContainer" type="HBoxContainer" parent="Camera2D/CanvasLayer/Control"]
layout_mode = 1
offset_left = 56.0
offset_top = 64.0
offset_right = 320.0
offset_bottom = 152.0
[node name="Score" type="Label" parent="Camera2D/CanvasLayer/Control/HBoxContainer"]
layout_mode = 2
text = "Score: "
label_settings = ExtResource("9_i2h5u")
horizontal_alignment = 1
vertical_alignment = 1
[node name="ScoreValue" type="Label" parent="Camera2D/CanvasLayer/Control/HBoxContainer"]
layout_mode = 2
label_settings = ExtResource("9_i2h5u")
horizontal_alignment = 1
[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 = -312.0
offset_top = 64.0
offset_right = -56.0
offset_bottom = 152.0
grow_horizontal = 0
alignment = 2
[node name="TimeValue" type="Label" parent="Camera2D/CanvasLayer/Control/HBoxContainer2"]
layout_mode = 2
label_settings = ExtResource("9_i2h5u")
horizontal_alignment = 1
vertical_alignment = 1
[node name="Time" type="Label" parent="Camera2D/CanvasLayer/Control/HBoxContainer2"]
layout_mode = 2
text = " :Time"
label_settings = ExtResource("9_i2h5u")
horizontal_alignment = 1
vertical_alignment = 1
[node name="HBoxContainer3" type="HBoxContainer" parent="Camera2D/CanvasLayer/Control"]
visible = false
modulate = Color(1, 1, 1, 0.588235)
layout_mode = 1
anchors_preset = 2
anchor_top = 1.0
anchor_bottom = 1.0
offset_left = 64.0
offset_top = -240.0
offset_right = 252.0
offset_bottom = -148.0
grow_vertical = 0
scale = Vector2(2, 2)
alignment = 2
[node name="left_Button" type="Button" parent="Camera2D/CanvasLayer/Control/HBoxContainer3"]
layout_mode = 2
action_mode = 0
icon = ExtResource("10_vgg21")
icon_alignment = 1
[node name="right_Button" type="Button" parent="Camera2D/CanvasLayer/Control/HBoxContainer3"]
layout_mode = 2
action_mode = 0
icon = ExtResource("11_pa3jp")
icon_alignment = 1
[node name="HBoxContainer4" type="HBoxContainer" parent="Camera2D/CanvasLayer/Control"]
visible = false
modulate = Color(1, 1, 1, 0.588235)
layout_mode = 1
anchors_preset = 3
anchor_left = 1.0
anchor_top = 1.0
anchor_right = 1.0
anchor_bottom = 1.0
offset_left = -432.0
offset_top = -240.0
offset_right = -244.0
offset_bottom = -148.0
grow_horizontal = 0
grow_vertical = 0
scale = Vector2(2, 2)
[node name="rotate_left_Button" type="Button" parent="Camera2D/CanvasLayer/Control/HBoxContainer4"]
layout_mode = 2
action_mode = 0
icon = ExtResource("12_qk3ju")
icon_alignment = 1
[node name="rotate_right_Button" type="Button" parent="Camera2D/CanvasLayer/Control/HBoxContainer4"]
layout_mode = 2
action_mode = 0
icon = ExtResource("13_kls78")
icon_alignment = 1
[node name="HBoxContainer5" type="HBoxContainer" parent="Camera2D/CanvasLayer/Control"]
visible = false
modulate = Color(1, 1, 1, 0.588235)
layout_mode = 1
anchors_preset = 7
anchor_left = 0.5
anchor_top = 1.0
anchor_right = 0.5
anchor_bottom = 1.0
offset_left = -92.0
offset_top = -240.0
offset_right = 4.0
offset_bottom = -148.0
grow_horizontal = 2
grow_vertical = 0
scale = Vector2(2, 2)
[node name="down_Button" type="Button" parent="Camera2D/CanvasLayer/Control/HBoxContainer5"]
layout_mode = 2
action_mode = 0
icon = ExtResource("14_i1yud")
icon_alignment = 1
[node name="CoyoteTimer" type="Timer" parent="."]
one_shot = true
[connection signal="timeout" from="Ticker" to="." method="_on_ticker_timeout"]
[connection signal="timeout" from="TurnTick" to="." method="_on_turn_tick_timeout"]
[connection signal="timeout" from="GameTimer" to="." method="_on_game_timer_timeout"]
[connection signal="pressed" from="Camera2D/CanvasLayer/Control/HBoxContainer3/left_Button" to="Camera2D/CanvasLayer/Control" method="_on_left_button_pressed"]
[connection signal="pressed" from="Camera2D/CanvasLayer/Control/HBoxContainer3/right_Button" to="Camera2D/CanvasLayer/Control" method="_on_right_button_pressed"]
[connection signal="pressed" from="Camera2D/CanvasLayer/Control/HBoxContainer4/rotate_left_Button" to="Camera2D/CanvasLayer/Control" method="_on_rotate_left_button_pressed"]
[connection signal="pressed" from="Camera2D/CanvasLayer/Control/HBoxContainer4/rotate_right_Button" to="Camera2D/CanvasLayer/Control" method="_on_rotate_right_button_pressed"]
[connection signal="button_down" from="Camera2D/CanvasLayer/Control/HBoxContainer5/down_Button" to="Camera2D/CanvasLayer/Control" method="_on_down_button_button_down"]
[connection signal="button_up" from="Camera2D/CanvasLayer/Control/HBoxContainer5/down_Button" to="Camera2D/CanvasLayer/Control" method="_on_down_button_button_up"]
[connection signal="timeout" from="CoyoteTimer" to="." method="_on_coyote_timer_timeout"]
[editable path="Borders/Border"]
[editable path="Borders/Border2"]

View file

@ -0,0 +1,5 @@
[gd_scene format=3 uid="uid://d2m5xvw4ucwfw"]
[node name="LoseArea" type="Area2D"]
collision_layer = 64
collision_mask = 2