It is currently Thu Aug 21, 2008 5:35 pm


Post a new topicPost a reply Page 1 of 6   [ 55 posts ]
Go to page 1, 2, 3, 4, 5, 6  Next
Author Message
 Post subject: Creating a Sniper Game in Flash
PostPosted: Sun Jul 22, 2007 5:13 pm 
Commander in Chief
Commander in Chief
User avatar

Joined: Sat Apr 21, 2007 6:43 pm
Posts: 861
Location: Salem, Oregon
Creating a Sniper Game in Flash Part 1
What we will be making: link

Step 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
Image

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.
Image

Image

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.
Image


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
Image

Image

Image
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".
Image


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:


Attachments:

sniper.fla [ 83 KiB | Viewed 2038 times ]

_________________
Image
Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 26, 2007 11:05 am 
Commander in Chief
Commander in Chief
User avatar

Joined: Sat Apr 21, 2007 6:43 pm
Posts: 861
Location: Salem, Oregon
Glad to see there is an interest in this tutorial, just letting everyone know that the second part should be done Friday night or Saturday morning.

_________________
Image


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jul 28, 2007 11:15 pm 
Warrant Officer Four
Warrant Officer Four
User avatar

Joined: Sat Jul 28, 2007 10:47 am
Posts: 996
Location: Mars
I was looking for this kind of tutorial, explaining function().
How do I make it scroll? I mean, when the sight is to the left, the city will slowly move to the right, revealing more area.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jul 28, 2007 11:46 pm 
Staff Sergeant
Staff Sergeant
User avatar

Joined: Wed Apr 25, 2007 7:23 pm
Posts: 82
back from my vacation, I haven't played with actionscript very much, so pardon some of these questions if they are *ahem* newbish.

for(i=1;i<=num_people;i++) for this statement, you didn't instantiate i, do you do that previously in the code, or is the compiler just that awesome. Plus what is onMouseDown, is it a function, an object, etc. I imagine it's confusing since macromedia is organized in a movie fashion, but an = is a strange way to call a function :/

last question, what exactly is root? I see it pretending to be the little guys your shooting, and used to access the scopes orientation as well.

Thanks :D


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jul 29, 2007 4:45 pm 
Staff Sergeant
Staff Sergeant
User avatar

Joined: Wed Apr 25, 2007 7:23 pm
Posts: 82
nvm, I'm pretty sure I figured out what all teh stuff meant.
Advertisement:


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jul 29, 2007 5:07 pm 
Commander in Chief
Commander in Chief
User avatar

Joined: Sat Apr 21, 2007 6:43 pm
Posts: 861
Location: Salem, Oregon
onMouseDown is considered an event which then in the above code means that that function happens on the event. Samething with onEnterFrame.

_root. is the root of the flash movie. The thing that contains everything i just think of it as a containing movie clip.

As for scrolling left and right you could do something like this,
if the mouse is less then 50
_root._x++;
if the mouse is greater then 500
_root._x--;

that is not the best way to do it though because it is more prone to lagging, but it should work ok. I will create a nice scroller tutorial sometime soon after i perfect my way of doing it.

_________________
Image


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jul 29, 2007 6:36 pm 
Staff Sergeant
Staff Sergeant
User avatar

Joined: Wed Apr 25, 2007 7:23 pm
Posts: 82
Holy cow I didn't notice it before, but this thread got 1,400+ views?!?!? I had no idea that many people visited this site...

edit//
http://www.beedigital.net/blog/?p=1011

first link on Google, directly links to your sight...
play your cards right, and you might just earn yourself some new members :p


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jul 29, 2007 6:50 pm 
Commander in Chief
Commander in Chief
User avatar

Joined: Sat Apr 21, 2007 6:43 pm
Posts: 861
Location: Salem, Oregon
yeah making my tutorials and putting them on good-tutorials has got some hits.
what is that beedigital website do they just link to tutorials they find?

_________________
Image


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jul 29, 2007 6:56 pm 
Staff Sergeant
Staff Sergeant
User avatar

Joined: Wed Apr 25, 2007 7:23 pm
Posts: 82
I have no idea what that website is, it was just the first website that popped up when I typed in create a sniper game, in google. I'll have to remember that good-tutorials site though if I plan on making tutorials in the future :/


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jul 29, 2007 6:58 pm 
Commander in Chief
Commander in Chief
User avatar

Joined: Sat Apr 21, 2007 6:43 pm
Posts: 861
Location: Salem, Oregon
yeah

you can post them on this site :)

_________________
Image


Top
 Profile  
 
Display posts from previous:  Sort by  
Post a new topicPost a reply Page 1 of 6   [ 55 posts ]
Go to page 1, 2, 3, 4, 5, 6  Next


Who is online

Users browsing this forum: Google [Bot] and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  


Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
610nm Style by Daniel St. Jules of Gamexe.net