How do I spawn a coin at random times?

0 favourites
  • 3 posts
From the Asset Store
An educational game for Times Table. An easy to use template for developers to build larger games
  • Hi I am working on my first game a basketball style game and I have a function that spawns the net at random places on screen.

    I am trying to figure out the logic on how I can spawn a coin at random times during the game.

    So for instance, I dunk the ball in the net and a new net is spawned and maybe after 1-8 dunks from the start of game without a coin, then between the next 9 - 20 play, I want to spawn the coins not 10 times but maybe 4-5 times within that 10-20 play window.

    The only idea that came in my mind is to hardcode the play like "when score is 9, then spawn coin". Next when score is 13 then do same and etc but this will hard to manage since my game is not level based.

    Any ideas pls.

    Thanks

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Every time you score or make a shot you run logic and set a variable to choose(1,0) where if 1 is chosen then it spawns a coin and if 0 is chosen then it doesn't. So this is like a 50/50 chance. If you want to make it rare you can use choose (1,0,0,0) where it has 25% chance to spawn a coin etc.

  • mama mia, I didn't think outside the box with regards to just 1 and 0. I am always used to doing choose(1-xxx) and not choose(1,0). Will give it a try and see how it goes.

    Thanks

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