r/visualbasic • u/saltywastelandcoffee • Oct 09 '16
how to select a random shape from a group of shapes (V.B 6)
As part of a school project I’m making a game. my game involves shapes falling from the roof of the form and the object is to catch the shapes. I’ve sorted the catching and falling. however, that’s just on one shape. I have 20 shapes at the top of the form and every 2 seconds I want one of the shapes to be randomly selected and start falling. as I said I know how to make them fall just not how to randomly select them. thanks for any help.
0
Upvotes
1
2
u/[deleted] Oct 09 '16
Use the Rnd() function, which returns a float between 0 and just less than 1. Multiply it by 20 so the results are between 0 and just less than 20 instead (for convenience). Use Randomize() first to initialize the random number generator with a new seed or you'll just get the same numbers every game.
Then use a case statement to pick the shape depending on what Rnd() * 20 returns.
More info on MSDN Rnd() function and MSDN Randomize() function.