Bullet pattern systems

A place for people with an interest in developing new shmups.
Post Reply
vonWolfehaus
Posts: 6
Joined: Tue Nov 30, 2010 3:41 am

Bullet pattern systems

Post by vonWolfehaus »

Hi again. As I build my next game/shmup, I'm putting a lot of thought into the bullet pattern system. What I'm wondering, after viewing a bunch of shmup gameplay vids, is if I should code up a system that is independent of enemies (ie the wave formation determines a unique bullet pattern), or if each enemy should have a set bullet pattern. Or some other method?

At the moment I think it's easier if each enemy type has a set pattern to fire but changes with difficulty level. But it's early enough in development that I can rewrite it to be more flexible... if it's worth it. Looking for input on what you guys think is a really good system to use :) Cheers
Attila7894
Posts: 9
Joined: Sat Dec 12, 2009 1:52 pm
Contact:

Re: Bullet pattern systems

Post by Attila7894 »

Usually I separate bullet pattern logic from the enemies.

In this way, I can choose the preferred pattern for each enemy, and even change it at runtime, without having to copy&paste logic code.
User avatar
Sumez
Posts: 8778
Joined: Fri Feb 18, 2011 10:11 am
Location: Denmarku
Contact:

Re: Bullet pattern systems

Post by Sumez »

I obviously keep my bulllet patterns as separate objects, but each bullet is a part of the same object, since treating each bullet as an object on its own can cause serious performance issues with thousands of bullets on screen, even though it would be the proper OOP way to do it...
User avatar
Udderdude
Posts: 6294
Joined: Thu Feb 16, 2006 7:55 am
Location: Canada
Contact:

Re: Bullet pattern systems

Post by Udderdude »

Sumez wrote:thousands of bullets on screen
This should not be happening anyway. Even hundreds of bullets is enough to make things extremely difficult.
User avatar
Sumez
Posts: 8778
Joined: Fri Feb 18, 2011 10:11 am
Location: Denmarku
Contact:

Re: Bullet pattern systems

Post by Sumez »

I don't like to think that way when coding, and always stress test using scenarios that are at least ten times worse that what I think I can expect.
If I expect my game to reach several hundred bullets at its worst, I test it using thousands.
User avatar
retlaf
Posts: 31
Joined: Mon Jun 13, 2011 5:33 pm
Location: Canada
Contact:

Re: Bullet pattern systems

Post by retlaf »

Sumez wrote:I obviously keep my bulllet patterns as separate objects, but each bullet is a part of the same object, since treating each bullet as an object on its own can cause serious performance issues with thousands of bullets on screen, even though it would be the proper OOP way to do it...
What exactly do you mean by making each bullet a part of the same object? Do you mean having only a single Bullet class which every bullet is an instance of, or do you mean having all bullets a part of the same instance declared sequentially in memory?
User avatar
Sumez
Posts: 8778
Joined: Fri Feb 18, 2011 10:11 am
Location: Denmarku
Contact:

Re: Bullet pattern systems

Post by Sumez »

The latter.
User avatar
retlaf
Posts: 31
Joined: Mon Jun 13, 2011 5:33 pm
Location: Canada
Contact:

Re: Bullet pattern systems

Post by retlaf »

I agree - Data Oriented Design has huge payoffs when programming shmups in particular because of the huge amount of small pieces of similar data. Optimizing like this isn't a bad idea because not only do you have the freedom to add more bullets, but you also have room to add more complexity to the logic manipulating them.
User avatar
Rozyrg
Posts: 918
Joined: Wed Feb 11, 2009 12:03 am
Location: Southeast USA

Re: Bullet pattern systems

Post by Rozyrg »

I just have a script that is essentially a list of parameters for preset patterns. An enemy may start with one by default; but given certain conditions, they can call any other on the list. Each pattern 'type' has it's own unique script, though; but they all use the same variables, so there's no issue switching from one to another. I can get about the same results with or without specialized pattern generator objects; but it is a bit tidier with them.

As for creating bullets without using multiple objects, I've only dabbled a bit; but manual collision detection drives me completely bonkers. -_-
User avatar
Sumez
Posts: 8778
Joined: Fri Feb 18, 2011 10:11 am
Location: Denmarku
Contact:

Re: Bullet pattern systems

Post by Sumez »

I learned quite quickly, the hard way, that including a collision detection routine on each bullet as a separate class was not the way to go. :P

Like retlaf said, data oriented design is important when looping through potentially hundreds of visible objects, and you don't want the actual code to jump between every object on screen. I've come up with two ways to do it.
Either keep references to all the hitboxes as direct data members of the stage, with dimension information and a reference to the object that owns it, and have the stage itself calculate what's colliding, only referring to other objects when there's an actual collision.
Or keep all the bullets as data members of the pattern class, and have each pattern figure out if either of its bullets are colliding with any enemy or player.

I think I prefer the first method, even though it's very OOP-ugly, it seems to be the sensible thing to do. In order to avoid spending time on bullet-on-bullet collision I keep different kinds of hitboxes in different collectios (a player, playerbullet, enemy and enemybullet).
User avatar
Rozyrg
Posts: 918
Joined: Wed Feb 11, 2009 12:03 am
Location: Southeast USA

Re: Bullet pattern systems

Post by Rozyrg »

Yeah, I found that out too, albeit slowly. Best to leave the collision checking to the objects on the receiving end, as there will almost always be much fewer enemies and player controlled stuff than bullets on screen.

After some frustration, I did get the collisions working well enough with my single object system... it's all managed with 1D arrays, though. That's one problem down; but all this talk of DATA and I realized I hadn't even touched data structures yet, and my first few stabs at it aren't exactly encouraging. *sigh* Time to pull out some more hair...lol
Post Reply