Godot Version
4.7.1.stable
Question
I know I should be figuring this stuff out myself, but this is a minor hill that I can’t find a solution to unlike the previous rest of the project.
When an enemy dies, they all die, from what’s below, would may be my issue andf how could I fix it? Should I take an entirely unique path?
Ignore anything commented out. Order of code is box 1 Enemy, box 2 RoomCode, 3 Player
If you share code, please wrap it inside three backticks or replace the code in the next block:
extends CharacterBody2D
signal outputRecieveDMG
signal DMGRomeo(value)
var HP = 10
var DMG = 5
var SPD = 40.0
var LUCK = 0
var player_pos
var target_pos
#@onready var player = get_parent().get_node("RomeoBody")
func _on_romeo_body_self_locate(value: Variant) -> void:
player_pos = value
target_pos = (player_pos - position).normalized()
if position.distance_to(player_pos) > 1:
velocity = target_pos * SPD
move_and_slide()
func _physics_process(_delta):
#player_pos = RomeoLocation.global_position
if HP < 1:
SPD = 0
$AnimatedSprite2D.play("Death")
queue_free()
func _on_atkzone_body_entered(_body: Node2D) -> void:
$Swing.visible = true
get_node("Swing/AnimatedSprite2D").play("Swing")
func _on_atkzone_body_exited(_body: Node2D) -> void:
$Swing.visible = false
func _on_swing_body_entered(body: Node2D) -> void:
if body.is_in_group("Romeo"):
emit_signal("DMGRomeo",DMG)
func _on_romeo_body_resend_dmg_output(value: Variant) -> void:
HP -= value
$AnimatedSprite2D.play("Hurt")
func take_damage1():
emit_signal("outputRecieveDMG")
# character_direction.x = Input.get_axis("Move_Left", "Move_Right")
# character_direction.y = Input.get_axis( "Move_Down", "Move_Up")
#
# if character_direction.x > 0: %AnimatedSprite2D.flip_h = false
# elif character_direction.x < 0: %AnimatedSprite2D.flip_h = true
#
# if character_direction:
# velocity = character_direction * SPD
# else:
# velocity = velocity.move_toward(Vector2.ZERO, SPD)
# move_and_slide()
#func input(event):
# if event.is_action_pressed("Move_Right"):
# %AnimatedSprite2D.play("Left_Right")
# if event.is_action_pressed("Move_Left"):
# %AnimatedSprite2D.play("Left_Right")
# if event.is_action_pressed("Move_Down"):
# %AnimatedSprite2D.play("Move_Up")
# if event.is_action_pressed("Move_Up"):
# %AnimatedSprite2D.play("Move_Down")
#
# if event.is_action_released("Move_Down"):
# %AnimatedSprite2D.play("Idle")
# if event.is_action_released("Move_Up"):
# %AnimatedSprite2D.play("Idle")
# if event.is_action_released("Move_Left"):
# %AnimatedSprite2D.play("Idle")
# if event.is_action_released("Move_Right"):
# %AnimatedSprite2D.play("Idle")
func _on_animated_sprite_2d_animation_finished() -> void:
$AnimatedSprite2D.play("Normal")
extends Node2D
@export var enemy_new: PackedScene = preload("res://Scenes/HappyEnemy.tscn")
func _ready() -> void:
var spawn_point = %Spawnpoint1
$Essentials/SpawnTimer.start()
$Essentials/SpawnTimer/SpawnRate.start()
func spawn_enemy():
var enemy_temp = enemy_new.instantiate()
add_child(enemy_temp)
enemy_temp.position = $Essentials/Spawnpoint1.global_position
var romeo = $Essentials/RomeoBody
romeo.selfLocate.connect(enemy_temp._on_romeo_body_self_locate)
romeo.resendDMGOutput.connect(enemy_temp._on_romeo_body_resend_dmg_output)
enemy_temp.DMGRomeo.connect(romeo._on_happy_enemy_dmg_romeo)
enemy_temp.outputRecieveDMG.connect(romeo._on_happy_enemy_output_recieve_dmg)
func _on_spawn_timer_timeout() -> void:
print("TIEM")
$Essentials/SpawnTimer.stop()
$Essentials/SpawnTimer/SpawnRate.stop()
func _on_spawn_rate_timeout() -> void:
spawn_enemy()
$Essentials/SpawnTimer/SpawnRate.wait_time = randi_range(0,3)
extends CharacterBody2D
signal selfLocate(value)
signal updateHP(value)
signal resendDMGOutput(value)
var SANITY = 30
var HP = 30
var WRATH = DMG
var DMG = 5
var rangedDMG = DMG
var GREED = LUCK
var LUCK = 0
var SLOTH = SPD
@export var SPD : float = 100
var PRIDE = ARMR
var ARMR = 0
var GLUTTONY = MLTP
var MLTP = 0.0
var LUST = CD
var CD = 0.0
@onready var animated_sprite = $RomeoSprite
func _physics_process(_delta):
var character_direction = Input.get_vector("Move_Left","Move_Right","Move_Down","Move_Up")
velocity = character_direction * SPD
move_and_slide()
emit_signal("selfLocate",position)
if HP < 1:
get_tree().reload_current_scene()
func _on_heart_body_entered(body: Node2D) -> void:
if body.is_in_group("Romeo"):
emit_signal("dmgEnemy",rangedDMG)
print("hhhhhh")
func _on_heart_holder_play_shooting() -> void:
$RomeoSprite.play("Shooting")
func _on_heart_holder_play_shot() -> void:
$RomeoSprite.play("Shot")
func _on_romeo_sprite_animation_finished() -> void:
$RomeoSprite.play("Idle")
func _on_happy_enemy_output_recieve_dmg() -> void:
emit_signal("resendDMGOutput",DMG)
func _on_happy_enemy_dmg_romeo(value: Variant) -> void:
$RomeoSprite.play("Injured")
HP -= value
emit_signal("updateHP",value)
