tetris
-rw-r--r--.gitignore1
-rw-r--r--Main.tscn21
-rw-r--r--Tetris.gd20
-rw-r--r--TetrisPiece.gd5
-rw-r--r--godot.lock6
-rw-r--r--godot.package6
-rwxr-xr-xinstall_addons.sh8
-rw-r--r--project.godot19
8 files changed, 78 insertions, 8 deletions
diff --git a/.gitignore b/.gitignore
index 5bbe921..f4cf9e0 100644
--- a/.gitignore
+++ b/.gitignore
@@ -6,3 +6,4 @@ logs/
.vscode/
exports/
*.x86_64
+addons/swipe-detector
diff --git a/Main.tscn b/Main.tscn
index ede399a..748dc0e 100644
--- a/Main.tscn
+++ b/Main.tscn
@@ -1,13 +1,26 @@
-[gd_scene load_steps=2 format=2]
+[gd_scene load_steps=3 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]
-[node name="Main" type="Control"]
+[node name="Main" type="MarginContainer"]
anchor_right = 1.0
anchor_bottom = 1.0
+mouse_filter = 2
+custom_constants/margin_right = 10
+custom_constants/margin_top = 10
+custom_constants/margin_left = 10
+custom_constants/margin_bottom = 10
[node name="Tetris" type="AspectRatioContainer" parent="."]
-anchor_right = 1.0
-anchor_bottom = 1.0
+margin_left = 10.0
+margin_top = 10.0
+margin_right = 170.0
+margin_bottom = 310.0
script = ExtResource( 1 )
colors = PoolColorArray( 0.811765, 0.176471, 0.176471, 1, 0.427451, 0.721569, 0.278431, 1, 0.156863, 0.270588, 0.709804, 1, 0.615686, 0.164706, 0.611765, 1, 0.717647, 0.713726, 0.282353, 1, 0.47451, 0.47451, 0.47451, 1, 0.835294, 0.588235, 0.113725, 1 )
+
+[node name="SwipeDetector" type="Node" parent="."]
+script = ExtResource( 2 )
+swipe_timeout = 0.3
+min_swipe_distance = 50.0
diff --git a/Tetris.gd b/Tetris.gd
index 81e78a3..73a0dd7 100644
--- a/Tetris.gd
+++ b/Tetris.gd
@@ -80,15 +80,27 @@ func draw_board(mat: Array = matrix.duplicate(true), shape: TetrisPiece = curren
func _input(event):
+ if event is InputEventSwipe:
+ match event.direction.round().normalized():
+ Vector2.RIGHT:
+ current_shape.move(Vector2.RIGHT, matrix)
+ Vector2.LEFT:
+ current_shape.move(Vector2.LEFT, matrix)
+ Vector2.DOWN:
+ current_shape.fall(matrix)
+ tick(false)
+ _:
+ current_shape.rotate(matrix)
+ tick(false)
+
if event.is_action_pressed("ui_left", true):
- current_shape.move(Vector2(-1, 0), matrix)
+ current_shape.move(Vector2.LEFT, matrix)
elif event.is_action_pressed("ui_right", true):
- current_shape.move(Vector2(1, 0), matrix)
+ current_shape.move(Vector2.RIGHT, matrix)
if event.is_action_pressed("ui_up"):
current_shape.rotate(matrix, true)
if event.is_action_pressed("ui_down"):
- while current_shape.move(Vector2(0, 1), matrix):
- continue
+ current_shape.fall(matrix)
tick(false)
else:
draw_board()
diff --git a/TetrisPiece.gd b/TetrisPiece.gd
index 9d9dc38..cb1da80 100644
--- a/TetrisPiece.gd
+++ b/TetrisPiece.gd
@@ -72,3 +72,8 @@ func rotate(matrix: Array, cw := true):
shape = s
return false
return true
+
+
+func fall(matrix: Array) -> void:
+ while move(Vector2.DOWN, matrix):
+ continue
diff --git a/godot.lock b/godot.lock
new file mode 100644
index 0000000..2772097
--- /dev/null
+++ b/godot.lock
@@ -0,0 +1,6 @@
+{
+ "@bendn/swipe-detector": {
+ "version": "1.1.5",
+ "integrity": "sha512-td5Qr4yiJYE01inyYkxqak6V+Fdy+qm9jgwKMqWvXAbborfbrMJ0c5TXy9OJ0rrmF4Erl7eUYnTJEJan1T0NYA=="
+ }
+} \ No newline at end of file
diff --git a/godot.package b/godot.package
new file mode 100644
index 0000000..c98b3e6
--- /dev/null
+++ b/godot.package
@@ -0,0 +1,6 @@
+{
+ "name": "tetris",
+ "packages": {
+ "@bendn/swipe-detector": "1.1.5"
+ }
+} \ No newline at end of file
diff --git a/install_addons.sh b/install_addons.sh
new file mode 100755
index 0000000..98a3ef2
--- /dev/null
+++ b/install_addons.sh
@@ -0,0 +1,8 @@
+#!/usr/bin/env bash
+
+rm -rf addons && mkdir addons
+git clone --depth 1 https://github.com/you-win/godot-package-manager
+mv godot-package-manager/addons/godot-package-manager addons/
+rm -rf godot-package-manager
+godot -s --no-window addons/godot-package-manager/cli.gd update
+rm -rf addons/godot-package-manager
diff --git a/project.godot b/project.godot
index 308345a..4591f2c 100644
--- a/project.godot
+++ b/project.godot
@@ -9,11 +9,21 @@
config_version=4
_global_script_classes=[ {
+"base": "InputEventAction",
+"class": "InputEventSwipe",
+"language": "GDScript",
+"path": "res://addons/swipe-detector/InputEventSwipe.gd"
+}, {
"base": "Reference",
"class": "Logic",
"language": "GDScript",
"path": "res://Logic.gd"
}, {
+"base": "Node",
+"class": "SwipeDetector",
+"language": "GDScript",
+"path": "res://addons/swipe-detector/SwipeDetector.gd"
+}, {
"base": "AspectRatioContainer",
"class": "Tetris",
"language": "GDScript",
@@ -25,7 +35,9 @@ _global_script_classes=[ {
"path": "res://TetrisPiece.gd"
} ]
_global_script_class_icons={
+"InputEventSwipe": "",
"Logic": "",
+"SwipeDetector": "",
"Tetris": "",
"TetrisPiece": ""
}
@@ -51,6 +63,13 @@ window/dpi/allow_hidpi=true
window/stretch/mode="2d"
window/stretch/aspect="expand"
+[input]
+
+unused={
+"deadzone": 0.5,
+"events": [ ]
+}
+
[logging]
file_logging/enable_file_logging=true