-
Notifications
You must be signed in to change notification settings - Fork 38
/
input_handler.gd
37 lines (30 loc) · 915 Bytes
/
input_handler.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
extends Control
onready var game = get_node ("Spatial")
onready var width = Globals.get("display/width")
var last_pos = 0
var touchs_vec = {}
func _ready():
get_node("LevelLabel").set_text("Level " + str(global.level))
set_process_input(true)
func handle_pos (pos):
var rot_pos = ((-(pos - last_pos) * 300) / width)
if (!game.receive_input (rot_pos)):
game.lock_rot();
last_pos = pos
func _input(event):
if (event.type==InputEvent.SCREEN_TOUCH):
if (event.pressed):
touchs_vec[event.index] = event.pos.x
if (touchs_vec.size() == 1):
last_pos = event.pos.x
game.lock_rot();
else:
touchs_vec.erase(event.index)
if (touchs_vec.size() == 1):
last_pos = touchs_vec.values()[0]
game.lock_rot();
elif (event.type==InputEvent.SCREEN_DRAG):
touchs_vec[event.index] = event.pos.x
var a = event.pos.x
if (touchs_vec.size() == 1):
handle_pos (event.pos.x)