-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBigCircle.gd
37 lines (29 loc) · 915 Bytes
/
BigCircle.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 Sprite
const RADIUS = 60
const SMALL_RADIUS = 24
var stick_pos
var evt_index = -1
func _init():
stick_pos = position
func _input(event):
if event is InputEventScreenTouch:
if event.is_pressed():
if stick_pos.distance_to(event.position) < RADIUS:
evt_index = event.index
elif evt_index != -1:
if evt_index == event.index:
evt_index = -1
$SmallCircle.position = Vector2()
$"../".stick_vector = Vector2()
$"../".stick_speed = 0
$"../".stick_angle = 0
if evt_index != -1 and event is InputEventScreenDrag:
var dist = stick_pos.distance_to(event.position)
if dist + SMALL_RADIUS > RADIUS:
dist = RADIUS - SMALL_RADIUS
var vect = (event.position - stick_pos).normalized()
var ang = event.position.angle_to_point(stick_pos)
$"../".stick_vector = vect
$"../".stick_speed = dist
$"../".stick_angle = ang
$SmallCircle.position = vect * dist