From 30566dc395cd2870343a6b6295ed9ba42437ef62 Mon Sep 17 00:00:00 2001 From: MarcEricMartel Date: Tue, 10 Oct 2023 13:34:26 -0400 Subject: [PATCH] Love thy enemy --- Scenes/enemy.tscn | 4 +++- Scripts/Enemy.gd | 17 +++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/Scenes/enemy.tscn b/Scenes/enemy.tscn index 723c347..feb4a54 100644 --- a/Scenes/enemy.tscn +++ b/Scenes/enemy.tscn @@ -380,7 +380,7 @@ script = ExtResource("1_xj62t") sprite_frames = SubResource("SpriteFrames_dqf8u") animation = &"Idle" autoplay = "Idle" -frame_progress = 0.93659 +frame_progress = 0.487368 flip_h = true [node name="Atk_cooldown" type="Timer" parent="."] @@ -406,6 +406,8 @@ scale_amount_min = 0.01 scale_amount_max = 0.01 color = Color(1, 1, 1, 0.423529) +[node name="LvlUpSnd" type="AudioStreamPlayer2D" parent="."] + [node name="CharacterCollision" type="CollisionShape2D" parent="."] shape = SubResource("CapsuleShape2D_p2hkm") diff --git a/Scripts/Enemy.gd b/Scripts/Enemy.gd index 637d137..d1478c5 100644 --- a/Scripts/Enemy.gd +++ b/Scripts/Enemy.gd @@ -9,12 +9,14 @@ extends CharacterBody2D @export var level: int = 1 @export var hp: int = 100 @export var maxhp: int = 100 +@export var maxvel: float = 2 @export var experience: int = 0 @export var state: String = "Idle" @onready var anim: Node = get_node("Sprite") @onready var cooldown: Node = get_node("Atk_cooldown") @onready var lvlanim: Node = get_node("LvlUp") +@onready var lvlsnd: Node = get_node("LvlUpSnd") # Called when the node enters the scene tree for the first time. func _ready(): @@ -31,12 +33,25 @@ func _process(delta): is_facing_left = velocity.x >= 0 # AI STUFF + #velocity = processAI(objects,velocity,delta) + velocity.x += delta velocity.y += delta + if abs(velocity.x + velocity.y) > maxvel: + velocity.x *= maxvel / velocity.x + velocity.y *= maxvel / velocity.y + position += velocity +func processAI(objs, delta): + var vec: Vector2 = Vector2(0,0) + for obj in objs: + vec += obj.vecpos * obj.weight * (1 / (position - obj.vecpos)) * delta + return vec.normalized() + + func attack(): is_attacking = true if (level > 1): @@ -86,6 +101,7 @@ func receive_exp(x): func setLevel(lvl): level = lvl lvlanim.restart() + lvlsnd.play() if level > 2: cooldown.wait_time = 0.5 @@ -99,3 +115,4 @@ func _on_sprite_animation_looped(): if is_attacking: stop_attack() is_dying = false +