Be a Supporter!

AS: Need help with shooting engine.

  • 461 Views
  • 6 Replies
New Topic Respond to this Topic
Jenjamik
Jenjamik
  • Member since: Jul. 8, 2005
  • Offline.
Forum Stats
Member
Level 14
Blank Slate
AS: Need help with shooting engine. 2007-01-10 21:27:39 Reply

My friend is making a game (based around Comet Busters), that is a space shooter. It is in top-down view (EV Nova, EV Override, Radien X kind of view). He is having trouble giving four different ships the ability to shoot.

What he needs:

- Code that works with any ship.

- Bullets will shoot in the direction the ship is pointing, and move independently, not turning as the ship turns unrealistically.

- Bullets are not simple instant A to B shots (Madness Interactive), they spend a good time in the air (space).

Asking for the exact code would be unrealistic, because I don't know the instance names, or the buttons that work for each ship.

Anyone have any help?

DarkMana
DarkMana
  • Member since: Apr. 4, 2005
  • Offline.
Forum Stats
Member
Level 23
Blank Slate
Response to AS: Need help with shooting engine. 2007-01-10 21:33:55 Reply

The perfect shooting tutorial.


Asus P5Q PRO, Intel E8400 @ 3.60 GHz, 4GB DDR2-1000, ATI HD4850

BBS Signature
Jenjamik
Jenjamik
  • Member since: Jul. 8, 2005
  • Offline.
Forum Stats
Member
Level 14
Blank Slate
Response to AS: Need help with shooting engine. 2007-01-10 21:45:25 Reply

That looks like a good tut, but thi shooting doesnt have to do with the mouse. It is like, rotate your ship with arrow keys, and shoot with space, in the direction the ship is pointing.

Madferit
Madferit
  • Member since: Jul. 29, 2005
  • Offline.
Forum Stats
Member
Level 10
Blank Slate
Response to AS: Need help with shooting engine. 2007-01-10 21:58:45 Reply

At 1/10/07 09:45 PM, PimpinJ wrote: That looks like a good tut, but thi shooting doesnt have to do with the mouse. It is like, rotate your ship with arrow keys, and shoot with space, in the direction the ship is pointing.

So just replace the mouse actions with keyboard actions.

Kart-Man
Kart-Man
  • Member since: Jan. 7, 2007
  • Offline.
Forum Stats
Member
Level 27
Blank Slate
Response to AS: Need help with shooting engine. 2007-01-10 22:27:55 Reply

At 1/10/07 09:58 PM, Alacrity wrote: So just replace the mouse actions with keyboard actions.

on frame:
var bc=1000; //bulletcount
_root.onEnterFrame=function(){
if (Key.isDown (Key.SPACE)) {
bc++;
if(bc>1100){ bc=1000; } //Reset bulletcount
duplicateMovieClip("bullet", "b"+bc, bc); //Create dupe bullet
}
}

on bullet clip, instance named bullet:
onClipEvent(load){
spd=20; //bullet speed
_x=_root.ship._x; //Move to ship_x
_y=_root.ship._y; //Move to ship_y
_rotation= _root.ship._rotation; //Point in same direction as ship
}
onClipEvent(enterFrame){
if(_name == "bullet"){
_x = -1000; //Move the original bullet MC offstage
}else{
//Run this movement code on all dupes
if (_rotation>180) {
_y += (spd*Math.cos( Math.PI/180*_rotation));
_x -= (spd*Math.sin( Math.PI/180*_rotation));
} else {
_y -= (spd*Math.cos (Math.PI/180*_rotation));
_x += (spd*Math.sin( Math.PI/180*_rotation));
}
//if(hitTest(_root.enemy)){ blahh; } Not going to address this here, check AS: Main for hitTest threads.
}
if(_x>Stage.width || _x<0 || _y<0 || _y>Stage.height){
//If off-stage, delete the dupe to save CPU
this.removeMovieClip();
}

}


postcount +=1;
Newgrounds Photoshop Headquarters || Don't use MS Paint! Use Aviary!
SING US A SING YOU'RE THE PIANO MAN

BBS Signature
3dwarrior
3dwarrior
  • Member since: Nov. 3, 2003
  • Offline.
Forum Stats
Member
Level 10
Blank Slate
Response to AS: Need help with shooting engine. 2007-01-11 01:42:05 Reply

I would like to note that for this code:

if (_rotation>180) {
_y += (spd*Math.cos( Math.PI/180*_rotation));
_x -= (spd*Math.sin( Math.PI/180*_rotation));
} else {
_y -= (spd*Math.cos (Math.PI/180*_rotation));
_x += (spd*Math.sin( Math.PI/180*_rotation));
}

you only need this:

_y -= (spd*Math.cos (Math.PI/180*_rotation));
_x += (spd*Math.sin( Math.PI/180*_rotation));

I never knew why the code checks for (_rotation>180) because, in flash the values you can get for _rotation is between 0 to 180 or 0 to -180...


AS2 Main | AS3 Main | Flash Wiki There is no excuse for not trying to learn. Linux.

BBS Signature
FlashBurgerHelper
FlashBurgerHelper
  • Member since: Jul. 5, 2006
  • Offline.
Forum Stats
Member
Level 13
Blank Slate
Response to AS: Need help with shooting engine. 2007-01-11 02:00:23 Reply


I never knew why the code checks for (_rotation>180) because, in flash the values you can get for _rotation is between 0 to 180 or 0 to -180...

because people dont seem to notice it cause its common for it to goto 360degrees.
only people that use trace functions would notice