Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (476)
Games in Android Showcase (106)
games submitted by our members
Games in WIP (533)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Enemy Shooting Question  (Read 870 times)
0 Members and 1 Guest are viewing this topic.
Offline GlennBrann
« Posted 2013-05-24 21:53:07 »

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.
Offline Sammidysam
« Reply #1 - Posted 2013-05-24 22:36:13 »

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.
Offline Andre Lopes
« Reply #2 - Posted 2013-05-24 23:28:27 »

Is it a 2D or a 3D game ?
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline _Scyth_

Junior Member





« Reply #3 - Posted 2013-05-27 13:09:52 »

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
Offline relminator
« Reply #4 - Posted 2013-05-27 18:19:00 »

You could try this bullet and turret classes I made:

rel.phatcode.net/junk.php?id=139
Offline Jimmt
« League of Dukes »

JGO Kernel


Medals: 128
Projects: 4
Exp: 3 years



« Reply #5 - Posted 2013-05-27 18:34:20 »

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
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.
Offline _Scyth_

Junior Member





« Reply #6 - Posted 2013-05-27 19:00:27 »

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
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).

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.

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.
Offline Jimmt
« League of Dukes »

JGO Kernel


Medals: 128
Projects: 4
Exp: 3 years



« Reply #7 - Posted 2013-05-27 19:12:26 »

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.
Offline GlennBrann
« Reply #8 - Posted 2013-05-27 19:28:28 »

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 ?
Offline _Scyth_

Junior Member





« Reply #9 - Posted 2013-05-27 19:40:19 »

err... i havent wrote any of these out before, but im sure if you created your bullet class :
Bullet.java
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
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

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


then when the enemy fires a bullet

1  
2  
3  
4  
5  
public void fireBullet()
{
Bullet newBullet = new Bullet(...);
activeBullets.add(newBullet);
}


then simply render them and check for collisions
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline alaslipknot
« Reply #10 - Posted 2013-05-28 12:34:32 »

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  Tongue
good luck

"It's not at all important to get it right the first time. It's vitally important to get it right the last time."
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

pw (18 views)
2014-07-24 01:59:36

Riven (17 views)
2014-07-23 21:16:32

Riven (14 views)
2014-07-23 21:07:15

Riven (17 views)
2014-07-23 20:56:16

ctomni231 (45 views)
2014-07-18 06:55:21

Zero Volt (41 views)
2014-07-17 23:47:54

danieldean (32 views)
2014-07-17 23:41:23

MustardPeter (36 views)
2014-07-16 23:30:00

Cero (51 views)
2014-07-16 00:42:17

Riven (50 views)
2014-07-14 18:02:53
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!