Need help identifying enemy id for stat drawing

S

Stranger

Guest
Hello everyone. So I'm having difficulty drawing the enemy stats(more specifically the enemy picture and health bar). It is a turn-based system and I'd like to have up to eight enemies per battle. So I plotted out where each enemy picture and health bar will go. Now what I'm having difficulty with is determining which enemy will display their stats at which HUD location. I tried a few different ways but can't seem to find a way to distinguish one enemy from the other(maybe with a variable). In the end, the game will populate the battle room with enemies based on the encounter that led up to combat. But right now the enemy is just one object which has been placed on the map four times(four separate instances). I just need a way to determine who is enemy_one, enemy_two etc so I can draw their stats at enemy_slot_one, enemy_slot_two etc. Here is a screenshot to help visualize the situation. The giant robots on the map are the enemies I'd like to identify and draw their stats below. Any help is much appreciated. Let me know if you need any code posted.
upload_2019-10-20_12-24-1.png
 
Heres an example that sets a unique index for each object and then draws it. This code should be on the control object.
Code:
global.index = 0;
with(obj_badguy)
{
  //you could put a if statement here to check if object is active or in the room.
  index = global.index;
  global.index += 1;
}
with(obj_badguy)
{
  draw_text(x,y,string(index))
}
 

Simon Gust

Member
I would do it fully automatic.
Example
Code:
var x0 = [30, 80, 130, 180, 15, 65, 115, 165];
var y0 = [30, 30,  30,  30, 80, 80,  80,  80];
var counter = 0;

with (obj_enemy)
{
    // get drawing position
    var xx = x0[counter];
    var yy = y0[counter];
  
    // draw enemy icon
    draw_sprite(sprite_index, 0, xx, yy);
  
    // draw enemy stats
    draw_text(xx + 20, yy + 10, name);
    draw_text(xx     , yy + 15, string(hp) + "/" + string(max_hp));
    draw_text(xx     , yy + 20, string(ap) + "/" + string(max_ap));
    // and so on...

    counter++;
}
and if you can select enemies you can visualize it by adding little code inside the with() loop like drawin a colored rectangle signaling the selected enemy.
 
S

Stranger

Guest
I would do it fully automatic.
Example
Code:
var x0 = [30, 80, 130, 180, 15, 65, 115, 165];
var y0 = [30, 30,  30,  30, 80, 80,  80,  80];
var counter = 0;

with (obj_enemy)
{
    // get drawing position
    var xx = x0[counter];
    var yy = y0[counter];
 
    // draw enemy icon
    draw_sprite(sprite_index, 0, xx, yy);
 
    // draw enemy stats
    draw_text(xx + 20, yy + 10, name);
    draw_text(xx     , yy + 15, string(hp) + "/" + string(max_hp));
    draw_text(xx     , yy + 20, string(ap) + "/" + string(max_ap));
    // and so on...

    counter++;
}
and if you can select enemies you can visualize it by adding little code inside the with() loop like drawin a colored rectangle signaling the selected enemy.
Dang this is working well so far. Exactly what I was trying to do. Fully automatic is much desired in this situation. Thank you a ton for your help!
 

Yal

šŸ§ *penguin noises*
GMC Elder
Only potential caveat you could see with the with approach is that the order you iterate through objects isn't well defined, so adding or deleting objects could potentially scramble the list entirely instead of adding/removing at the end... no one really knows. But I imagine this wouldn't be a super big issue in a turn-based game where things might not change more than once every minute or so. But if it becomes a problem and you want a well defined order, it's good to be aware of this (and the natural solution would be to add things to a priority queue to get a well defined order - this also lets you list the player and bosses first, by giving them a higher priority)
 
S

Stranger

Guest
Thanks for the info Yal. I'll keep an eye on it as the system progresses more and I'll definitely circle back to this when/if it happens. I'm sure it'll get completely reworked once I automate the battle setup anyway. In the meantime, here is a screenshot showing the results thanks to the help of all you! It even highlights the enemy stats when it is selected on the map!upload_2019-10-20_23-0-50.png
 
Top