From 4887f593f6610163b527d433347f36e0c5fa6922 Mon Sep 17 00:00:00 2001 From: MarcEricMartel Date: Wed, 11 Oct 2023 09:36:16 -0400 Subject: [PATCH] ol --- Scenes/Levels/level_1.tscn | 2 +- Scenes/Spawnables/template_spawnable.gd | 9 ++++--- Scripts/Enemy.gd | 34 +++++++++++++++++-------- 3 files changed, 31 insertions(+), 14 deletions(-) diff --git a/Scenes/Levels/level_1.tscn b/Scenes/Levels/level_1.tscn index 2b751f4..b288a14 100644 --- a/Scenes/Levels/level_1.tscn +++ b/Scenes/Levels/level_1.tscn @@ -2,7 +2,7 @@ [ext_resource type="Script" path="res://Scripts/level.gd" id="1_0nmok"] [ext_resource type="PackedScene" uid="uid://b8s2seg2lf7wo" path="res://Scenes/Tilemaps/tileset_1.tscn" id="1_4n82n"] -[ext_resource type="PackedScene" uid="uid://dgtscjxcqoxls" path="res://Scenes/Props/candle_1.tscn" id="2_5hdq4"] +[ext_resource type="PackedScene" uid="uid://cl7w6ndvons1a" path="res://Scenes/Props/candle_1.tscn" id="2_5hdq4"] [ext_resource type="PackedScene" uid="uid://cf7al5uln33rn" path="res://Scenes/Props/candle_2.tscn" id="2_o33c4"] [ext_resource type="PackedScene" uid="uid://b5lnjonlf4i1b" path="res://Scenes/enemy.tscn" id="4_g0oey"] [ext_resource type="PackedScene" uid="uid://0onqgygm832d" path="res://Scenes/Player/player.tscn" id="5_ik47y"] diff --git a/Scenes/Spawnables/template_spawnable.gd b/Scenes/Spawnables/template_spawnable.gd index 8ee95e2..407b280 100644 --- a/Scenes/Spawnables/template_spawnable.gd +++ b/Scenes/Spawnables/template_spawnable.gd @@ -93,7 +93,8 @@ func endAttack(): animatedSprite.play("default") func receive_damage(dmg): - hitSnd[rng.randi_range(0,4)].play(); + if hitSnd: + hitSnd[rng.randi_range(0,4)].play(); if !isAlive: return if currentHp - dmg <= 0: @@ -104,7 +105,8 @@ func receive_damage(dmg): spawnableUI.setHP(currentHp, maxHp) func die(): - dieSnd[rng.randi_range(0,4)].play(); + if dieSnd: + dieSnd[rng.randi_range(0,4)].play(); enemy.remove_foe(self) signal_death.emit(self) bodyCollision.disabled = true @@ -133,5 +135,6 @@ func _on_damage_area_body_entered(body): func _on_tree_entered(): - spawnSnd[rng.randi_range(0,4)].play(); + if spawnSnd: + spawnSnd[rng.randi_range(0,4)].play(); diff --git a/Scripts/Enemy.gd b/Scripts/Enemy.gd index 5d96b42..3ba6567 100644 --- a/Scripts/Enemy.gd +++ b/Scripts/Enemy.gd @@ -15,7 +15,7 @@ extends CharacterBody2D @export var state: String = "Idle" @export var damage: int = 5 @export var maxAtks: int = 1 -@export var maxcooldown: float = 0.5 +@export var maxcooldown: float = 0.75 @onready var currentcooldown: float = 0 @onready var killcount: int = 0 @@ -102,30 +102,44 @@ func _process(delta): func processAI(objs): var vec: Vector2 = Vector2(0,0) + var skel = false var weight: int = 0 if hp <= 0: return vec for obj in objs: if !obj || !obj.isAlive: continue - if position.distance_to(obj.position) > 50: - 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) + if position.distance_to(obj.position) < 25: + if obj.priority == 10: + vec += position.direction_to(obj.position) * 30 + if currentcooldown <= 0: + attack() + currentcooldown = maxcooldown + weight = obj.priority * position.distance_to(obj.position) * ((maxhp + 1) / hp) * 1.25 vec = weight * -position.direction_to(obj.position) if currentcooldown <= 0: attack() currentcooldown = maxcooldown + else: + if obj.priority == 10: + skel = true + vec = position.direction_to(obj.position) * 10 + if currentcooldown <= 0: + attack() + currentcooldown = maxcooldown + break + weight = abs(obj.priority) * position.distance_to(obj.position) + vec += weight * position.direction_to(obj.position) + - if vec.length() < 5 && objs.size() > 1: + if vec.length() < 5 && objs.size() > 1 && !skel: vec.y *= 3 - if velocity.length() < 95 && objs.size() > 1: + if velocity.length() < 95 && objs.size() > 1 && !skel: vec.y += 10 vec.x += 5 - return vec.normalized() * 100 + return vec.normalized() * 1000 func attack(): @@ -192,7 +206,7 @@ func setLevel(lvl): maxAtks = 2 maxhp += 5 - hp += 10 + hp += 5 * level + 5 if hp > maxhp: hp = maxhp