2d spaceshooter help needed

I've been trying to work on a 2d spaceshooter, but i'm having some problems. i've been wanting to make a semi-follow shot (for an enemy) so when it shoots it goes in the general direction of me. How would i go about doing this? i've found the center point of the player and the enemy, then i used graphics.drawLine to test if the line wud work, which it did, but now i'm having problems actually deploying a shot to move in that direction. Also i'm trying to incorporate particle effects, but i'm not sure how to do it properly. Oh, and last thing, what would be an efficient way to create a level and deploy enemies? should i preload each enemy when i initialize the level?

[688 byte] By [Astrofa] at [2007-10-3 8:54:04]
# 1

When the weapon is fired, place the shot just in front of the firing ship.

Draw the the shot.

Move the ships.

Figure out where the shot is compared to the enemy and turn it a set amount (say 15 degrees unless you want to make it a slow responder then turn it less, or a very accurate/cheating shot and turn it more).

Move the shot

Repeat the drawing, movement and turning steps.

Check out Javoids! at the link below. It is a simple Java asteroids like game with some nice changes.

http://sourceforge.net/projects/javoids/

patrickmallettea at 2007-7-15 4:04:00 > top of Java-index,Other Topics,Java Game Development...
# 2

ok, so how shud i rotate it? shud i give the shot a variable and start it at 90 (or π/2) then adjust it based on that, and update X and Y based on cos and sin?

what i have right now is an attempt at Vector based drawing, and so far it aint workin. maybe i'll try the rotation, or maybe make it wokr on both and compare.

Astrofa at 2007-7-15 4:04:00 > top of Java-index,Other Topics,Java Game Development...
# 3

I use a standard sprite class that keeps track of the position, speed, direction, etc. Start the shot at the same direction as the ship otherwise it looks odd. The shot should have a greater speed than the ship shooting it. When you move the ships and other sprites move the shots as well. Yes, update the x and y based on the speed and direction using the standard trig functions.

Feel free to use the code in my game, just keep the copyright information like the GPL says. If you don't want to use it at least try the game and see how it plays to get some ideas for yourself.

patrickmallettea at 2007-7-15 4:04:00 > top of Java-index,Other Topics,Java Game Development...
# 4

wow is javoids ur game? nice. thanks, i fixed it! i'll keep posting here as throughout the lifetime of the projects i will more than likely screw up. oh, guess what a big problem of mine had been? 1. Java's grid system is diffrerent than normal grid system, so i had to change my formulas. 2. i 4got to use double stead of int....wow i feel stupid. now mostly everything works, cept i need to figure out a nice way to make the enemy move, like maybe come in, swarm, and leave or sumthin like that ne one have ne ideas?

Astrofa at 2007-7-15 4:04:00 > top of Java-index,Other Topics,Java Game Development...
# 5

Very good question. Here's how I would approach it.

Easy:

Head towards opponent always, shooting straight at him.

Medium-Easy:

head towards opponent with random dodging side-to-side. maybe shoot off-angle also.

Medium:

Have set of different behaviours, choose (randomly or other means) between wandering, attacking, running away, gathering into "flock" for attack, whatever.

Hard - Write AI code to accomplish the above, so the little buggers get smarter as the game goes by, and learn to defeat the player.

I am not that experienced w/game writing, but I have read several book son the subject.

BobCa at 2007-7-15 4:04:00 > top of Java-index,Other Topics,Java Game Development...
# 6
so far the enemy moves in a circle, and shoots the shot angled at the player. the later oponents can create shots that can later on home in completely,but these are avanced enemies.
Astrofa at 2007-7-15 4:04:00 > top of Java-index,Other Topics,Java Game Development...