From 98e9404435e032263f380ca0165d760877157744 Mon Sep 17 00:00:00 2001 From: MarcEricMartel Date: Tue, 10 Oct 2023 19:27:17 -0400 Subject: [PATCH] "eh bo derek" --- Scenes/Levels/level_test.tscn | 2 +- Scenes/Spawnables/template_spawnable.gd | 1 + Scripts/Enemy.gd | 71 +++++++++++++++---------- 3 files changed, 46 insertions(+), 28 deletions(-) diff --git a/Scenes/Levels/level_test.tscn b/Scenes/Levels/level_test.tscn index 33abc78..fd3399e 100644 --- a/Scenes/Levels/level_test.tscn +++ b/Scenes/Levels/level_test.tscn @@ -14,7 +14,7 @@ position = Vector2(441, 312) [node name="BatSpawnable" parent="." instance=ExtResource("3_a1ucf")] -position = Vector2(248, 225) +position = Vector2(62, 122) [node name="BatSpawnable2" parent="." instance=ExtResource("3_a1ucf")] position = Vector2(644, 251) diff --git a/Scenes/Spawnables/template_spawnable.gd b/Scenes/Spawnables/template_spawnable.gd index 702b9c4..dc29d01 100644 --- a/Scenes/Spawnables/template_spawnable.gd +++ b/Scenes/Spawnables/template_spawnable.gd @@ -90,6 +90,7 @@ func die(): animatedSprite.play("death") animatedSprite.disconnect("animation_finished", endAttack) animatedSprite.connect("animation_finished", fadeOut) + enemy.remove_foe(self) func fadeOut(): var tween = get_tree().create_tween() diff --git a/Scripts/Enemy.gd b/Scripts/Enemy.gd index 5e551fa..bdaec5d 100644 --- a/Scripts/Enemy.gd +++ b/Scripts/Enemy.gd @@ -44,11 +44,13 @@ func _ready(): atk1r.set_disabled(true) atk2l.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. 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") elif !is_attacking: setAnimState("Run") @@ -57,32 +59,33 @@ func _process(delta): is_facing_left = velocity.x > 0 && !(velocity.x < 0) # AI STUFF - #velocity += processAI(list,delta) - var x = 0 - var y = 0 + velocity += processAI(list) * delta + #var x = 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. - x -= delta * 50 - elif Input.is_action_pressed("ui_right"): + # y -= delta * 50 + #elif Input.is_action_pressed("ui_down"): # 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. - y -= delta * 50 - elif Input.is_action_pressed("ui_down"): - # Move as long as the key/button is pressed. - y += delta * 50 - else: - velocity.y *= 0.8 - - velocity.x += x - velocity.y += y - - - + # y += delta * 50 + #else: + # velocity.y *= 0.8 + while velocity.length() > 100: + velocity.x *= 0.99 + velocity.y *= 0.99 + velocity.x *= 0.99 + velocity.y *= 0.99 + #velocity.x += x + #velocity.y += y if !hitanim.is_emitting(): anim.modulate.a = 1 @@ -90,11 +93,25 @@ func _process(delta): move_and_slide() -func processAI(objs, delta): +func processAI(objs): var vec: Vector2 = Vector2(0,0) + var weight: int = 0 for obj in objs: - vec += obj.vecpos * obj.weight * (1 / (position - obj.vecpos)) * delta - return vec.normalized() + 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 / hp) * 100 + 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():