33 lines
880 B
GDScript
33 lines
880 B
GDScript
extends CharacterBody2D
|
|
|
|
var direction = -1
|
|
var directiony = -1
|
|
var speed = 15
|
|
|
|
# Called when the node enters the scene tree for the first time.
|
|
func _ready() -> void:
|
|
$sprites.play()
|
|
|
|
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
|
func _process(delta: float) -> void:
|
|
# Pursue Jean
|
|
if $"../jean"/sprites.global_position.x > $sprites.global_position.x:
|
|
if direction == -1:
|
|
$sprites.flip_h = false
|
|
direction = 1
|
|
else:
|
|
if direction == 1:
|
|
$sprites.flip_h = true
|
|
direction = -1
|
|
if $"../jean"/sprites.global_position.y > $sprites.global_position.y:
|
|
directiony = 1
|
|
else:
|
|
directiony = -1
|
|
velocity.x = direction * speed
|
|
velocity.y = directiony * speed
|
|
move_and_slide()
|
|
|
|
func _on_area_2d_body_entered(body: Node2D) -> void:
|
|
if body.is_in_group("player") and Global.jeandeath == 0:
|
|
Global.jeandeath = 1
|
|
Global.jeanblocked = 1
|