This question is about a battle card game.
There are currently three enemy cards on screen, each with its own health and health bar, as well as five player cards.
All players are instantiated from the same scene (player_card) and all enemies are instantiated from the same scene (enemy_card). Player_card and enemy_card are different scenes.
In each turn, the player picks one of its cards and attacks one of the enemy cards. The player attack is handled properly. The code detects the player card that attacks, computes damage and deals damage to the chosen target enemy. So far, so good.
Then I try to update the enemy’s health bar by passing a signal to the enemy_card code. It works, except that, instead of updating the size of the health bar of the enemy that took the damage, all enemies’ health bars are updated simultaneously.
This is my code:
In GlobalSignals.gd (singleton)
signal update_enemy_healthbar
In Player_card.gd
(...)
enemy_health_left #this is computed from attack power - defense power*
#now compute the new size of the health bar, also correct
GlobalVars.enemy_health_bar_size.x = (enemy_health_left*GlobalVars.enemy_health_bar_size.x)/GlobalVars.enemy_active[6]
GlobalSignals.emit_signal ("update_enemy_healthbar")
In Enemy_card.gd
func _ready():
GlobalSignals.connect("update_enemy_healthbar", update_enemy_healthbar_function)
func update_enemy_healthbar_function():
$EnemyImage/EnemyHealthBar.set_size(GlobalVars.enemy_health_bar_size,$EnemyImage/EnemyHealthBar.size.y)
I believe the issue is with the very last function, which updates the health bar size of all instances of the enemy scene.
How would I go about updating only the health bar of the enemy that was attacked?
Thanks!