diff --git a/GameBoard.gd b/GameBoard.gd index fef6c96..0cd9d56 100644 --- a/GameBoard.gd +++ b/GameBoard.gd @@ -5,13 +5,13 @@ signal score_changed(new_score) signal new_next_shape(next_shape_scene) var shapes = [ - preload("res://ShapeI.tscn"), - preload("res://ShapeJ.tscn"), - preload("res://ShapeL.tscn"), - preload("res://ShapeZ.tscn"), - preload("res://ShapeS.tscn"), - preload("res://ShapeT.tscn"), - preload("res://ShapeO.tscn") + preload("res://Shapes/ShapeI.tscn"), + preload("res://Shapes/ShapeJ.tscn"), + preload("res://Shapes/ShapeL.tscn"), + preload("res://Shapes/ShapeZ.tscn"), + preload("res://Shapes/ShapeS.tscn"), + preload("res://Shapes/ShapeT.tscn"), + preload("res://Shapes/ShapeO.tscn") ] var active_shape: TetrisShape diff --git a/GameBoard.tscn b/GameBoard.tscn index 5fb8e4d..a16e7f8 100644 --- a/GameBoard.tscn +++ b/GameBoard.tscn @@ -1,6 +1,6 @@ [gd_scene load_steps=4 format=2] -[ext_resource path="res://background.png" type="Texture" id=1] +[ext_resource path="res://Resources/background.png" type="Texture" id=1] [ext_resource path="res://GameBoard.gd" type="Script" id=2] [ext_resource path="res://SwipeHandler.gd" type="Script" id=3] diff --git a/Main.tscn b/Main.tscn index bdf40a1..b2816c1 100644 --- a/Main.tscn +++ b/Main.tscn @@ -1,14 +1,19 @@ -[gd_scene load_steps=4 format=2] +[gd_scene load_steps=6 format=2] [ext_resource path="res://GameBoard.tscn" type="PackedScene" id=1] [ext_resource path="res://UI.gd" type="Script" id=2] [ext_resource path="res://Main.gd" type="Script" id=3] +[ext_resource path="res://Resources/Kenney Future.ttf" type="DynamicFontData" id=4] + +[sub_resource type="DynamicFont" id=1] +size = 128 +font_data = ExtResource( 4 ) [node name="Main" type="Node"] script = ExtResource( 3 ) [node name="GameBoard" parent="." instance=ExtResource( 1 )] -position = Vector2( 547, 813 ) +position = Vector2( 540, 1000 ) [node name="UI" type="Control" parent="."] anchor_right = 1.0 @@ -30,13 +35,14 @@ margin_right = 1080.0 margin_bottom = 150.0 [node name="Score" type="Label" parent="UI/VBoxContainer/HBoxContainer"] -margin_top = 68.0 -margin_right = 8.0 -margin_bottom = 82.0 +margin_top = 3.0 +margin_right = 107.0 +margin_bottom = 147.0 +custom_fonts/font = SubResource( 1 ) text = "0" [node name="Spacer" type="Control" parent="UI/VBoxContainer/HBoxContainer"] -margin_left = 12.0 +margin_left = 111.0 margin_right = 926.0 margin_bottom = 150.0 size_flags_horizontal = 3 diff --git a/Resources/Kenney Future.ttf b/Resources/Kenney Future.ttf new file mode 100644 index 0000000..1dbb2dd Binary files /dev/null and b/Resources/Kenney Future.ttf differ diff --git a/background.png b/Resources/background.png similarity index 100% rename from background.png rename to Resources/background.png diff --git a/background.png.import b/Resources/background.png.import similarity index 71% rename from background.png.import rename to Resources/background.png.import index 1e8ce85..b3a67a1 100644 --- a/background.png.import +++ b/Resources/background.png.import @@ -2,15 +2,15 @@ importer="texture" type="StreamTexture" -path="res://.import/background.png-98289422cd7d93003950872a7b97021f.stex" +path="res://.import/background.png-29f75aad12319c515b0a31e04e27d610.stex" metadata={ "vram_texture": false } [deps] -source_file="res://background.png" -dest_files=[ "res://.import/background.png-98289422cd7d93003950872a7b97021f.stex" ] +source_file="res://Resources/background.png" +dest_files=[ "res://.import/background.png-29f75aad12319c515b0a31e04e27d610.stex" ] [params] diff --git a/brick.png b/Resources/brick.png similarity index 100% rename from brick.png rename to Resources/brick.png diff --git a/brick.png.import b/Resources/brick.png.import similarity index 73% rename from brick.png.import rename to Resources/brick.png.import index f35588f..cf6fd34 100644 --- a/brick.png.import +++ b/Resources/brick.png.import @@ -2,15 +2,15 @@ importer="texture" type="StreamTexture" -path="res://.import/brick.png-3b7e2d2d29430a475fb75656e3e81471.stex" +path="res://.import/brick.png-f9b7612ef038ee5d9ee3b9e2a0996994.stex" metadata={ "vram_texture": false } [deps] -source_file="res://brick.png" -dest_files=[ "res://.import/brick.png-3b7e2d2d29430a475fb75656e3e81471.stex" ] +source_file="res://Resources/brick.png" +dest_files=[ "res://.import/brick.png-f9b7612ef038ee5d9ee3b9e2a0996994.stex" ] [params] diff --git a/ShapeI.tscn b/ShapeI.tscn deleted file mode 100644 index 3afa308..0000000 --- a/ShapeI.tscn +++ /dev/null @@ -1,23 +0,0 @@ -[gd_scene load_steps=3 format=2] - -[ext_resource path="res://Block.tscn" type="PackedScene" id=1] -[ext_resource path="res://TetrisShape.gd" type="Script" id=2] - -[node name="ShapeI" type="Node2D"] -script = ExtResource( 2 ) - -[node name="Block" parent="." instance=ExtResource( 1 )] -position = Vector2( 32, 32 ) -color = Color( 0.717647, 1, 0.952941, 1 ) - -[node name="Block2" parent="." instance=ExtResource( 1 )] -position = Vector2( 32, -32 ) -color = Color( 0.717647, 1, 0.952941, 1 ) - -[node name="Block3" parent="." instance=ExtResource( 1 )] -position = Vector2( 32, -96 ) -color = Color( 0.717647, 1, 0.952941, 1 ) - -[node name="Block4" parent="." instance=ExtResource( 1 )] -position = Vector2( 32, -160 ) -color = Color( 0.717647, 1, 0.952941, 1 ) diff --git a/ShapeJ.tscn b/ShapeJ.tscn deleted file mode 100644 index ad01cf6..0000000 --- a/ShapeJ.tscn +++ /dev/null @@ -1,23 +0,0 @@ -[gd_scene load_steps=3 format=2] - -[ext_resource path="res://Block.tscn" type="PackedScene" id=1] -[ext_resource path="res://TetrisShape.gd" type="Script" id=2] - -[node name="ShapeJ" type="Node2D"] -script = ExtResource( 2 ) - -[node name="Block" parent="." instance=ExtResource( 1 )] -position = Vector2( -32, 32 ) -color = Color( 0.486275, 0.494118, 1, 1 ) - -[node name="Block2" parent="." instance=ExtResource( 1 )] -position = Vector2( 32, 32 ) -color = Color( 0.486275, 0.494118, 1, 1 ) - -[node name="Block3" parent="." instance=ExtResource( 1 )] -position = Vector2( 32, -32 ) -color = Color( 0.486275, 0.494118, 1, 1 ) - -[node name="Block4" parent="." instance=ExtResource( 1 )] -position = Vector2( 32, -96 ) -color = Color( 0.486275, 0.494118, 1, 1 ) diff --git a/ShapeL.tscn b/ShapeL.tscn deleted file mode 100644 index 9286a9f..0000000 --- a/ShapeL.tscn +++ /dev/null @@ -1,23 +0,0 @@ -[gd_scene load_steps=3 format=2] - -[ext_resource path="res://Block.tscn" type="PackedScene" id=1] -[ext_resource path="res://TetrisShape.gd" type="Script" id=2] - -[node name="ShapeL" type="Node2D"] -script = ExtResource( 2 ) - -[node name="Block" parent="." instance=ExtResource( 1 )] -position = Vector2( -32, 32 ) -color = Color( 1, 0.47451, 0.47451, 1 ) - -[node name="Block3" parent="." instance=ExtResource( 1 )] -position = Vector2( -32, -32 ) -color = Color( 1, 0.47451, 0.47451, 1 ) - -[node name="Block4" parent="." instance=ExtResource( 1 )] -position = Vector2( -32, -96 ) -color = Color( 1, 0.47451, 0.47451, 1 ) - -[node name="Block2" parent="." instance=ExtResource( 1 )] -position = Vector2( 32, 32 ) -color = Color( 1, 0.47451, 0.47451, 1 ) diff --git a/ShapeO.tscn b/ShapeO.tscn deleted file mode 100644 index dc03e0e..0000000 --- a/ShapeO.tscn +++ /dev/null @@ -1,23 +0,0 @@ -[gd_scene load_steps=3 format=2] - -[ext_resource path="res://Block.tscn" type="PackedScene" id=1] -[ext_resource path="res://TetrisShape.gd" type="Script" id=2] - -[node name="ShapeSquare" type="Node2D"] -script = ExtResource( 2 ) - -[node name="Block" parent="." instance=ExtResource( 1 )] -position = Vector2( 32, 32 ) -color = Color( 0.827451, 1, 0.490196, 1 ) - -[node name="Block2" parent="." instance=ExtResource( 1 )] -position = Vector2( 32, -32 ) -color = Color( 0.827451, 1, 0.490196, 1 ) - -[node name="Block3" parent="." instance=ExtResource( 1 )] -position = Vector2( -32, -32 ) -color = Color( 0.827451, 1, 0.490196, 1 ) - -[node name="Block4" parent="." instance=ExtResource( 1 )] -position = Vector2( -32, 32 ) -color = Color( 0.827451, 1, 0.490196, 1 ) diff --git a/ShapeS.tscn b/ShapeS.tscn deleted file mode 100644 index 84cddf5..0000000 --- a/ShapeS.tscn +++ /dev/null @@ -1,23 +0,0 @@ -[gd_scene load_steps=3 format=2] - -[ext_resource path="res://Block.tscn" type="PackedScene" id=1] -[ext_resource path="res://TetrisShape.gd" type="Script" id=2] - -[node name="ShapeS" type="Node2D"] -script = ExtResource( 2 ) - -[node name="Block" parent="." instance=ExtResource( 1 )] -position = Vector2( -32, 32 ) -color = Color( 0.607843, 1, 0.603922, 1 ) - -[node name="Block2" parent="." instance=ExtResource( 1 )] -position = Vector2( 32, 32 ) -color = Color( 0.607843, 1, 0.603922, 1 ) - -[node name="Block3" parent="." instance=ExtResource( 1 )] -position = Vector2( 32, -32 ) -color = Color( 0.607843, 1, 0.603922, 1 ) - -[node name="Block4" parent="." instance=ExtResource( 1 )] -position = Vector2( 96, -32 ) -color = Color( 0.607843, 1, 0.603922, 1 ) diff --git a/ShapeT.tscn b/ShapeT.tscn deleted file mode 100644 index d029cf9..0000000 --- a/ShapeT.tscn +++ /dev/null @@ -1,23 +0,0 @@ -[gd_scene load_steps=3 format=2] - -[ext_resource path="res://Block.tscn" type="PackedScene" id=1] -[ext_resource path="res://TetrisShape.gd" type="Script" id=2] - -[node name="ShapeT" type="Node2D"] -script = ExtResource( 2 ) - -[node name="Block" parent="." instance=ExtResource( 1 )] -position = Vector2( -32, 32 ) -color = Color( 0.968627, 0.411765, 1, 1 ) - -[node name="Block2" parent="." instance=ExtResource( 1 )] -position = Vector2( 32, 32 ) -color = Color( 0.968627, 0.411765, 1, 1 ) - -[node name="Block3" parent="." instance=ExtResource( 1 )] -position = Vector2( 32, -32 ) -color = Color( 0.968627, 0.411765, 1, 1 ) - -[node name="Block4" parent="." instance=ExtResource( 1 )] -position = Vector2( 96, 32 ) -color = Color( 0.968627, 0.411765, 1, 1 ) diff --git a/ShapeZ.tscn b/ShapeZ.tscn deleted file mode 100644 index fa6ea72..0000000 --- a/ShapeZ.tscn +++ /dev/null @@ -1,23 +0,0 @@ -[gd_scene load_steps=3 format=2] - -[ext_resource path="res://Block.tscn" type="PackedScene" id=1] -[ext_resource path="res://TetrisShape.gd" type="Script" id=2] - -[node name="ShapeZ" type="Node2D"] -script = ExtResource( 2 ) - -[node name="Block" parent="." instance=ExtResource( 1 )] -position = Vector2( -32, -32 ) -color = Color( 0.984314, 1, 0.537255, 1 ) - -[node name="Block2" parent="." instance=ExtResource( 1 )] -position = Vector2( 32, -32 ) -color = Color( 0.984314, 1, 0.537255, 1 ) - -[node name="Block3" parent="." instance=ExtResource( 1 )] -position = Vector2( 32, 32 ) -color = Color( 0.984314, 1, 0.537255, 1 ) - -[node name="Block4" parent="." instance=ExtResource( 1 )] -position = Vector2( 96, 32 ) -color = Color( 0.984314, 1, 0.537255, 1 ) diff --git a/Block.gd b/Shapes/Block.gd similarity index 100% rename from Block.gd rename to Shapes/Block.gd diff --git a/Block.tscn b/Shapes/Block.tscn similarity index 74% rename from Block.tscn rename to Shapes/Block.tscn index d812e31..a75da87 100644 --- a/Block.tscn +++ b/Shapes/Block.tscn @@ -1,7 +1,7 @@ [gd_scene load_steps=5 format=2] -[ext_resource path="res://brick.png" type="Texture" id=1] -[ext_resource path="res://Block.gd" type="Script" id=2] +[ext_resource path="res://Shapes/Block.gd" type="Script" id=1] +[ext_resource path="res://Resources/brick.png" type="Texture" id=2] [sub_resource type="Shader" id=1] code = "shader_type canvas_item; @@ -21,10 +21,10 @@ shader = SubResource( 1 ) shader_param/color = Color( 1, 1, 1, 1 ) [node name="Block" type="Node2D"] -script = ExtResource( 2 ) +script = ExtResource( 1 ) color = Color( 1, 1, 1, 1 ) [node name="Sprite" type="Sprite" parent="."] material = SubResource( 2 ) scale = Vector2( 0.125, 0.125 ) -texture = ExtResource( 1 ) +texture = ExtResource( 2 ) diff --git a/Shapes/ShapeI.tscn b/Shapes/ShapeI.tscn new file mode 100644 index 0000000..4c2cda9 --- /dev/null +++ b/Shapes/ShapeI.tscn @@ -0,0 +1,23 @@ +[gd_scene load_steps=3 format=2] + +[ext_resource path="res://Shapes/TetrisShape.gd" type="Script" id=1] +[ext_resource path="res://Shapes/Block.tscn" type="PackedScene" id=2] + +[node name="ShapeI" type="Node2D"] +script = ExtResource( 1 ) + +[node name="Block" parent="." instance=ExtResource( 2 )] +position = Vector2( 32, 32 ) +color = Color( 0.717647, 1, 0.952941, 1 ) + +[node name="Block2" parent="." instance=ExtResource( 2 )] +position = Vector2( 32, -32 ) +color = Color( 0.717647, 1, 0.952941, 1 ) + +[node name="Block3" parent="." instance=ExtResource( 2 )] +position = Vector2( 32, -96 ) +color = Color( 0.717647, 1, 0.952941, 1 ) + +[node name="Block4" parent="." instance=ExtResource( 2 )] +position = Vector2( 32, -160 ) +color = Color( 0.717647, 1, 0.952941, 1 ) diff --git a/Shapes/ShapeJ.tscn b/Shapes/ShapeJ.tscn new file mode 100644 index 0000000..52314b0 --- /dev/null +++ b/Shapes/ShapeJ.tscn @@ -0,0 +1,23 @@ +[gd_scene load_steps=3 format=2] + +[ext_resource path="res://Shapes/TetrisShape.gd" type="Script" id=1] +[ext_resource path="res://Shapes/Block.tscn" type="PackedScene" id=2] + +[node name="ShapeJ" type="Node2D"] +script = ExtResource( 1 ) + +[node name="Block" parent="." instance=ExtResource( 2 )] +position = Vector2( -32, 32 ) +color = Color( 0.486275, 0.494118, 1, 1 ) + +[node name="Block2" parent="." instance=ExtResource( 2 )] +position = Vector2( 32, 32 ) +color = Color( 0.486275, 0.494118, 1, 1 ) + +[node name="Block3" parent="." instance=ExtResource( 2 )] +position = Vector2( 32, -32 ) +color = Color( 0.486275, 0.494118, 1, 1 ) + +[node name="Block4" parent="." instance=ExtResource( 2 )] +position = Vector2( 32, -96 ) +color = Color( 0.486275, 0.494118, 1, 1 ) diff --git a/Shapes/ShapeL.tscn b/Shapes/ShapeL.tscn new file mode 100644 index 0000000..39b8774 --- /dev/null +++ b/Shapes/ShapeL.tscn @@ -0,0 +1,23 @@ +[gd_scene load_steps=3 format=2] + +[ext_resource path="res://Shapes/TetrisShape.gd" type="Script" id=1] +[ext_resource path="res://Shapes/Block.tscn" type="PackedScene" id=2] + +[node name="ShapeL" type="Node2D"] +script = ExtResource( 1 ) + +[node name="Block" parent="." instance=ExtResource( 2 )] +position = Vector2( -32, 32 ) +color = Color( 1, 0.47451, 0.47451, 1 ) + +[node name="Block3" parent="." instance=ExtResource( 2 )] +position = Vector2( -32, -32 ) +color = Color( 1, 0.47451, 0.47451, 1 ) + +[node name="Block4" parent="." instance=ExtResource( 2 )] +position = Vector2( -32, -96 ) +color = Color( 1, 0.47451, 0.47451, 1 ) + +[node name="Block2" parent="." instance=ExtResource( 2 )] +position = Vector2( 32, 32 ) +color = Color( 1, 0.47451, 0.47451, 1 ) diff --git a/Shapes/ShapeO.tscn b/Shapes/ShapeO.tscn new file mode 100644 index 0000000..d69bdf4 --- /dev/null +++ b/Shapes/ShapeO.tscn @@ -0,0 +1,23 @@ +[gd_scene load_steps=3 format=2] + +[ext_resource path="res://Shapes/TetrisShape.gd" type="Script" id=1] +[ext_resource path="res://Shapes/Block.tscn" type="PackedScene" id=2] + +[node name="ShapeSquare" type="Node2D"] +script = ExtResource( 1 ) + +[node name="Block" parent="." instance=ExtResource( 2 )] +position = Vector2( 32, 32 ) +color = Color( 0.827451, 1, 0.490196, 1 ) + +[node name="Block2" parent="." instance=ExtResource( 2 )] +position = Vector2( 32, -32 ) +color = Color( 0.827451, 1, 0.490196, 1 ) + +[node name="Block3" parent="." instance=ExtResource( 2 )] +position = Vector2( -32, -32 ) +color = Color( 0.827451, 1, 0.490196, 1 ) + +[node name="Block4" parent="." instance=ExtResource( 2 )] +position = Vector2( -32, 32 ) +color = Color( 0.827451, 1, 0.490196, 1 ) diff --git a/Shapes/ShapeS.tscn b/Shapes/ShapeS.tscn new file mode 100644 index 0000000..816b84b --- /dev/null +++ b/Shapes/ShapeS.tscn @@ -0,0 +1,23 @@ +[gd_scene load_steps=3 format=2] + +[ext_resource path="res://Shapes/TetrisShape.gd" type="Script" id=1] +[ext_resource path="res://Shapes/Block.tscn" type="PackedScene" id=2] + +[node name="ShapeS" type="Node2D"] +script = ExtResource( 1 ) + +[node name="Block" parent="." instance=ExtResource( 2 )] +position = Vector2( -32, 32 ) +color = Color( 0.607843, 1, 0.603922, 1 ) + +[node name="Block2" parent="." instance=ExtResource( 2 )] +position = Vector2( 32, 32 ) +color = Color( 0.607843, 1, 0.603922, 1 ) + +[node name="Block3" parent="." instance=ExtResource( 2 )] +position = Vector2( 32, -32 ) +color = Color( 0.607843, 1, 0.603922, 1 ) + +[node name="Block4" parent="." instance=ExtResource( 2 )] +position = Vector2( 96, -32 ) +color = Color( 0.607843, 1, 0.603922, 1 ) diff --git a/Shapes/ShapeT.tscn b/Shapes/ShapeT.tscn new file mode 100644 index 0000000..0c8f21b --- /dev/null +++ b/Shapes/ShapeT.tscn @@ -0,0 +1,23 @@ +[gd_scene load_steps=3 format=2] + +[ext_resource path="res://Shapes/TetrisShape.gd" type="Script" id=1] +[ext_resource path="res://Shapes/Block.tscn" type="PackedScene" id=2] + +[node name="ShapeT" type="Node2D"] +script = ExtResource( 1 ) + +[node name="Block" parent="." instance=ExtResource( 2 )] +position = Vector2( -32, 32 ) +color = Color( 0.968627, 0.411765, 1, 1 ) + +[node name="Block2" parent="." instance=ExtResource( 2 )] +position = Vector2( 32, 32 ) +color = Color( 0.968627, 0.411765, 1, 1 ) + +[node name="Block3" parent="." instance=ExtResource( 2 )] +position = Vector2( 32, -32 ) +color = Color( 0.968627, 0.411765, 1, 1 ) + +[node name="Block4" parent="." instance=ExtResource( 2 )] +position = Vector2( 96, 32 ) +color = Color( 0.968627, 0.411765, 1, 1 ) diff --git a/Shapes/ShapeZ.tscn b/Shapes/ShapeZ.tscn new file mode 100644 index 0000000..f5bdab1 --- /dev/null +++ b/Shapes/ShapeZ.tscn @@ -0,0 +1,23 @@ +[gd_scene load_steps=3 format=2] + +[ext_resource path="res://Shapes/TetrisShape.gd" type="Script" id=1] +[ext_resource path="res://Shapes/Block.tscn" type="PackedScene" id=2] + +[node name="ShapeZ" type="Node2D"] +script = ExtResource( 1 ) + +[node name="Block" parent="." instance=ExtResource( 2 )] +position = Vector2( -32, -32 ) +color = Color( 0.984314, 1, 0.537255, 1 ) + +[node name="Block2" parent="." instance=ExtResource( 2 )] +position = Vector2( 32, -32 ) +color = Color( 0.984314, 1, 0.537255, 1 ) + +[node name="Block3" parent="." instance=ExtResource( 2 )] +position = Vector2( 32, 32 ) +color = Color( 0.984314, 1, 0.537255, 1 ) + +[node name="Block4" parent="." instance=ExtResource( 2 )] +position = Vector2( 96, 32 ) +color = Color( 0.984314, 1, 0.537255, 1 ) diff --git a/TetrisShape.gd b/Shapes/TetrisShape.gd similarity index 100% rename from TetrisShape.gd rename to Shapes/TetrisShape.gd diff --git a/UI.gd b/UI.gd index a25d134..9712468 100644 --- a/UI.gd +++ b/UI.gd @@ -1,6 +1,10 @@ extends Control +func _ready(): + _set_safe_area() + + func update_score(new_score): $VBoxContainer/HBoxContainer/Score.text = str(new_score) @@ -10,3 +14,18 @@ func set_next_shape(shape_scene): child.free() $VBoxContainer/HBoxContainer/NextShape/Origin.add_child(shape_scene.instance()) + + +# Resizes the UI to accomodate for notches, rounded corners, etc on mobile +# Adapted from https://github.com/godotengine/godot/issues/49887 +func _set_safe_area(): + var window_to_root = Transform2D.IDENTITY.scaled(get_tree().root.size / OS.window_size) + var safe_area_root = window_to_root.xform(OS.get_window_safe_area()) + + assert(get_viewport() == get_tree().root, "Assumption: control is not in a nested Viewport") + var parent_to_root = get_viewport_transform() * get_global_transform() * get_transform().affine_inverse() + var root_to_parent = parent_to_root.affine_inverse() + + var safe_area_relative_to_parent = root_to_parent.xform(safe_area_root) + rect_position = safe_area_relative_to_parent.position + rect_size = safe_area_relative_to_parent.size diff --git a/project.godot b/project.godot index e620c0c..fd3e327 100644 --- a/project.godot +++ b/project.godot @@ -12,7 +12,7 @@ _global_script_classes=[ { "base": "Node2D", "class": "TetrisShape", "language": "GDScript", -"path": "res://TetrisShape.gd" +"path": "res://Shapes/TetrisShape.gd" } ] _global_script_class_icons={ "TetrisShape": ""