Shooting bullets
[ September 20, 2003 ] by Mad Sci
Mad-Sci explains two ways of firing bullets: multiple bullets shoot and single bullet shoot.

Shooting is the most important thing in any arcade game. Basically you have 2 types of shooting. The first one is multiple bullets shooting when you press SPACE key, and the second is one bullet at a time.


Shooting of multiple bullets can be done duplicating movie clips. So lets say you have one movie clip which you name "bullet". This movie clip will be the one we duplicate. Inside you script it in a such a way that it goes up no matter if the SPACE key is down or not. The seccond step is to bind that bullet to the ship. In the actions of the ship you can put:

_root.bullet._x = this._x;
_root.bullet._y = this._y;

When you press the SPACE key you basicaly duplicate this movie and because the new movie will have a different name it will not be bound to the ship and will go up.

In this example, each line of the .fla file is explained in detail:

Download the source code of this example


You have 2 conditions: shooting and not-shooting. When not shooting the bullet is bound to the ship coordinates. When shooting it goes up untill it reaches the top of the scene: at this moment it will be repositioned and bound to the ship again.

Download the source code of this example

In other types of games like Top-Down view or Side-scroll view the basis of shooting is almost the same. In top-down view what you need to know is not only when you shoot or not, but also the current direction the hero: is it facing like LEFT, RIGHT, UP or DOWN? In side scroll you need only 2 directions LEFT and RIGHT. The current direction could be marked when appropriate key is pressed, for example:

if (Key.isDown(Key.LEFT)) dir = "left";
if (Key.isDown(Key.RIGHT)) dir="right";

When you press the SPACE key look first for the variable dir and then shoot a bullet in this direction.

Name: Mad Sci
Location: N/A
Age: N/A
Flash experience: N/A
Job: N/A
| Homepage | News | Games | Articles | Multiplayer Central | Reviews | Spotlight | Forums | Info | Links | Contact us | Advertise | Credits |

| | | |

gotoAndPlay() v 3.0.0 -- (c)2003-2008 gotoAndPlay() Team -- P.IVA 03121770048