GML Damage system

Discussion in 'Programming' started by Mikael.K, Sep 19, 2018.

Tags:
  1. Mikael.K

    Mikael.K Member

    Joined:
    Jun 22, 2016
    Posts:
    23
    Hey.

    I'm coding a damage system. I want to have the object that does the damage to store the IDs of its "victims", and then check if it already dealt damage to the victim or not. This is so that the object only does damage to the same object once, but can still damage other objects until it is destroyed.

    Like a bullet that travels through many objects and stores the ID of the objects it impacts along it's path.

    I'm thinking something like this.

    Step Event.
    1. Check to see how many objects it's colliding with.
    2. Check to see if it has done damage to those objects already - if not, do damage to the objects not on the "victim list"
    3. Store the IDs of the objects it has done damage to on the "victim list"

    Is this good logic? How can i code this?
     
  2. Mikael.K

    Mikael.K Member

    Joined:
    Jun 22, 2016
    Posts:
    23
  3. CloseRange

    CloseRange Member

    Joined:
    Jul 2, 2016
    Posts:
    730
    create event
    Code:
    hit[0] = false;
    with(obj_enemy) {
        other.hit[id] = false;
    }
    step event
    Code:
    with(obj_enemy) {
        if(other.hit[id]) continue;
        if(place_meeting(x, y, other) {
            // do damage
            other.hit[id] = true;
        }
    }
    I just wrote this real quick so might have an error.
    this is how I usually do this sort of damage system. Make an array of enemys and set them to false. every fame loop through the enemys; check if it's already been hit and if so skip it; if not then check if it's colliding and do the damage.

    If you have differant enemy objects like obj_enemyA and obj_enemyB ect then make a obj_enemy_parent and make all enemys parent it. Then you can just call that object instead.
     
  4. Fabseven

    Fabseven Member

    Joined:
    Oct 7, 2016
    Posts:
    347

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice