How do i create bullet patterns ?

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

I’m trying to create a bullet hell game. What should i do to make the enemies have different bullet patterns ?

:bust_in_silhouette: Reply From: kris_bsx

Hi,

To put it simply, I think you can create different “BulletPattern” classes. If you use GDScript, you can simply create a script and create a new instance of this class in your Ennemy script.

This way, an “Ennemy” class could have one or more “BulletPattern” classes, and the bullet patterns could be used by any enemy.

Then, each “BulletPattern” class could have one or more timers to define when to fire bullets.

You can use timers to define when a firing sequence starts and when it stops. And you can use timers to define an interval between two fire event.

Then, to define the direction of the bullets, you need to use some geometric functions, but I think you already know that!

Here is a very basic idea of what you can do:

Assign a bullet pattern to an ennemy by adding a code like that in your Ennemy class:

var parent = get_node("Path_to_parent_node_in_scene_tree");
var bulletPattern = load("res://Scripts/BulletPattern.gd").new(parent);

Start bullet pattern:

bulletPattern.start();

Stop bullet pattern:

bulletPattern.stop();

And the BulletPattern class:

var parent;
var timer;

# Constructor
func _init(parent):

    # You need a parent node to add the timer to the scene tree
    self.parent = parent;
    
func start():

    fire();

    # Note: You can create the timer in Constructor ("init()")
    timer = Timer.new();
    timer.connect("timeout",self,"fire");
    parent.add_child(timer);
    timer.start(1.0); # Fire every 1 second

func stop():

    # Add "if timer != null" if you are not sure the timer has been instanciated
    timer.stop();

    # Do not forget to delete the timer from scene tree
    # if you add it every call to "start()"
    timer.queue_free();

func fire():

    print("FIRE!");

Hope this helps! Good luck!