abbayedesmorts-godot/scripts/worm.gd

30 lines
760 B
GDScript

extends Area2D
var limitx = [0,0]
var direction = 0 # 0 - left to right, 1 right to left
var speed = 0
# 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:
if Global.stop == 0:
if direction == 0:
if limitx[1] > position.x:
position.x += speed * delta
else:
direction = 1
$sprites.flip_h = true
else:
if limitx[0] < position.x:
position.x -= speed * delta
else:
direction = 0
$sprites.flip_h = false
func _on_body_entered(body: Node2D) -> void:
if body.is_in_group("player") and Global.jeandeath == 0:
Global.jeandeath = 1
Global.jeanblocked = 1