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.
MULTIPLE BULLETS
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:
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:
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.
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.