0
votes

I'm making a game in AS3, with immense inspiration from games such as Mushihimesama (Bug Princess on iOS), Dodonpachi and the Touhou series. It mainly revolves around having the player dodge a huge number of bullets (sometimes numbering in the hundreds) at a time while taking down a large number of enemies and bosses.

Each "bullet" in my game takes in several parameters, including start position, x-speed, y-speed, movement behavior, color and size. Each function that "fires" these bullets takes in parameters such as point where the bullets come from, initial angle to fire at, which bullets to fire, how many to fire, how fast to fire them, when to stop firing them.

Some big limitations to my methods are that bullets have to come from a single point, their starting points cannot be offset on the x or y, every bullet has to follow a specified path and behave in a specified way and they cannot be added to the stage without a parent.

If anyone has knowledge of these games and the best way to go about creating similar "fire" functions, I would greatly appreciate your advice.

EDIT: Another possibly important thing about this game is that the bullets are all drawn with code.

2
Unsure why your shot HAVE to originate at one point, can you show us some code? :) - Nate
My game development training is about one semester, I took a game dev course as an elective and decided to see how far I could take my knowledge after that, so I've been doing this for about ~5 months and I'm sure that my methods probably aren't the best. Basically they originate from one point because I'm not sure how to make it easy to write, and make them originate from anything else. This also lets me know what enemy is actually shooting the bullets, and I use this in other parts of the game, for example, I need to clear all the bullets on screen that where fired from specific enemies. - Evan Ward
Here's a snapshot of 2 main fire functions in the game. i.imgur.com/tdCL7.png The first is a function that takes another function and offsets it around an arc, the second is a function that fires bullets in succession around a circle, in a "sprinkler"-esque fashion (thus the name). "up" is a mod that affects how the bullets are fired, the "if count..." part allows me to designate certain bullets to NOT fire, creating gaps in lines of bullets, the var Tick at the bottom is just an anonymous function that calls a version of itself to continue the firing. - Evan Ward
The "HAVE to come from a single point" doesn't mean that that point is the same all of the time, it's just that they cannot be displaced during a functions running time. It's just that the way the bullets are added, they come from a specific point on the enemy, I can make multiple bullet spawn points however, but calling bullets from each one requires another function call. - Evan Ward
I think what would help you greatly would be to look into object oriented methodology. Flash / AS3 is object oriented so you can use these general design practices to help with the relationships between the items. For example, your enemy is an object and each bullet it fires is an object. The bullet can have a property called enemy that when you initiate the bullet links back to the enemy - thus you always know what bullet is owned by what enemy. You can have the bullet start its firing position based off of the parent enemy location at the time of firing - meaning the enemy can move - Nate

2 Answers

0
votes

You will probably want to do some refactoring, as having a bunch of public functions in a single class and passing around that many parameters doesn't seem like a manageable solution.

I would start by creating a ShotPattern base class or interface, with a class extending or implementing it for each type or category of shot pattern. The logic for how and when to fire bullets, and what kind of bullets to fire, would be handled by the ShotPattern. The ShotPattern could also affect the Bullets after they are fired, to change their direction or speed, or even produce more Bullets to create a splitting effect.

The constructors for ShotPatterns could still take some parameters; the goal is just to reduce the repetition and keep a larger portion of the bullet generation logic internal to the instance. The func parameter in your FireAroundArc function is clever, and the same idea can be used by creating ShotPatterns that require other ShotPatterns as parameters.

Each instance of an Enemy should keep track of its ShotPatterns, which in turn keep track of their Bullets; that would allow clearing bullets fired by certain enemies, and the bullet creation pattern could move with the enemy.

In terms of actually designing enemy attack patterns, there's a lot of possibility and it's a very open-ended problem. Having a solid architecture is important and will allow you to add more complexity without having to change as much existing code, but the general problem of creating patterns that are interesting, varied and challenging is beyond the scope of a Stack Overflow question.

0
votes

One solution would be to create a ShotManager class which could have a method Shoot that took a paramter of type Bullet that would contain information about the type and trajectory of the bullet. Inside the ShotManager class you could update the positions of the bullets according to their type.

Drawing of the bullets would be handled seperatly by reading a list of the current bullets and their positions from the ShotManager and matching these with some Sprites or bitmap drawings.