1. Hey! Guest! The 32nd GMC Jam will take place between Feb 22nd, 12:00 UTC (Friday noon) and Feb 25th, 12:00 UTC (Monday noon). Why not join in! Click here to find out more!
    Dismiss Notice

Question - Code Different bullets same gun?

Discussion in 'GameMaker Studio 2 Community Tech Support' started by PabloDiez, Feb 11, 2019 at 12:59 PM.

  1. PabloDiez

    PabloDiez Member

    Joined:
    Monday
    Posts:
    3
    Hello! I'm just a begginer and I apologise in advance if im asking something someone else has tackled before.
    I'm trying to develop my first game but i've encountered a problem regarding my weapons. Thing is I'd like my player's gun to shoot different projectiles switching its bullets from one shot to another. This is because his gun is a bag of candy and and the bullets are the different coulored candies inside it.
    Does anyone know how i could do this code-wise? Thanks a lot in advance
     
  2. Lady Glitch

    Lady Glitch Member

    Joined:
    Sunday
    Posts:
    15
    Your different colored candies are all sub-images of the same sprite, right?
    If so, you can choose a random sub-image for your bullet each time you create one.
    Code:
    image_index = irandom(sprite_get_number(sprite_index));
    image_speed = 0;
    You can also choose a random sprite
    Code:
    sprite_index = choose(spr_candy0, spr_candy1, spr_candy2, spr_candy3);
     
    PabloDiez likes this.
  3. PabloDiez

    PabloDiez Member

    Joined:
    Monday
    Posts:
    3
    Million thx lady glitch! It worked!!
    Unfortunately now i face another problem: in the sprite i also had a beam of light to simulate the flare of the gunshot, it appeared at the beggining and then with the "animation end" event it went away, but now when i implement the irandom, certain bullets become the flare itself as it is one of the images included inside the sprite. Is there a way that in the irandom...i can skip that image?
    Im very sorry to disturb you again. Thanks a lot
     
    Lady Glitch likes this.
  4. Lady Glitch

    Lady Glitch Member

    Joined:
    Sunday
    Posts:
    15
    Use irandom_range instead
    Code:
    image_index = irandom_range(1,sprite_get_number(sprite_index));
    This will skip the very first sub-image of your sprite. If you want to skip more, change "1" to the number of sub-images you want to skip, but make sure to move those sub-images at the beginning in your sprite editor.

    I hope this helps :)
     
    PabloDiez likes this.
  5. PabloDiez

    PabloDiez Member

    Joined:
    Monday
    Posts:
    3

    PERFECT!!! Million thanks Lady Glitch!!! That's exactly what i wanted! Wow! this sure seems like magic hahaha
    Thank you thank you thank you!!!
     
    Lady Glitch likes this.

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