0 votes

I am trying to create a 2D Super Mario platform like game
I managed to create my own bricks and make them bust and do random coins
but Now what I like to do is

[A] at random if he breaks a brick it grows a flower on top so that the Player walks into the flower he grows..
[B] at random if he breaks a brick it sends a mushroom out (moving) the player has to chase it. if he catches it he gets (I do not know yet but I wanted to get ahead start here!

Godot version 3.4.4
in Engine
``````var random = RandomNumberGenerator.new()
var number : int
func _ready():
random.randomize()
number = random.randi()% 2
print(number)
pass

func example():
if number == 0:
print("flower")
else:
print("mushroom")
``````

1 Answer

0 votes

You already implement coins, so you probably understand how to make other collectables. If the question is about random, most common way to make it is `randi()` function. `randi()` generates random intager, so how you can use it?

Firstly, you should define probability of spawning object. Let's say that bricks drops nothing in 80% of chances, flover in 15% and mushroom in 5%. Take the modulo 100 and you'll get random int from 0 to 99. Then you can use if statement to spawn appropriate object. Like this:

``````var spawn_number = randi() % 100
if spawn_number < 15:
spawn_flower() #Make this function
elif spawn_number < 20:
spawn_mushroom() #And this too
``````
by (650 points)