45 lines
1.1 KiB
GDScript
45 lines
1.1 KiB
GDScript
extends KinematicBody2D
|
|
|
|
export var vertical_speed= 4.2
|
|
export var horizontal_speed= 1.75
|
|
var ghost_dead = false
|
|
export var fall_speed= 0.1
|
|
export var side_speed= 0.0
|
|
var direction=Vector2()
|
|
|
|
signal _on_visibilty_exit
|
|
signal _on_death
|
|
|
|
# Called when the node enters the scene tree for the first time.
|
|
func _ready():
|
|
$AnimationPlayer.play("idle")
|
|
|
|
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
|
#func _process(delta):
|
|
# pass
|
|
func _physics_process(delta):
|
|
direction=Vector2(side_speed, fall_speed)
|
|
if ghost_dead==false:
|
|
if Input.is_action_pressed("move_up"):
|
|
direction[1] = -1
|
|
elif Input.is_action_pressed("move_down"):
|
|
direction[1] = 1
|
|
if Input.is_action_pressed("move_left"):
|
|
direction[0] = -1
|
|
if Input.is_action_pressed("move_right"):
|
|
direction[0] = 1
|
|
move_and_collide(Vector2(direction[0]*horizontal_speed, direction[1]*vertical_speed))
|
|
|
|
|
|
func _on_collide():
|
|
emit_signal("_on_death")
|
|
ghost_dead = true
|
|
collision_layer=0
|
|
collision_mask=0
|
|
$AnimationPlayer.play("Death_1")
|
|
$AnimationPlayer.queue("death_2")
|
|
|
|
|
|
func _on_VisibilityNotifier2D_screen_exited():
|
|
emit_signal("_on_visibilty_exit")
|