This commit is contained in:
MarcEricMartel 2023-10-11 09:36:16 -04:00
parent bf6483bf7b
commit 4887f593f6
3 changed files with 31 additions and 14 deletions

View File

@ -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"]

View File

@ -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();

View File

@ -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