tetris
-rw-r--r--.gitignore2
-rw-r--r--Main.tscn8
-rw-r--r--Tetris.gd11
-rw-r--r--assets/circle.styleboxbin0 -> 414 bytes
-rw-r--r--assets/main.themebin0 -> 244 bytes
-rw-r--r--assets/panel.styleboxbin0 -> 435 bytes
-rw-r--r--assets/remap.themebin0 -> 732 bytes
-rw-r--r--assets/ubuntu-bold.ttfbin0 -> 269584 bytes
-rw-r--r--assets/ubuntu.tres7
-rw-r--r--godot.lock4
-rw-r--r--godot.package3
-rw-r--r--project.godot71
-rw-r--r--settings/KeySelector.tscn68
-rw-r--r--settings/RemapHolder.gd13
-rw-r--r--settings/Settings.gd12
-rw-r--r--settings/Settings.tscn62
16 files changed, 253 insertions, 8 deletions
diff --git a/.gitignore b/.gitignore
index 4f5f1d2..324ecbe 100644
--- a/.gitignore
+++ b/.gitignore
@@ -6,5 +6,5 @@ logs/
.vscode/
exports/
*.x86_64
-addons/swipe-detector
+addons/
.github/icon.svg
diff --git a/Main.tscn b/Main.tscn
index 72cc1de..3a3db6a 100644
--- a/Main.tscn
+++ b/Main.tscn
@@ -1,12 +1,15 @@
-[gd_scene load_steps=3 format=2]
+[gd_scene load_steps=5 format=2]
[ext_resource path="res://Tetris.gd" type="Script" id=1]
[ext_resource path="res://addons/swipe-detector/SwipeDetector.gd" type="Script" id=2]
+[ext_resource path="res://settings/Settings.tscn" type="PackedScene" id=3]
+[ext_resource path="res://assets/main.theme" type="Theme" id=4]
[node name="Main" type="Control"]
anchor_right = 1.0
anchor_bottom = 1.0
mouse_filter = 2
+theme = ExtResource( 4 )
[node name="Tetris" type="MarginContainer" parent="."]
anchor_right = 1.0
@@ -24,3 +27,6 @@ bg_color = Color( 0.992157, 0.964706, 0.890196, 1 )
[node name="SwipeDetector" type="Node" parent="."]
script = ExtResource( 2 )
min_swipe_distance = 10.0
+
+[node name="Settings" parent="." instance=ExtResource( 3 )]
+visible = false
diff --git a/Tetris.gd b/Tetris.gd
index 49f1ac6..a2b8bd5 100644
--- a/Tetris.gd
+++ b/Tetris.gd
@@ -53,7 +53,6 @@ func init_squares(on: Control):
on.add_child(aspect)
var sqs := create_grid_container("squares")
aspect.add_child(sqs)
- print_tree_pretty()
for _i in range(ROWS * COLUMNS):
squares.append(create_square(sqs, "%d" % _i))
@@ -181,12 +180,14 @@ func _input(event):
current_shape.rotate(matrix)
tick(false)
- if event.is_action_pressed("ui_left", true):
+ if event.is_action_pressed("left", true):
current_shape.move(Vector2.LEFT, matrix)
- elif event.is_action_pressed("ui_right", true):
+ elif event.is_action_pressed("right", true):
current_shape.move(Vector2.RIGHT, matrix)
- if event.is_action_pressed("ui_up"):
+ if event.is_action_pressed("rotate_cw"):
current_shape.rotate(matrix, true)
+ elif event.is_action_pressed("rotate_anti_cw"):
+ current_shape.rotate(matrix, false)
if event.is_action_pressed("ui_down"):
current_shape.fall(matrix)
tick(false)
@@ -196,7 +197,7 @@ func _input(event):
func tick(create_timer := true):
if create_timer:
- var t := get_tree().create_timer(.25)
+ var t := get_tree().create_timer(.25, false)
t.connect("timeout", self, "tick")
if not current_shape.move(Vector2(0, 1), matrix): # invalid move: cant go down
diff --git a/assets/circle.stylebox b/assets/circle.stylebox
new file mode 100644
index 0000000..8c8105f
--- /dev/null
+++ b/assets/circle.stylebox
Binary files differ
diff --git a/assets/main.theme b/assets/main.theme
new file mode 100644
index 0000000..ad09b63
--- /dev/null
+++ b/assets/main.theme
Binary files differ
diff --git a/assets/panel.stylebox b/assets/panel.stylebox
new file mode 100644
index 0000000..79cec9c
--- /dev/null
+++ b/assets/panel.stylebox
Binary files differ
diff --git a/assets/remap.theme b/assets/remap.theme
new file mode 100644
index 0000000..a12860e
--- /dev/null
+++ b/assets/remap.theme
Binary files differ
diff --git a/assets/ubuntu-bold.ttf b/assets/ubuntu-bold.ttf
new file mode 100644
index 0000000..4af149a
--- /dev/null
+++ b/assets/ubuntu-bold.ttf
Binary files differ
diff --git a/assets/ubuntu.tres b/assets/ubuntu.tres
new file mode 100644
index 0000000..fe50599
--- /dev/null
+++ b/assets/ubuntu.tres
@@ -0,0 +1,7 @@
+[gd_resource type="DynamicFont" load_steps=2 format=2]
+
+[ext_resource path="res://assets/ubuntu-bold.ttf" type="DynamicFontData" id=1]
+
+[resource]
+size = 10
+font_data = ExtResource( 1 )
diff --git a/godot.lock b/godot.lock
index 2772097..68aa3b4 100644
--- a/godot.lock
+++ b/godot.lock
@@ -2,5 +2,9 @@
"@bendn/swipe-detector": {
"version": "1.1.5",
"integrity": "sha512-td5Qr4yiJYE01inyYkxqak6V+Fdy+qm9jgwKMqWvXAbborfbrMJ0c5TXy9OJ0rrmF4Erl7eUYnTJEJan1T0NYA=="
+ },
+ "@bendn/remap": {
+ "version": "1.2.2",
+ "integrity": "sha512-3XCE5CsFahUPPMl9acDKFlObW+kD+NlWmt4EJl4YrhZtfzX5069jVLnbSUF0Ac3CgUep0+I1x36jpnNpoVdHkQ=="
}
} \ No newline at end of file
diff --git a/godot.package b/godot.package
index c98b3e6..dc84bf6 100644
--- a/godot.package
+++ b/godot.package
@@ -1,6 +1,7 @@
{
"name": "tetris",
"packages": {
- "@bendn/swipe-detector": "1.1.5"
+ "@bendn/swipe-detector": "1.1.5",
+ "@bendn/remap": "1.2.2"
}
} \ No newline at end of file
diff --git a/project.godot b/project.godot
index 7b3d042..3dd8cc7 100644
--- a/project.godot
+++ b/project.godot
@@ -9,16 +9,51 @@
config_version=4
_global_script_classes=[ {
+"base": "HBoxContainer",
+"class": "ActionIcons",
+"language": "GDScript",
+"path": "res://addons/remap/ActionIcons.gd"
+}, {
+"base": "HBoxContainer",
+"class": "ActionLabel",
+"language": "GDScript",
+"path": "res://addons/remap/ActionLabel.gd"
+}, {
+"base": "Reference",
+"class": "IconMap",
+"language": "GDScript",
+"path": "res://addons/remap/IconMap.gd"
+}, {
"base": "InputEventAction",
"class": "InputEventSwipe",
"language": "GDScript",
"path": "res://addons/swipe-detector/InputEventSwipe.gd"
}, {
+"base": "Node",
+"class": "KeySelector",
+"language": "GDScript",
+"path": "res://addons/remap/KeySelector.gd"
+}, {
"base": "Reference",
"class": "Logic",
"language": "GDScript",
"path": "res://Logic.gd"
}, {
+"base": "HBoxContainer",
+"class": "RemapButton",
+"language": "GDScript",
+"path": "res://addons/remap/RemapButton.gd"
+}, {
+"base": "Reference",
+"class": "RemapUtilities",
+"language": "GDScript",
+"path": "res://addons/remap/RemapUtilities.gd"
+}, {
+"base": "Node",
+"class": "SaveLoadUtils",
+"language": "GDScript",
+"path": "res://addons/remap/SaveLoadUtils.gd"
+}, {
"base": "Node",
"class": "SwipeDetector",
"language": "GDScript",
@@ -35,8 +70,15 @@ _global_script_classes=[ {
"path": "res://TetrisPiece.gd"
} ]
_global_script_class_icons={
+"ActionIcons": "",
+"ActionLabel": "",
+"IconMap": "",
"InputEventSwipe": "",
+"KeySelector": "",
"Logic": "",
+"RemapButton": "",
+"RemapUtilities": "",
+"SaveLoadUtils": "",
"SwipeDetector": "",
"Tetris": "",
"TetrisPiece": ""
@@ -71,6 +113,35 @@ unused={
"deadzone": 0.5,
"events": [ ]
}
+left={
+"deadzone": 0.5,
+"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777231,"physical_scancode":0,"unicode":0,"echo":false,"script":null)
+ ]
+}
+right={
+"deadzone": 0.5,
+"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777233,"physical_scancode":0,"unicode":0,"echo":false,"script":null)
+ ]
+}
+down={
+"deadzone": 0.5,
+"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777234,"physical_scancode":0,"unicode":0,"echo":false,"script":null)
+ ]
+}
+rotate_cw={
+"deadzone": 0.5,
+"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777232,"physical_scancode":0,"unicode":0,"echo":false,"script":null)
+ ]
+}
+rotate_anti_cw={
+"deadzone": 0.5,
+"events": [ ]
+}
+pause={
+"deadzone": 0.5,
+"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777217,"physical_scancode":0,"unicode":0,"echo":false,"script":null)
+ ]
+}
[logging]
diff --git a/settings/KeySelector.tscn b/settings/KeySelector.tscn
new file mode 100644
index 0000000..6e6e658
--- /dev/null
+++ b/settings/KeySelector.tscn
@@ -0,0 +1,68 @@
+[gd_scene load_steps=6 format=2]
+
+[ext_resource path="res://addons/remap/KeyPromptLabel.gd" type="Script" id=1]
+[ext_resource path="res://addons/remap/KeySelector.gd" type="Script" id=2]
+[ext_resource path="res://assets/remap.theme" type="Theme" id=3]
+[ext_resource path="res://addons/remap/PromptFont.ttf" type="DynamicFontData" id=4]
+
+[sub_resource type="DynamicFont" id=1]
+size = 50
+font_data = ExtResource( 4 )
+
+[node name="KeySelector" type="CanvasLayer"]
+script = ExtResource( 2 )
+
+[node name="Background" type="ColorRect" parent="."]
+anchor_right = 1.0
+anchor_bottom = 1.0
+theme = ExtResource( 3 )
+color = Color( 0.160156, 0.160156, 0.160156, 0.705882 )
+
+[node name="Center" type="CenterContainer" parent="Background"]
+anchor_right = 1.0
+anchor_bottom = 1.0
+
+[node name="V" type="VBoxContainer" parent="Background/Center"]
+margin_left = 13.0
+margin_top = 75.0
+margin_right = 167.0
+margin_bottom = 168.0
+
+[node name="Label" type="Label" parent="Background/Center/V"]
+margin_right = 154.0
+margin_bottom = 12.0
+text = "type any key"
+align = 1
+
+[node name="KeyPrompter" type="Label" parent="Background/Center/V"]
+unique_name_in_owner = true
+margin_top = 16.0
+margin_right = 154.0
+margin_bottom = 77.0
+rect_min_size = Vector2( 125, 0 )
+custom_fonts/font = SubResource( 1 )
+align = 1
+script = ExtResource( 1 )
+
+[node name="H" type="HBoxContainer" parent="Background/Center/V"]
+margin_top = 81.0
+margin_right = 154.0
+margin_bottom = 93.0
+
+[node name="ok" type="Button" parent="Background/Center/V/H"]
+unique_name_in_owner = true
+margin_right = 50.0
+margin_bottom = 12.0
+rect_min_size = Vector2( 50, 0 )
+size_flags_horizontal = 3
+disabled = true
+text = "ok"
+
+[node name="cancel" type="Button" parent="Background/Center/V/H"]
+unique_name_in_owner = true
+margin_left = 54.0
+margin_right = 154.0
+margin_bottom = 12.0
+rect_min_size = Vector2( 100, 0 )
+size_flags_horizontal = 3
+text = "cancel"
diff --git a/settings/RemapHolder.gd b/settings/RemapHolder.gd
new file mode 100644
index 0000000..54838f5
--- /dev/null
+++ b/settings/RemapHolder.gd
@@ -0,0 +1,13 @@
+extends VBoxContainer
+
+const remappable = ["left", "right", "down", "rotate_cw", "rotate_anti_cw"]
+
+
+func _ready():
+ for remap in remappable:
+ var l := RemapButton.new()
+ l.action = remap
+ l._name = " %s " % remap.replace("_", " ").replace("cw", "clockwise")
+ l.icon_size = Vector2(20, 20)
+ l.popup = preload("./KeySelector.tscn")
+ add_child(l)
diff --git a/settings/Settings.gd b/settings/Settings.gd
new file mode 100644
index 0000000..d346f8b
--- /dev/null
+++ b/settings/Settings.gd
@@ -0,0 +1,12 @@
+extends Control
+
+
+func _input(event):
+ if event.is_action_pressed("pause"):
+ get_tree().paused = !get_tree().paused
+ visible = get_tree().paused
+
+
+func unpause():
+ get_tree().paused = false
+ visible = false
diff --git a/settings/Settings.tscn b/settings/Settings.tscn
new file mode 100644
index 0000000..18d933e
--- /dev/null
+++ b/settings/Settings.tscn
@@ -0,0 +1,62 @@
+[gd_scene load_steps=5 format=2]
+
+[ext_resource path="res://assets/main.theme" type="Theme" id=1]
+[ext_resource path="res://settings/RemapHolder.gd" type="Script" id=2]
+[ext_resource path="res://assets/remap.theme" type="Theme" id=3]
+[ext_resource path="res://settings/Settings.gd" type="Script" id=4]
+
+[node name="Settings" type="ColorRect"]
+pause_mode = 2
+anchor_right = 1.0
+anchor_bottom = 1.0
+theme = ExtResource( 1 )
+color = Color( 0.345, 0.433167, 0.46, 0.392157 )
+script = ExtResource( 4 )
+__meta__ = {
+"_editor_description_": ""
+}
+
+[node name="MC" type="MarginContainer" parent="."]
+anchor_right = 1.0
+anchor_bottom = 1.0
+custom_constants/margin_right = 5
+custom_constants/margin_top = 5
+custom_constants/margin_left = 5
+custom_constants/margin_bottom = 5
+
+[node name="P" type="PanelContainer" parent="MC"]
+margin_left = 5.0
+margin_top = 5.0
+margin_right = 175.0
+margin_bottom = 238.0
+
+[node name="RemapHolder" type="VBoxContainer" parent="MC/P"]
+margin_left = 5.0
+margin_top = 5.0
+margin_right = 165.0
+margin_bottom = 228.0
+size_flags_horizontal = 3
+size_flags_vertical = 3
+theme = ExtResource( 3 )
+script = ExtResource( 2 )
+
+[node name="h" type="HBoxContainer" parent="MC/P/RemapHolder"]
+margin_right = 160.0
+margin_bottom = 13.0
+
+[node name="BackButton" type="Button" parent="MC/P/RemapHolder/h"]
+margin_right = 30.0
+margin_bottom = 13.0
+rect_min_size = Vector2( 30, 13 )
+text = " back "
+
+[node name="Labeler" type="Label" parent="MC/P/RemapHolder/h"]
+margin_left = 34.0
+margin_right = 160.0
+margin_bottom = 12.0
+size_flags_horizontal = 3
+custom_colors/font_color = Color( 0.396078, 0.482353, 0.513726, 1 )
+text = "remap controls"
+align = 1
+
+[connection signal="pressed" from="MC/P/RemapHolder/h/BackButton" to="." method="unpause"]