In article <5aaf$47e6cbe8$4f612435$5605@[EMAIL PROTECTED]
>,
"CMulvey" <devnull@[EMAIL PROTECTED]
> wrote:
> This might sound like a very elementary question, i've been working on a
> small personal project making a top down shooting game where the player
> controls a character(sprite) using the mouse, the player's character
should
> be able to shoot from its current location, in a straight line in at the
> cursor.
>
> The problem i'm having is that I can't seem to get the player's
character to
> shoot anywhere near the cursor and also, it won't shoot at a constant
speed,
> i've tried a couple of different approaches which each seemed to end in
> disaster. Most of the time the character can move around and do what hes
> told but when the character is instructed to shoot the bullets fly off
in
> any direction apart from the one hes supposed to be aiming at, and at
random
> speeds.
>
> So basicly what i'm looking for is a little short algorythym to
calculate
> the coordinates for each frame when a bullet is shot from the position
of
> the players character e.g: coordinates 50,50 to where ever the cursor is
> aiming e.g (200,250) at a constant speed. The bullet terminates and is
> destroyed when it reaches the boundarys of the screen(already have this
> done).
Keep in mind that screen cordinates look like this:
-y
+y
-x +x
While mathematical coordinates look like this:
+y
-y
-x +x
Also note that 0° in math is pointing along the X axis and 90° is along
the Y -- this is very different from the compass, where North is along
the Y and 90° is along the X.
So you'll need a couple of routines to convert those. qed.
The gist of getting a bullet to go at constant speed is:
* Make sure the bullet has systemTime() of last movement stored.
(initialize this when fired.)
* At every frame...
- Get system time
- distance to move = (prevTime - currentTime) * speed
- new locationX = old locationX + (cos (direction) * distance to move)
- Similar for Y, use sin().
Remember to do the X/Y translations, and also to adjust the
direction-fired accordingly. Again:
Compass:
0
|
270 --+-- 90
|
180
Math functions:
90
|
180 --+-- 0
|
270
(Most math functions are in radians, also -- so you'll want to not
forget to do THAT conversion...!)
--
Please take off your pants or I won't read your e-mail.
I will not, no matter how "good" the deal, patronise any business which
sends
unsolicited commercial e-mail or that advertises in discussion newsgroups.


|