-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlayer.tscn
54 lines (41 loc) · 1.27 KB
/
Player.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
42
43
44
45
46
47
48
49
50
51
52
53
54
[gd_scene load_steps=3 format=2]
[sub_resource type="GDScript" id=2]
script/source = "extends Area2D
signal hit
var screen_size # Size of the app window
export var speed = 400 # How fast the gabor will move (pixels/sec)
func _ready():
screen_size = get_viewport_rect().size
hide()
func _process(delta):
var velocity = Vector2.ZERO # movement vector
if Input.is_action_pressed(\"move_right\"):
velocity.x += 1
if Input.is_action_pressed(\"move_left\"):
velocity.x -= 1
if velocity.length() > 0:
velocity = velocity.normalized() * speed
position += velocity * delta
position.x = clamp(position.x, 0, screen_size.x)
var center_left = (screen_size.x / 2) - 5
var center_right = (screen_size.x / 2) + 5
if position.x >= center_left and position.x <= center_right:
emit_signal(\"hit\")
func start(pos):
position = pos
show()
func change_texture(filename):
var imported_resource = load(filename)
$Sprite.texture = imported_resource
print(\"texture loaded: \", filename)
"
[sub_resource type="CircleShape2D" id=1]
[node name="Player" type="Area2D"]
script = SubResource( 2 )
__meta__ = {
"_edit_group_": true
}
[node name="Sprite" type="Sprite" parent="."]
position = Vector2( 0, 3 )
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
shape = SubResource( 1 )