-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathslingshot.tscn
41 lines (28 loc) · 956 Bytes
/
slingshot.tscn
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
[gd_scene load_steps=3 format=2]
[ext_resource path="res://icon.png" type="Texture" id=1]
[sub_resource type="GDScript" id=1]
script/source = "extends Sprite
var velocity = Vector2(0,0)
var gravity = 0.1
var wire_length = 50
var momentum = 0
func _input(event):
if event is InputEventMouseButton:
wire_length = position.distance_to(event.position)
func _process(delta):
var m = get_global_mouse_position()
velocity.y += gravity
if Input.is_mouse_button_pressed(BUTTON_LEFT):
momentum = velocity.length()
position = move_2ward(position, m, momentum)
else:
position += velocity
if position.y>get_viewport_rect().size.y: position.y = 0
func move_2ward(a:Vector2, b:Vector2, amount:float):
return Vector2( move_toward(a.x,b.x,amount), move_toward(a.y,b.y,amount) )
"
[node name="Node2D" type="Node2D"]
[node name="icon" type="Sprite" parent="."]
position = Vector2( 44, 44 )
texture = ExtResource( 1 )
script = SubResource( 1 )