Random Moving Objects

Discussion in 'Programming' started by Alexis3335, May 25, 2018.

  1. Alexis3335

    Alexis3335 Member

    Joined:
    May 25, 2018
    Posts:
    3
    Hello,
    I am making an Asteroid-like game and I am a begginer.I now have a spaceship that follows your cursor and moves and it even has a little flame animation,but I have trouble with the "asteroids".I made the object with the sprite,but how can I make it so it moves randomly on the room and when it hits the player,you go to the "Game Over" room I will make (for this part of coding,I'm okay)Could you guys help me?Thanks for your time :)
    (Picture is showing my Spaceship object coding for now,idk if it's usefull but I put it just in case) View attachment 18590
     
  2. Jdown79

    Jdown79 Member

    Joined:
    Aug 21, 2016
    Posts:
    69
    so in create you can call image_angle to be random on spawn ( I think irandom(0,359))
    and then call direction to that angle, and apply a speed.

    as for game over, if place_meeting() is how you can call the collision.
     
  3. Alexis3335

    Alexis3335 Member

    Joined:
    May 25, 2018
    Posts:
    3
    I don't really get,I wrote irandom(0,359) but you only need 1 argument,not 2.As for the speed and direction,what commands should I use?
     
  4. flerpyderp

    flerpyderp Member

    Joined:
    Apr 26, 2018
    Posts:
    205
    irandom indeed requires only 1 argument, Jdown79 likely meant irandom_range which isn't necessary if the lowest value required is 0.

    You could use the functions random_range, irandom_range, or choose in the create event of those objects. I recommend reading the manual on how these commonly used functions work.
     
  5. Jdown79

    Jdown79 Member

    Joined:
    Aug 21, 2016
    Posts:
    69
    Ahh yes, my mistake, i did mean random_range, but as flerpy has said, is an unnecessary function for this case.
     
  6. Alexis3335

    Alexis3335 Member

    Joined:
    May 25, 2018
    Posts:
    3
    I found a fix on YouTube,but thanks for your help! I will read the manual too :)
     

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