This commit is contained in:
Victor Turgeon 2023-10-10 19:38:31 -04:00
commit d518691cea
2 changed files with 47 additions and 27 deletions

View File

@ -103,6 +103,7 @@ func die():
animatedSprite.play("death") animatedSprite.play("death")
animatedSprite.disconnect("animation_finished", endAttack) animatedSprite.disconnect("animation_finished", endAttack)
animatedSprite.connect("animation_finished", fadeOut) animatedSprite.connect("animation_finished", fadeOut)
enemy.remove_foe(self)
func fadeOut(): func fadeOut():
var tween = get_tree().create_tween() var tween = get_tree().create_tween()

View File

@ -44,11 +44,13 @@ func _ready():
atk1r.set_disabled(true) atk1r.set_disabled(true)
atk2l.set_disabled(true) atk2l.set_disabled(true)
atk2r.set_disabled(true) atk2r.set_disabled(true)
list.append($"../BatSpawnable")
list.append($"../BatSpawnable2")
# Called every frame. 'delta' is the elapsed time since the previous frame. # Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta): func _process(delta):
if abs(velocity.x) < 0.1 && abs(velocity.y) < 0.1 && !is_attacking: if abs(velocity.x) < 0.2 && abs(velocity.y) < 0.2 && !is_attacking:
setAnimState("Idle") setAnimState("Idle")
elif !is_attacking: elif !is_attacking:
setAnimState("Run") setAnimState("Run")
@ -57,32 +59,33 @@ func _process(delta):
is_facing_left = velocity.x > 0 && !(velocity.x < 0) is_facing_left = velocity.x > 0 && !(velocity.x < 0)
# AI STUFF # AI STUFF
#velocity += processAI(list,delta) velocity += processAI(list) * delta
var x = 0 #var x = 0
var y = 0 #var y = 0
if Input.is_action_pressed("ui_left"): #if Input.is_action_pressed("ui_left"):
# # Move as long as the key/button is pressed.
# x -= delta * 50
#elif Input.is_action_pressed("ui_right"):
# # Move as long as the key/button is pressed.
# x += delta * 50
#else:
# velocity.x *= 0.8
#if Input.is_action_pressed("ui_up"):
# Move as long as the key/button is pressed. # Move as long as the key/button is pressed.
x -= delta * 50 # y -= delta * 50
elif Input.is_action_pressed("ui_right"): #elif Input.is_action_pressed("ui_down"):
# Move as long as the key/button is pressed. # Move as long as the key/button is pressed.
x += delta * 50 # y += delta * 50
else: #else:
velocity.x *= 0.8 # velocity.y *= 0.8
if Input.is_action_pressed("ui_up"): while velocity.length() > 100:
# Move as long as the key/button is pressed. velocity.x *= 0.99
y -= delta * 50 velocity.y *= 0.99
elif Input.is_action_pressed("ui_down"): velocity.x *= 0.99
# Move as long as the key/button is pressed. velocity.y *= 0.99
y += delta * 50 #velocity.x += x
else: #velocity.y += y
velocity.y *= 0.8
velocity.x += x
velocity.y += y
if !hitanim.is_emitting(): if !hitanim.is_emitting():
anim.modulate.a = 1 anim.modulate.a = 1
@ -90,11 +93,27 @@ func _process(delta):
move_and_slide() move_and_slide()
func processAI(objs, delta): func processAI(objs):
var vec: Vector2 = Vector2(0,0) var vec: Vector2 = Vector2(0,0)
var weight: int = 0
for obj in objs: for obj in objs:
vec += obj.vecpos * obj.weight * (1 / (position - obj.vecpos)) * delta if !obj || !obj.isAlive:
return vec.normalized() continue
if position.distance_to(obj.position) > 10:
weight = abs(obj.priority) * position.distance_to(obj.position)
vec += weight * position.direction_to(obj.position)
else:
weight = obj.priority * position.distance_to(obj.position) * ((maxhp + 1) / hp)
vec += weight * -position.direction_to(obj.position)
if vec.length() < 5 && objs.size() > 1:
vec.y *= 3
if velocity.length() < 95 && objs.size() > 1:
vec.y += 10
vec.x -= vec.x * .2
return vec.normalized() * 100
func attack(): func attack():