Creating a Sniper Game in Flash Part 1What we will be making:
linkStep 1:
-Open up a new flash actionscript 2.0 document on (CS3) and Flash 8 and below just a new .fla.
-use the default dimensions and set the FPS to 30
Step 2: -Create a black square with dimensions 2 times as big as the stage size. (1100x800).
-Convert this square into a movie clip make sure the registration point is in the center. I gave it the name scope.
-Double click on the square to edit it.
-Create a circle about (150x150).
-With it selected, enter the x and y values of (-75,-75) in the property inspector, this makes it go to the very center of the movie clip.
-With it still selected click the eraser tool. Click erase selected fills under the eraser mode.
-Erase the selected circle, this will create a hole in our black square.
-You can fill the empty space with anything you like.
-Give the movie clip an instance name of scope, and move it far out of the way.

Step 3:
-Create a new layer and make sure that it is below the scope layer.
-Now draw out a level. I drew a city.
-Convert the city into a movie clip.
Step 4:
-Draw out a stick figure with its head separate.
-Convert the body into a movie clip.
-Convert the head into a movie clip.
-Give the head an instance name of "head"
-Give the body an instance name of "body"
-Convert both the head and body into one movie clip


Step 5:
-Drag 2 more people onto the stage (total of 3)
-Give each one a different instance name with a increasing number after it.
I used "p1", "p2", "p3".

Explanation so far: -We have a movie clip on stage with a black square with a hole in the center of it. The whole is in the center because this is where we want it to follow the mouse.
-A level drawn out with 3 people with the names "p1","p2","p3". We use the names with an incrimental number so we can easily call on them in a FOR loop. This will make more sense when we look at the actionscript code.
Actionscript:
Click on the first frame in the timeline and add this code.
Code:
Mouse.hide();
startDrag("scope",true);
num_people=3;
Mouse.hide(); This hides the real mouse cursor.
[/COLOR]
startDrag("scope",true); This makes the scope turn into our cursor.
num_people=3; This is a variable that holds the total number of people (enemys) that there are.
Code:
onMouseDown=function(){
for(i=1;i<=num_people;i++){
if(_root["p"+i].head.hitTest(_root.scope._x,_root.scope._y,true)){
_root["p"+i]._visible=false;
}
}
}
[/COLOR]
onMouseDown=function(){This tells flash that when the player presses the mouse button down then run the following code
for(i=1;i<=num_people;i++){This is a for loop that create a variable called i and gives it a value of 1, then it goes through the following code while i is less then or equal to num_players. it then adds 1 to i every run through.
[/COLOR]
if(_root["p"+i].head.hitTest(_root.scope._x,_root.scope._y,true)){ This line says that if there is a head of a person at the _x and _y values of the scope. The first part _root["p"+i] means that it is refering to the person with the instance name of whatever the letter p with the value of i added to the end of it.
_root["p"+i]._visible=false; This makes the person invisible, in part 2 we will create a death animation and create a blood effect.
}
}
}That is it, we are done with part 1. In part 2 we will cover alot more on creating effects, including adding sound, blood, animation and more.
Advertisement: