Enemy Shooting Question

Hey Everyone,

My question is how would you go about making an enemy shoot like the ones in the famous Japanese game “TouHou” by Zun. Does anyone know how this would be possible. ?
I would like the enemy to shoot in all directions. i know how to get the angle of a bullet but how would i shoot multiple bullets from all angles ?

Thanks.

As long as you have a functional Bullet class, it’s pretty easy. It was hard for me in PixelZombies because it isn’t very OO, but if your game is OO it should be easy. The code in PixelZombies might be a bad example of what to do. Someone may come by with a much better example.

Is it a 2D or a 3D game ?

If its a 2D games, then sin should find your angles for you.

If you have a bullet class then it would help a lot.
Your bullet class should contain variables like, damage, enemyId( so you know what enemy fired the bullet ), direction( your angle) and velocity, maybe possibly range, if you take that into account, and also a boolean to say whether the bullet is active.

Then, You can add say 8 bullets ( N, NE, E , SE, S, SW, W, NW ) to an ArrayList, which could be specific to the enemy fired, disregarding the need for enemyId in the bullet class.

Then you can simply render them, and check for collisions.

Hope this helps

You could try this bullet and turret classes I made:

rel.phatcode.net/junk.php?id=139

This is actually really bad code design. Instead of having an enemyID at all, each enemy should have an arraylist of bullets (this can be optimized but I’m keeping it simple). Since each bullet is its own individual bullet, it doesn’t make a lot of sense to create a new bullet for each direction - if you could only ever fire one bullet, and if the direction of firing changed the bullet in a major way, then it might make sense.

[quote] You can add say 8 bullets ( N, NE, E , SE, S, SW, W, NW ) to an ArrayList, which could be specific to the enemy fired, disregarding the need for enemyId in the bullet class.
[/quote]
i went on to say that jimmit. and it should work, flawed design and all, and it is easy for a new person to understand, they could then build on it and make it better.

No, I mean the 8 bullet method is not good design. And you should always start with good design - simple design, but good. Bad habits are worst when built from the start.

Hey, that really gives me some really good help. but the problem is i don’t really understand the code too great. How do i make the pasterns like you do. could you simplify it ?

err… i havent wrote any of these out before, but im sure if you created your bullet class :
Bullet.java

public class Bullet {

float x, float y;
double direction;
int range;
boolean alive;

public Bullet(float x, float y, double direction, int range, boolean alive)
{
   // Set the global variables with the local ones
   // eg
   this.x = x;
}

public void renderBullet(Graphics g)
{
   // Render Settings
}
 etc etc
}

and then just create the bullet in your enemy class or whatever

ArrayList<Bullet[]> activeBullets = new ArrayList<Bullet[]>;

then when the enemy fires a bullet

public void fireBullet()
{
Bullet newBullet = new Bullet(...);
activeBullets.add(newBullet);
}

then simply render them and check for collisions

you could try to take a look here, i’ve made a “special” shot that allow you to shoot many(variable) bullets in different direction,
but i have no idea if that’s a good or bad design :stuck_out_tongue:
good luck