Is there a Godot tutorial somewhere for a Zuma type or bubble shooter type of game?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By MIna

I’ve looked around but I can only find tutorials on “guns” or “cannons”.

I have a mobile bubble shooter game where KinematicBody2D bubbles are spawned in from the top by basic nodes and they accumulate in order to push themselves down along the screen.

The problem is that I’m trying to make a launcher at the bottom of the screen that spawns one instance of those bubbles at random (of the 6 colors of bubbles) then launches it at the mouse position when left click is released. I’ve gotten it to spawn one type of bubble, but I can’t figure out how to do the rest. It would also need to stop moving once it hits the other bubbles.

Thanks for any help or links in advance.

:bust_in_silhouette: Reply From: Xian

Problem with godot is that the randi function is not really random hahaha.
here’s my random generator function from my one of my projects.

static func randomNumber():
	#Author: Christian Quiel Panuncillo
	#Date: 23/01/2018
	#Description: Returns a random number based on seconds and the randi().
	return OS.get_time().second+randi()

Using this would give you a perfect set of random numbers based on seconds. Convert your code that spawns bubble bullets into a single function argument with at least 1 function argument that accepts bullects, say:

func shootBubble(bullet:PackedScene)

And bullet:PackedScene passed variable is the prefabricated scenes for each type of bubble bullet. Inside the function you can instantiate the bullet as

bullet.instance()

After making the function make an array variable containing all the different bullets. Like:

var magazine = [ load("res://prefabs/yellowBall.tscn"),
                 load("res://prefabs/redBall.tscn"),
                 load("res://prefabs/blueBall.tscn")]

After that call the function as:

shootBubble(magazine[randomNumber()%magazine.size()])

The end result should allow you to randomly select a bubble type to shoot. Hope this helps you.

As for it to stop moving after collision, I don’t know what you have tried or haven’t tried so I can can’t give any concrete advice there. You can probably use the move_and_collide function and set your collision layer and collision mask to allow it all to collide. You can use move_and_collide to get the object it collided with so use that and add a script that tells the bullet to stop moving when it has detected a collision from a specific type.

Xian | 2020-09-01 05:55

I see, I will try this as soon as I get the other stuff working.

Thank you very much!

MIna | 2020-09-01 21:58