Aborigines series as Getting Started tutorial--actual combat article _flash as

Source: Internet
Author: User
This time we have to go into combat, I want to teach you to do a very simple game, each of the following code I will add comments, if you have seen the above tutorial, I want to fully understand should not be difficult.

Now let's get started. This game is my beginner's time by the tutorial to do a game, so the impression is more profound. The game is called the Snail race, the process is like this: there are several circuits on the screen, each track has a snail, each snail crawling speed is not the same. The game begins, you have to guess which snail first ran to the end. If you guessed right, you Win, otherwise, Game over.

The 1th step, we first set the size of the scene 600*400 px, running speed of 48 frames/sec This is my personal preference speed.
screen.width*0.7) {this.resized=true; this.width=screen.width*0.7 this.alt= ' Click here to open new Window\nctrl+mouse Wheel to zoom in/out ';} ' Border=0>


The 2nd step, we change the default layer name to Bkground, and draw the track, starting line and finish lines, I am here 4 track.
screen.width*0.7) {this.resized=true; this.width=screen.width*0.7 this.alt= ' Click here to open new Window\nctrl+mouse Wheel to zoom in/out ';} ' Border=0>


The 3rd step, a new layer, the layer named Wn_layer, and then draw a moving snail placed on this layer, F8 defined as MC,MC named WN_MC. Put the snail's tail in the middle of the whole MC, if less this step, the snail has not finished the end. Then copy 3 of the same snail, in the property bar to adjust the color, so that they look a little different. Then align them to the starting point of each track.

The 4th step, a new layer, named Btn, and then make a button, copy 4, respectively, placed next to 4 snails.
screen.width*0.7) {this.resized=true; this.width=screen.width*0.7 this.alt= ' Click here to open new Window\nctrl+mouse Wheel to zoom in/out ';} ' Border=0>

The 5th step, remember the snail began the x-axis position data, I here is 25, and then drag a snail to the end to see its x-axis position data how much, and then write down to prepare for as. What I got here is 540. Remember to put it back!
screen.width*0.7) {this.resized=true; this.width=screen.width*0.7 this.alt= ' Click here to open new Window\nctrl+mouse Wheel to zoom in/out ';} ' Border=0>

The 6th step, a new layer, named Actoins, used to write as. We need 4 keyframes for this layer. Let me tell you why.
We need a frame to prepare to start the game, that is, let the player guess the frame, is the beginning of the game snail motionless picture. This is done by frame 1th. The 4 buttons we make are to let the player guess which snail will win.
When the game started, the player can not change the data, so the turtle crawl process, the button layer has no content.
2nd frame We have to make every snail crawl once, why only let them climb once? Because the pointer to the timeline passes through this keyframe, only the as in the frame is executed once. To keep the snail crawling, we need to repeatedly let the time pointer pass through this 2nd frame, so our 3rd frame is to get the time pointer back to frame 2nd.
After the 3rd frame is to display the results of the frame, then we create a new layer, named Show, do the 4th and 52 keyframes, in the 4th frame put a victory, in the 5th frame of the words failed.
In addition, after the game, we need a button to let the player play again, so the 4th to 5th two frames of the button layer need a button.

After the layout is finished, the entire layer is structured as shown (there are no as):
screen.width*0.7) {this.resized=true; this.width=screen.width*0.7 this.alt= ' Click here to open new Window\nctrl+mouse Wheel to zoom in/out ';} ' Border=0>
Now we have 4 objects: _root.wn1, _root.wn2, _root.wn3, _ROOT.WN4


Here's what we do in one frame:

Action Frame 1th
CODE:
_root.stop (); Stop Time Axis
_root.truewinner = 0;
_root.guesswinner = 0;

The following 2-sentence code defines two variables Truewinner,guesswinner in _root this timeline. Variables are used to store data and can be defined by themselves. The Truewinner,guesswinner here respectively indicates which snail won and what number the player guessed. This initializes both of these data.

Action Frame 2nd
CODE:
_root.wn1._x + = Random (a)/10+random (1); The x-axis data of snail 1th adds a certain number
_root.wn2._x + = Random (a)/10+random (1); The x-axis data of snail 2nd adds a certain number
_root.wn3._x + = Random (a)/10+random (1); The x-axis data of snail 3rd adds a certain number
_root.wn4._x + = Random (a)/10+random (1); The x-axis data of snail 4th adds a certain number

Read the object article, this is not difficult to understand it?
_x represents one of the properties of the object snail: The position of the x axis.
+ = to express themselves, so that understanding a=a+1 and A+=1 is the same. Represents the addition of 1.
Here's a way, random ()
This method is used to obtain a random number, such as random (10) to get any number in the middle of 0-9. The expression above obtains a random number from the 0-1.9.


Action Frame 3rd
CODE:
if (_root.wn1._x>540) {
_root.truewinner = 1;
}
if (_root.wn2._x>540) {
_root.truewinner = 2;
}
if (_root.wn3._x>540) {
_root.truewinner = 3;
}
if (_root.wn4._x>540) {
_root.truewinner = 4;
}
Judge which snail has arrived, change the value of Truewinner, record which snail wins
if (_root.truewinner!= 0) {
if (_root.guesswinner = = _root.truewinner) {
_root.gotoandstop (4);
} else {
_root.gotoandstop (5);
}
} else {
_root.gotoandplay (2);
}
/*--------------------------------------------
To judge the value of Truewinner, if it is changed, it means that there are already snails.
If it hasn't changed, the snails are not here yet.
If not, just jump the _root pointer to frame 2nd and let them keep running,
It's just not the same as judging the player's pressure and the real one. If you guessed right, let the time
The pointer jumps to frame 4th, or jumps to frame 5th.
---------------------------------------------*/

It should be easy to understand the process carefully.

Next is the as on the button:
button for frame 1th

CODE:
On (release) {
_root.play ();
_root.guesswinner = 1;
}

The first snail next to the button above the AS. When the button is released, the pointer jumps to frame 2nd, and then the record variable Guesswinner to 1 (guess 1th).
Next to the other snail code is similar to the record variable Guesswinner value of the corresponding 2, 3, 4

The last button that is used to play again.
CODE:
On (release) {
_root.gotoandstop (1);
_root.wn1._x = 25;//snail number 1th back to the beginning
_root.wn2._x = 25;
_root.wn3._x = 25;
_root.wn4._x = 25;
}

Do you see all this? Well, look what I did.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.