The snoocker game
ericlin@ms1.hinet.net

The bounce

I detect the collision by if (distance<=2*ball_radius){}; I use globalToLocal to handle the bounce after collision. My friction is a about of 1 twip/frame, not related to speed.

The ball going into the hole

The "ball going into the hole" consists of two segment. One is script-drive movement, driving the ball from the "hit" point to the center of the hole with the speed before hit. The other segment is a tween. It just tween the ball from the center of the hole to "vanish";

Scripting collision between multiple balls

I have two options to do check for collision between multiple balls.

One is check from ball 1 and check its hit to other 9 balls. Then pick ball 2 to check its hit to other 8 balls omit the ball 1. The total loop will be 9+8+7+6+5+4+3+2+1;

The other option is pick the moving balls only. The ball that does not move will not hit other balls.  If we got all balls moving, I will have a loop of 9*9; That is much larger than the one described above. However, most of the time, there are only about 2-5 balls moving, except the first time when all balls are gethered together. So, I will get a loop about 2*9 to 5*9 only.

The playing speed of this movie

Since the bounce, collision-checking loops and refresh balls position need heavy work of CPU, the speed of movie can not go up to what I set 36 fps. The side effect in slow machine is that, the movie will play in 36 fps if there is only one ball is moving without collision. Once there are many balls moving, the speed will go down, for example 12 fps.

It is annoying, that 8 balls bounced and moving with low movie speed. Then some balls stopped due to friction, and only one ball keeps going. Now, the hit check jobs relieved and the movie plays faster with 36 fps now. What we see on the screen is that, one ball goes "faster and faster" instead of "slower and slower by friction". It is weird.

So, I add a script. If that frame took too much time to render, I would omit some jobs to make the movie slightly faster. What job can be omitted ? I choose "refresh" functions. Flash still calculate the loop and bounce and store the x and y but I dont say _x=x;_y=y; So, it will not do "paint job" to the screen.

something I want to comment

There are many ways to script friction. Dont script like this: speed*=0.099; That is very CPU constraint.

It would be better to script: speed-=speed/1000;