-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlayer.gd
33 lines (28 loc) · 1.13 KB
/
Player.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
extends KinematicBody2D
signal player_moved
var velocity
func _ready():
velocity = 0
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
var velocity = Vector2()
if Input.is_action_pressed("ui_right"):
velocity -= 300 * $Area2D.gravity_vec.normalized().rotated(TAU/4)
if Input.is_action_pressed("ui_left"):
velocity += 300 * $Area2D.gravity_vec.normalized().rotated(TAU/4)
if Input.is_action_pressed("ui_down"):
velocity += 300 * $Area2D.gravity_vec.normalized()
if Input.is_action_pressed("ui_up"):
velocity -= 300 * $Area2D.gravity_vec.normalized()
if velocity.length() > 0:
$AnimatedSprite.play()
position += velocity*delta
emit_signal("player_moved", position)
else:
$AnimatedSprite.stop()
if get_parent().planet2 != null:
$Area2D.gravity_vec = get_parent().planet2.absolute_ish_position() + get_parent().planet2.get_size()/2 - position
$AnimatedSprite.set_rotation($Area2D.gravity_vec.angle()-TAU/4)#(-atan2($Area2D.gravity_vec.y, $Area2D.gravity_vec.x))
func _physics_process(delta):
move_and_collide($Area2D.gravity_vec/10000)
emit_signal("player_moved", position)