1. 35
posts
Registered User

## Shooter Game HELP

Ok, im makeing a side scroller shooter game where you point and click to shoot with your mouse. I wanted to make it so instead of actualy shooting a bullet movie clip out of your gun on mouseDown, just have a line apear for a split second between your gun and the enemy.

To do this i used the pythagoron therom (a^2 + b^2 = c^2)
in the code its:
x = _root.hero._x - _xmouse
y = _root.hero._y - _ymouse
_root.hyp = Math.sqrt(x*x + y*y)

Then i made a movie clip of a line and set its _xscale to c, and then set the lines _rotation to the same as the guns

my only problem is when the line rotates around it becomes thicker and thiner, also at a point the line stops growing and there is a gap between the gun and the enemy. how can i fix this? id i do the pythagorian equation wrong or something?
Last edited by lancerawks; April 27th, 2008 at 08:11 PM.

2. 557
posts
Block user.
Originally Posted by lancerawks
Ok, im makeing a side scroller shooter game where you point and click to shoot with your mouse. I wanted to make it so instead of actualy shooting a bullet movie clip out of your gun on mouseDown, just have a line apear for a split second between your gun and the enemy.

To do this i used the pythagoron therom (a^2 + b^2 = c^2)
in the code its:
x = _root.hero._x - _xmouse
y = _root.hero._y - _ymouse
_root.hyp = Math.sqrt(x*x + y*y)

Then i made a movie clip of a line and set its _xscale to c, and then set the lines _rotation to the same as the guns

my only problem is when the line rotates around it becomes thicker and thiner, also at a point the line stops growing and there is a gap between the gun and the enemy. how can i fix this? id i do the pythagorian equation wrong or something?
ditch that approach and use the drawing api.

as2:
Code:
```// myMovieClip.lineStyle ( thickness, rgb, alpha )
bullet.lineStyle ( 1, 0x000000, 100 );

//myMovieClip.moveTo( x, y );
bullet.moveTo ( startx, starty );

// myMovieClip.lineTo ( x, y );
bullet.lineTo ( targetx, targety );

// then, whenever you want to clear it:
bullet.clear ();```
as3 is nearly identical, but preface your drawing api commands with 'graphics'

i.e.
myMovieClip.graphics.lineStyle (1, 0x000000, 1);

I hope that is enough info to help you. The drawing api is pretty straightforward to use, just experiment with it until you achieve your desired results.

3. 35
posts
Registered User
Thanks man, works like a charm

4. Ah... That's useful for my laser too but I'd like to ask one question...

I see you can set the thickness. When the line is thick and the line has plain colour, it looks dull. Is it possible to add gradient colour to the line drawn by AS?

5. I think it is possible when you look at this: http://www.adobe.com/support/flash/a...ionary510.html

Since the line you draw is just a normal movieclip you should be able to apply that to the line movieclip. I'll might test it out when get back from walking with my dog! xD
Last edited by ArmoredSandwich; April 28th, 2008 at 08:08 AM.

6. I'll take a look at that. Thank you for the hint.

//edit:
And... don't quite understand the purpose and usage of the "matrix" parameter...
Last edited by fw2803; April 30th, 2008 at 10:29 PM.