0 Favourites

How do I "damage" enemy sprite from a family

  • Let's say there are 2 or 3 kind of baddies: enemy1, enemy2, etc all of them inside a family called Enemies, and each enemy have his own health different from each other as instance variable, then there is a bullet or fireball or something that hits the enemy and deals X dmg

    How do I substract the bullet damage from the enemy health? Do I need to do it manually? I mean bullet on collision with sprite (and do it for each enemy I design) instead of doing it by comparing the UID of the family, or something like that:

    Pick enemies.UID --- substract bullet.damage from picked enemy.health

    As you can see, I'm not very familiar with UIDs and I cant find something that fits to the case (maybe it does not exists)

    Thanks and exuse if i'm asking for something really dumb

  • You don't need to compare

    Fireball - On collision with Family1 --> Family1 - Subtract 1 from health[/code:3159vzc6]
    
    This will only effect the hitted ones. Others in the family wont be affected
  • The problem is that every object inside the family has his own health(enemy1.health=50, enemy2.health=100, and so on), so I cant just substract from the family

  • give the family the required instance variable not the objects inside.

    as it sounds like you have given the variables to the objects rather than to the family have a look at

    https://www.scirra.com/tutorials/535/ho ... o-a-family

  • I dont know if im misunderstanding something but... the actual problem is that every enemy inside the family has a different number for health, so i cant refer to the family instance variable since, if i had one, it would be the same for every object inside the group

    If I create a family instance variable, for example enemies.health, this aplies to all instances, enemy.health, enemy2.health, etc So if i want to substract 10 from the enemy health i want this enemy to have enemy.health=50, and enemy2 to have 100 health, for example

    I dont know if I'm correctly explaining my problem

  • There is a RTS example coming with the software that might help you with this? In that one each object in the family has it's own instance variables with hp.

  • Thats not what I mean, I need to have a different predefined MaxHealth on each type of enemy

    Enemy1.maxhealth=50

    Enemy2.maxhealth=100

    and so on

    So when a bullet hits on the family enemies it substract X from the health from the on-collision-with sprite

    The point is just to have 1 condition that affects all enemies but each one with different max health

    I know every enemy has his own health if I make a family instance variable, but the same max health too, I want different max health for each enemy

    I hope its clear now ^^'

    PD: sorry, my fault, I should have mentioned its maxhealth instead of health

  • Construct 3

    Buy Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Buy Now Construct 3 users don't see these ads
  • say you have 5 sprites called red,blue,green,orange and yellow

    you add all 5 to a family "boxes"

    then to the family you add instance variables maxhealth and health

    now each of the sprites have now also got instance variables maxhealth and health

    so at start of layer you can say

    red.maxhealth=100

    blue.maxhealth=1000

    green.maxhealth=500

    etc

    but you can then say

    when members of boxes hit

    boxes.maxhealth =boxes.maxhealth-damage

    so if the area of damage hist a red, and green sprite then their and only their health will drop

  • here you go - a quick example...

    https://db.tt/E7yuO7s6 (r212.2)

  • ok, thats not what I really wanted but this is much easier than manually create an instance variable for each enemy

    If linking a sprite instance variable from a family to his family instance variable could be done, it would be awesome (for sure there is a plugin out there)

    Thanks a lot for your replies! Made my day RamPackWobble! I can conclude this as solved

  • just to stress the point you can still access the instance variable created for the family from the sprite. so from above you can still access red.maxhealth. so sprite.health is linked to family.health...

  • Yes I know, im just saying that it could be easy if you create a family.maxhealth variable but then apply a diff number for each sprite as you want (sprite1.maxhealth=10, sprite2.maxhealt=20, etc), so when you create the new sprite it is created with his own number, with no need to create a new event to change this number

    I dont know if im explaining myself correctly as my english is still bad ^^'

  • if you edit the capx to the above - when run all spOrange will be created with ivHealth = 150 (which is the family (famThings) instance variable). spBlue will be created with ivhealth of 50 and spGreen with ivHealth of 100 - these figures were set by selecting (in the projects list)each of the spOrange, spBlue and spGreen in turn and the setting (in the properties list) the ivHealth value I wanted for each sprite . You can overrule these set values in the code but do not need to.

  • OOOOOOOOHHH! wow, now I see! that's exactly what I wanted! I feel so dumb right now, thank you very much for your patience!

  • Hey there,

    This is exactly what i was looking for. It's just a pitty that the images and the capx in this thread are deleted. Is there a chance to get those examples again?

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)