abbayedesmorts-godot/scripts/death.gd

48 lines
1.2 KiB
GDScript

extends Area2D
var direction = 0 #0 left to right, 1 right to left
var counter = 0
var retnormal = 0
var saxes = preload("res://scenes/axes.tscn")
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
$sprites.play()
Global.axes = 0
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
if counter < 90:
counter += 60 * delta
else:
counter = 0
if counter == 0 and Global.axes < 5:
# Shoot one axe
$sprites.play("shoot")
Global.axes += 1
var naxe = saxes.instantiate()
get_tree().root.add_child(naxe)
naxe.add_to_group("disparos")
naxe.position = $".".position
retnormal = 1
if counter > 8 and retnormal == 1:
# Return to frame of "don't shoot"
$sprites.play("default")
retnormal = 0
if direction == 1:
if position.x > 32:
position.x -= 50 * delta
else:
direction = 0
$sprites.flip_h = false
else:
if position.x < 223:
position.x += 50 * delta
else:
direction = 1
$sprites.flip_h = true
func _on_body_entered(body: Node2D) -> void:
if body.is_in_group("player") and Global.jeandeath == 0:
Global.jeandeath = 1
Global.jeanblocked = 1