-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSystem.gd
57 lines (49 loc) · 2.04 KB
/
System.gd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
extends Node
signal swipeDirection(direction)
################
# Touch events #
################
# Figure out the swipe direction
var initialPoint = Vector2(0,0);
var secondPoint = Vector2(0,0);
# The difference allowed for directional swipe
const vectorSensitivity = Vector2(200, 200)
func _input(event):
if (event is InputEventScreenTouch) and (event.pressed):
initialPoint = event.position;
if (event is InputEventScreenTouch) and (!event.pressed):
secondPoint = event.position;
calculateDirection(initialPoint, secondPoint)
func calculateDirection(firstPt, secondPt):
var deviation = Vector2(int(abs(firstPt.x - secondPt.x)), \
int(abs(firstPt.y - secondPt.y)));
# Check which vector is dominant (X or Y)
if (deviation.x > deviation.y):
# Check direction of X
if (firstPt.x > secondPt.x) and (deviation.x > vectorSensitivity.x):
#Variables.swipeDirection = Variables.SwipeDirection.LEFT
emit_signal("swipeDirection", Variables.SwipeDirection.LEFT)
#print("initial larger x <-" + str(deviation.x))
pass
elif (firstPt.x < secondPt.x) and (deviation.x > vectorSensitivity.x):
#Variables.swipeDirection = Variables.SwipeDirection.RIGHT
emit_signal("swipeDirection", Variables.SwipeDirection.RIGHT)
#print("initial smaller x ->" + str(deviation.x))
pass
else:
# Check direction of Y
if (firstPt.y > secondPt.y) and (deviation.y > vectorSensitivity.y):
#Variables.swipeDirection = Variables.SwipeDirection.UP
emit_signal("swipeDirection", Variables.SwipeDirection.UP)
Variables.showSettings = true
#print("initial larger y U " + str(deviation.y))
pass
elif (firstPt.y < secondPt.y) and (deviation.y > vectorSensitivity.y):
#Variables.swipeDirection = Variables.SwipeDirection.DOWN
emit_signal("swipeDirection", Variables.SwipeDirection.DOWN)
Variables.showSettings = false
#print("initial smaller y D " + str(deviation.y))
pass
else:
#print("no change in xy: " + str(deviation))
pass