How do I apply a list of values to enemies damage?

  • I have spent quite a bit of time looking into doing this one but could not find the most efficient solution of doing it.

    I am trying to have a list of variables each with with the enemy name and damage type associated, so this I can easily do.

    Example:

    e_grunt1

    value 10

    e_grunt2

    value 15

    e_grunt3

    value 20

    What I struggle with however is probably the simplest part of all; How do I call each value when I need it?

    So the way I have it set up right now is that when a collision with a single generic sprite for damage collides with the player, I use a variable called "getdamage" to ask the damage value.

    So it goes something like this:

    getdamage:

    if player overlaps with collision sprite1 subtract e_grunt1 to player health

    The problem with this is that it means that I Will have to do a unique collision sprite for each individual enemy (so creating a sprite1, sprite2 and sprite3, just for collisions), surely there must be a more efficient way?

  • This is what Families are for, you group all enemy objects into an enemy family, replace the damage variable with a family instance variable for damage and say on overlapping family do family.damage.

  • Would you be so kind as to elaborate on that, I Am not sure I follow :)

  • Read up on Families in the manual. It describes an example with enemies.

  • It helps but the problem remains.

    1. I will have to create a family for each damage value, so if a mosnter does 10 damage, he cannot be in the family where they do 20 damage (as far as I can the family does not allow me to assign a variable for each sprite, unless I assign it to each sprite within the family and they inherit it anyways).

    2. I still do not know how to call specific damages as I quoted from my example above I will do so again, perhaps I as not clear.

    What I have so far are 4 states:

    If you are facing right and are hit in the front, or back.

    If you are facing left and are hit in the front or back.

    Everytime there is a collision with... "family" (and checking the x coordinateds to see if they are coming from the back or the front), go get the damage (varaible "getdamage").

    getdamage subtract ....????? from health.

    ?????= What do I put here? How do I tell it "from the family you have just collided with" or "check the family you have collided with, then go get this global/local variable"?

  • I am going to explain how to do it in the sense that an enemy is attacking the player.

    You put all enemy objects, enemyA enemyB enemyC into a family 'enemies'.

    You add a family instance variable to enemies - 'damage'.

    You add other logic, set enemyA.damage to 10, set enemyB.damage to 20, set enemyC.damage to 30 on created.

    Then you have attack logic, enemies(family) on collision with player, subtract enemies.damage from player.

  • Not sure if I understand it 100% but I will try it, thanks.

    Also another problem I have with the family is that, when I check to see if the player x is greater or less than the x of "enemies" to see from which direction he is getting hit, no matter how many enemies there are, it always consider the x of the first enemy I have placed in the layout, not sure how to fix t his one.

  • A file would help...

    But speaking in general, even if an enemy is in a family you can still check types of enemies or specific instances individualy.

    Without seeing a file to understand the specific problem you're having is very difficult to give you advice on that. Sorry.

    Cheers!

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Well the first problem is pretty simple to explain:

    I do a player x value check and if it is greater than the x value of the enemy (in this case of the whole family), so if the character is hit from the left, he flies to the right, if he is hit to the right, he flies to the left (this also depend on which direction he is facing).

    This works, but when there are multiple instances from the same family, construct only takes reference of the x value of the enemy I first put down in the layout (rather than the closest one), so if enemy 2 is like 500 pixels +X (right) of enemy 1, the collision still thinks you get hit from the right, no matter where enemy 2 is, even if he is to the left of the player (-x).

    The second problem is that I literally have no clue how can I call with events a variable based on which enemy from that family has hit you without having to write a massive list:

    getdamage=

    if enemy_1 collides with player, get variable enemydamage_1

    if enemy_2 collides with player, get variable enemydamage_2

    if enemy_3 collides with player, get variable enemydamage_3

    if enemy_4 collides with player, get variable enemydamage_4

    if enemy_5 collides with player, get variable enemydamage_5

    because they might all have different values.

  • You add a 'for each instance' to resolve that.

  • Sorry resolve which problem, the damage coordinates or the list to call who gets hit?

  • if you add a for each instance it picks all instances, that should resolve multiple instances coming at you from either side. the enemy damage being combined into one event I resolved above with families.

  • Maybe this image will help, please forgive the convlutedness of it, but it was necessary to make the 4 directional hits thing.

    I have gone through it at the bottom and explained it on case you are not sure why certain things are the way they are.

    p_hurt = "not" //need to do this so the player only collides once

    p_invulnerable=0 //I have done this so the player cannot get hit for about 2 seconds after he lands.

    p_health > 0 //so this will only trigger when the player health is above 0

    player is overlapping Damage //damage is the name of the enemy family for now

    player x > Damage.X //this is so where on the coordinates the player is

    p_facing = left //so we know to do this only when the character faces left

    trigger once

    p_ishurt to "subtract" //this goes elsewhere to call the value of health to subtract

    p_washit to f_left" //this records which of the 4 possible ways the player gets hit, so when subtracts has removed health, it turns into "where", this is important because the animation playing could be the death of the character instead of the one being hurt, it needs to know before it plays it.

    p_ishurt = "where"//after subtracting health it now comes back here to do the next thing

    p_facing = "left" //even if redundant I had to place it here because it was causing some bugs otherwise

    p_health >o = // this needs to know you are not dead yet so it plays this animation.

    p_washit = "f_left" //this is to confirm the hit location

    p_ishurt to "f_left" //this is used to confirm and trigger the right animation and event

    p_ishurt = "f_left" //this event starts now because of what is aboove

    trigger once

    vector y // makes it move from damage

    vector x // same as above

    p_crouch to not" //this makes sure than any other animation is cancelled if you are hit

    p_punch to not //same as above

    p_kick to not //same as above

    protagonist //sets the hurt animation for this specific orientation and location

    The following is the same as before, but we are checking to see if the character is dead instead.

    So first of all, how to I fix the direction hit issue so that the x is of the instance of the enemy, not of the first one being called for.

  • Argh my eyes

  • Uhh... thanks?

    So can anyone help me with the x to x issue?

    I think is best deal with 1 problem at the time.

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