How to make a shooting game

Making a Shooting Game(tut.15)
I would certainly suggest to those of you who would like to make games using flash to take this tutorial. It only a simple tutorial, but it will help those people beginning in this field of flash, and give them a better understanding.


Let’s start by inserting the following layers:
Actions- adds interaction to the game
Crosshair- so the player knows where they are shooting
Score- this is so the player can see how well they are doing
Enemy- this is what the player is to shoot, each time they hit it, the score goes up by 1.
Restart- this is so the player can play the game again if they want to

We are going to start by making the crosshair, this is very easy. Select the stroke color and set it to red, and set the fill color to no fill.
Making sure you have the oval tool selected, in the properties inspector, change the stroke height to about 2.75.
Now draw out a circle on the stage, (remember that this will be the custom cursor, so don’t make it too big).
Now select the line tool and draw a cross in it, hence the name crosshair.
Now select the whole crosshair and convert it to a movie clip naming it crosshair, also give it an instance name of crosshair in the properties inspector.
Now on the first frame of the actions layer, right click and select actions. On the first line type in:
Mouse.hide();
crosshair.onMouseMove = function() {
this._x = _xmouse;
this._y = _ymouse;
updateAfterEvent;
};

This was discussed in a previous tutorial.

Now for the enemy, for this example let’s just use a black circle to practice with.
Ensure that the enemy layer is below the crosshair layer otherwise the crosshair will appear behind the enemy.
Using the oval tool draw out a black circle on the stage, convert this in to a movie clip and name it enemy.
Now right click on the enemy and select actions, on the first line type in:
onClipEvent(mouseDown) {
if(this.hitTest(_root.crosshair)) {
_root.score+=1;
}
}

This means that if the crosshair is over the enemy and the mouse is clicked the score will go up by one. This was explained in more detail in a previous tutorial.

Now for the score. Select the text tool, in the properties inspector set it to dynamic text. Now draw out a text box in the top centre of the stage, now give it a var of score. It would also be a good idea to set the text so that it is aligned in the centre of the text box. Do this by selecting the option in properties inspector align centre.
In the first frame of the actions layer type this underneath the code that is already there:
var score = 0;

As we know this sets the score to zero.

Now in the following layer insert a keyframe at frame 206.
Actions
Score
Crosshair
Restart

At frame 205 of the enemy layer insert a keyframe

Here is where we want the final score to be displayed. Start by moving the score on frame 206 to the centre and enlarging the text size, only on the last keyframe(206). Make sure the score has not changed in the other keyframes.
Now above the score in frame 206 on the score layer, insert a static text box above it that says: Your Score:
This is so the player knows that the number on the screen is what they scored.
On the last key frame of the actions layer, right click and select actions, on the first line type in:
Stop();

This is so the game stops here for the player to read their score.
Last but no least we want to add a restart button to restart the game.
On the last keyframe of the of the restart layer, using the oval tool draw out a circle and write restart inside of it using either the brush tool or the text tool.
Convert this to a button naming it restart.
Right click on the button and select actions, now on the first line type in:
on (release) {
gotoAndPlay(1);
}

This means that when this button is clicked on the, flash will go back to frame 1 and play from there again.
There you go, your very first game, as simple as it is, you have to start somewhere.
NOTE: MAKE SURE THE ENEMY IS NOT DISPLAYED ON THE LAST KEYFRAME, OTHERWISE THE PLAYER CAN CONTINUE TO CLICK ON THE ENEMY AND THEIR SCORE WILL KEEP GOING UP.

2 comments:

Anonymous said...

ty:)
very helpful

Randylin26 said...

Great! I was about to create my personal shooting game with other tutorials!