some workable stuff

This commit is contained in:
Victor Turgeon
2023-10-10 14:54:21 -04:00
parent b763efc1f6
commit 2687a2fdfe
7 changed files with 70 additions and 25 deletions

View File

@@ -6,11 +6,13 @@ extends CharacterBody2D
@export var speed : float = 0
@export var damage : int = 0
@export var priority : int = 0
@export var canAttack : bool = true
@onready var ai : Node = $AI
@onready var animatedSprite : AnimatedSprite2D = $AnimatedSprite2D
var isAlive : bool = true
var isFacingLeft : bool = false
var direction : Vector2 = Vector2.ZERO
var enemy : CharacterBody2D = null
@@ -27,19 +29,28 @@ func _process(delta):
return
if enemy != null:
direction = ai.getDirection(position, enemy.position)
direction = ai.getDirection(global_position, enemy.global_position)
else:
direction = Vector2.ZERO
if !isFacingLeft && velocity.x >= 0:
isFacingLeft = true
scale = Vector2(1, 1)
elif isFacingLeft && velocity.x < 0:
isFacingLeft = false
scale = Vector2(-1, 1)
velocity = direction * speed * delta
move_and_slide()
func attack(target):
func attack():
if !canAttack || !isAlive:
return
animatedSprite.play("attack")
animatedSprite.connect("animation_finished", endAttack(target))
animatedSprite.connect("animation_finished", endAttack)
func endAttack(target):
target.receive_damage(damage)
func endAttack():
animatedSprite.play("default")
func receive_damage(dmg):
@@ -55,13 +66,13 @@ func receive_damage(dmg):
func die():
isAlive = false
animatedSprite.play("death")
animatedSprite.connect("animation_finished", self.fadeOut())
animatedSprite.connect("animation_finished", fadeOut)
func fadeOut():
var tween = Tween.new()
add_child(tween)
var tween = get_tree().create_tween()
tween.tween_property(animatedSprite, "modulate", Color(0,0,0,0), 1)
tween.tween_callback(clean())
tween.tween_callback(clean)
func clean():
queue_free()