-
Notifications
You must be signed in to change notification settings - Fork 1
/
Player.gd
56 lines (48 loc) · 1.27 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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
extends KinematicBody2D
# Vector2(X,Y)
var motion = Vector2.ZERO
# var direction : Vector2 = Vector2()
var starting_position
const invincibility_duration = 1.5
onready var hurtbox = $Hurtbox_Player
onready var blinker = $Blinker
func _ready():
starting_position = get_global_position()
func _physics_process(delta):
motion = Vector2()
# moving right
if Input.is_action_pressed("right"):
motion.x = 100
print("right pressed")
# moving left
elif Input.is_action_pressed("left"):
motion.x = -100
print("left pressed")
else:
motion.x = 0
print("idle")
# moving up
if Input.is_action_pressed("up"):
motion.y = -100
print("up pressed")
# moving down
elif Input.is_action_pressed("down"):
motion.y = 100
print("down pressed")
# no movement
else:
motion.y = 0
print("idle")
move_and_collide(motion*delta)
func _on_Hurtbox_Player_area_entered(area):
pass
func _on_Hurtbox_Player_body_entered(body):
# if the player get's hit by a ghost, the scene starts over
# and player is sent back to start of maze
if (body.get_name() == 'Ghost'):
print("start over")
if !hurtbox.is_invincible:
print("ouch")
blinker.start_blinking(self, invincibility_duration)
hurtbox.start_invincibility(invincibility_duration)
get_tree().change_scene("res://Scene.tscn")