GML Minimap to show enemies

Discussion in 'Programming' started by Just a game programmer, May 19, 2018.

  1. Just a game programmer

    Just a game programmer Member

    Joined:
    Apr 10, 2017
    Posts:
    25
    I am creating a minimap for the game I am working on.
    I have set up a minimap square 1 tenth of the size of the room. I have a smaller version of the player moving at the player's position/10.
    That works fine but since I have multiple enemies this doesn't work for the enemies. Any ideas? Thanks!
     
  2. Simon Gust

    Simon Gust Member

    Joined:
    Nov 15, 2016
    Posts:
    3,174
    It does work if you use a with statement instead of enemy.x/10 and enemy.y/10
    Code:
    with (obj_enemy)
    {
        draw_sprite(sprite_index, image_index, x/10, y/10);
    }
    
    If you have multiple of an instance, don't refrence the object name as it will automatically take the latest enemy created while the other ones are ignored.
     
  3. Roman P.

    Roman P. Member

    Joined:
    Mar 1, 2017
    Posts:
    214
    have the draw code in your enemy objects
     
  4. Just a game programmer

    Just a game programmer Member

    Joined:
    Apr 10, 2017
    Posts:
    25
    Thanks!
     
  5. Just a game programmer

    Just a game programmer Member

    Joined:
    Apr 10, 2017
    Posts:
    25
    Thanks!
    I don't have the chance to try it out yet, but will that code show the location of all enemies in the room or only the latest one created?
     
  6. Each enemy that is running the code will show on the minimap. Neat little trick, I wouldn't have thought of it.
     
  7. flerpyderp

    flerpyderp Member

    Joined:
    Apr 26, 2018
    Posts:
    205
    The enemies are not running that code, it is run from another object, and the "with" statement simply references all instances of the enemy object that currently exist in the room.
     
  8. Right. I probably should have used a better wording.
     

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