Flash Example: Random turntable game

Source: Internet
Author: User
Tags cos relative sin
Random

Animation effect:

Click here to download the source file

Of course, the program can be perfected, but the main as and architecture have been completed. You can try to finish it yourself.
Add that, because the animation in the graphics more, so the operation may be slower, you can reduce the flash to play, it will not slow. (Of course this can be optimized, I do not have time to do this)
Let me explain briefly the purpose of AS

First frame

DECLARE variables here
pans=0; The rotation speed of the turntable, the unit is the Radian value
pansmax=0.3; The maximum speed of a turntable, measured in radians.
panva=-0.0008; The rotation of the turntable acceleration, due to the need for it more and more slowly, the so-called value and Pansmax opposite.
qiuvv=0; The position of the ball is relative to the angle value of the center point (198,198) of the turntable, the unit radian.
qius=0; The speed of the ball, relative to the center point of the turntable (198,198), the angular value of the speed, Unit radian.
qiusmax=-0.26; Maximum speed of small ball speed
qiusmin=-0.01; The minimum speed of a small ball, which determines how much of the ball's speed will drop to a turntable.
qiuva=0.001; The acceleration of the ball speed.
qiur=184; Small ball turning radius.

Frame 11th

Pans=pansmax-pansmax*random (100)/1000;
Qius=qiusmax+qiusmax*random (100)/1000;

The ball and the turntable are given an initial speed, because the result has a random change, so add the random to let the initial speed of an indefinite value.
Frame 12th

if (pans>0) {
Pan._rotation +=pans/math.pi*180;
Pans +=panva;
}

The above statement rotates the turntable and slows down slowly with the acceleration panva

if (qius<qiusmin) {//when the speed of the ball is still greater than the minimum speed. Note that the Qius equivalent is a negative radian value, so it is the < number instead of the > number
QIUVV +=qius; The turning angle of the ball increases Qius;
Qiuvv1 =qiuvv-pan._rotation*math.pi/180;; QIUVV1 is a temporary value used to record the relative angular difference between a small ball and a turntable.
tx= (qiur-qius*40-10) *math.sin (QIUVV) +198; Calculate the coordinates of the ball, note that the reason why the radius is not qiur but (qiur-qius*40-10) is because of hope to achieve an effect, according to the speed of the ball, let it slow, the closer the disc
ty=-(qiur-qius*40-10) *math.cos (QIUVV) +198;
QIU._X=TX;
Qiu._y=ty;
Qius +=qiuva; Small ball acceleration


else {//when the speed of the ball is too slow, less than the minimum speed
QIUVV =qiuvv1+pan._rotation*math.pi/180; The rotation of the ball is equal to the rotation of the turntable, plus the angle difference between them, is actually let the ball set on the turntable.
tx= (QIUR-17) *math.sin (QIUVV) +198;
ty=-(QIUR-17) *math.cos (QIUVV) +198;
QIU._X=TX;
Qiu._y=ty;
gotoAndPlay (14); The above is not difficult to understand, do not explain.
}

Frame 14th
Originally this frame is reserved for optimization use, meaning is to make the position of the ball more standardized, because now the ball stop position is random, it is likely to stop between the 2 lattice. But as I did not write, you find a way to solve it, I remind you, you can use the array to record the 37 key points of the Radian value, and then assign the value to QIUVV1.
Frame 15th

if (pans>0) {
Pan._rotation +=pans/math.pi*180;
Pans +=panva;
The above statement is when the turntable speed is still greater than 0 to allow the disk to rotate
else {//when the disk stops
m=0;
i=0;
while (i<=36) {
lik=pan["ser-" +i];
if (Lik.hittest (tx,ty,true)) {//In the instance pan, there are 37 instances representing 37 number regions, which are used to determine whether the coordinate tx,ty of the ball is coincident with the first number area. Refer to the Help for the use of HitTest
M=i;
i=37;
}
I+=1;
}
gotoAndStop (17);
}
}
QIUVV =qiuvv1+pan._rotation*math.pi/180;
tx= (QIUR-17) *math.sin (QIUVV) +198;
ty=-(QIUR-17) *math.cos (QIUVV) +198;
QIU._X=TX;
Qiu._y=ty;
The above statement allows the ball to follow the disc to rotate.

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.