pool game need help
hello all
i have pool game fla file and i try to understand the code to make it on swishmax
I succeeded in this, but I need some modifications and improvements to the file
1- How can I make the ball and the bat as in the following picture
2- Add time to the game
3- The number of misses and the number of hits that result in the ball being dropped
4- When you drop all the balls, the game ends and the game over text appears
thanks for help
Attached Files
Client Software Programmer
To answer question 1, this will start the ball at x: 170, y: 170
I also ran the script through the as2 convertor I am working on for you and it removed all comments as expected.
PHP Code:
degreestoradians = Math . PI / 180 ;
ballssunk = 0 ;
spacer = .2 ;
powermultiplier = .5 ;
friction = .965 ;
movetime = 30 ;
Array. prototype . shuffle =function() {
for( i = 0 ; i < this . length ; i ++){
this . push ( this . splice ( Math . floor ( Math . random ()* this . length ), 1 ));
}
};
function newGame (){
rackx = tablearea . _x + tablearea . _width * .75 ;
racky = tablearea . _y + tablearea . _height / 2 ;
this . attachMovie ( 'balls' , 'ball8' , this . getNextHighestDepth (),{ _x : rackx , _y : racky });
ball8 . gotoAndStop ( 8 );
ball8 . xvel = 0 ;
ball8 . yvel = 0 ;
ball8 . sunk = 0 ;
ballArray =[ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 9 , 10 , 11 , 12 , 13 , 14 , 15 ];
ballArray . shuffle ();
horizdiff = Math . sqrt ( Math . pow ( ball8 . _width + spacer , 2 )- Math . pow (( ball8 . _height + spacer )/ 2 , 2 ));
ballcoords =[[ rackx - horizdiff * 2 , racky ],[ rackx - horizdiff , racky -( ball8 . _height + spacer )/ 2 ],[ rackx - horizdiff , racky +( ball8 . _height + spacer )/ 2 ],[ rackx , racky -( ball8 . _height + spacer )],[ rackx , racky +( ball8 . _height + spacer )],[ rackx + horizdiff , racky -( ball8 . _height + spacer )* 1.5 ],[ rackx + horizdiff , racky -( ball8 . _height + spacer )* .5 ],[ rackx + horizdiff , racky +( ball8 . _height + spacer )* .5 ],[ rackx + horizdiff , racky +( ball8 . _height + spacer )* 1.5 ],[ rackx + horizdiff * 2 , racky -( ball8 . _height + spacer )* 2 ],[ rackx + horizdiff * 2 , racky -( ball8 . _height + spacer )],[ rackx + horizdiff * 2 , racky ],[ rackx + horizdiff * 2 , racky +( ball8 . _height + spacer )],[ rackx + horizdiff * 2 , racky +( ball8 . _height + spacer )* 2 ]];
for( ballpos = 0 ; ballpos < 14 ; ballpos ++){
this . attachMovie ( 'balls' , 'ball' + ballArray [ ballpos ], this . getNextHighestDepth (),{ _x : ballcoords [ ballpos ][ 0 ], _y : ballcoords [ ballpos ][ 1 ]});
eval( 'ball' + ballArray [ ballpos ]). xvel = 0 ;
eval( 'ball' + ballArray [ ballpos ]). yvel = 0 ;
eval( 'ball' + ballArray [ ballpos ]). sunk = 0 ;
eval( 'ball' + ballArray [ ballpos ]). gotoAndStop ( ballArray [ ballpos ]);
}
this . attachMovie ( 'balls' , 'ball0' , this . getNextHighestDepth (),{ _x : tablearea . _x + tablearea . _width / 4 , _y : tablearea . _y + tablearea . _height / 2 });
ball0 . gotoAndStop ( 16 );
scratch ();
var ballinterval : Number = setInterval ( this , "moveBalls" , movetime );
}
function moveBalls (){
for( curball = 0 ; curball <= 15 ; curball ++){
if(eval( 'ball' + curball ). sunk ){
eval( 'ball' + curball ). _x = Math . min ( trayarea . _x + trayarea . _width -eval( 'ball' + curball ). _width / 2 -eval( 'ball' + curball ). _width *(eval( 'ball' + curball ). sunk - 1 )- spacer *(eval( 'ball' + curball ). sunk - 1 ),eval( 'ball' + curball ). _x + 5 );
}else {
eval( 'ball' + curball ). _x +=eval( 'ball' + curball ). xvel ;
eval( 'ball' + curball ). _y +=eval( 'ball' + curball ). yvel ;
eval( 'ball' + curball ). xvel *= friction ;
eval( 'ball' + curball ). yvel *= friction ;
if( Math . abs (eval( 'ball' + curball ). xvel )< .02 && Math . abs (eval( 'ball' + curball ). yvel )< .02 ){
eval( 'ball' + curball ). xvel = 0 ;
eval( 'ball' + curball ). yvel = 0 ;
}
if(eval( 'ball' + curball ). _x +eval( 'ball' + curball ). _width / 2 > tablearea . _x + tablearea . _width ){
if(eval( 'ball' + curball ). _y -eval( 'ball' + curball ). _height * .75 < tablearea . _y ||eval( 'ball' + curball ). _y +eval( 'ball' + curball ). _height * .75 > tablearea . _y + tablearea . _height ){
sinkBall ( curball );
}else {
eval( 'ball' + curball ). xvel *=- 1 ;
eval( 'ball' + curball ). _x -=(eval( 'ball' + curball ). _x +eval( 'ball' + curball ). _width / 2 -( tablearea . _x + tablearea . _width ));
}
}else if(eval( 'ball' + curball ). _x -eval( 'ball' + curball ). _width / 2 < tablearea . _x ){
if(eval( 'ball' + curball ). _y -eval( 'ball' + curball ). _height * .75 < tablearea . _y ||eval( 'ball' + curball ). _y +eval( 'ball' + curball ). _height * .75 > tablearea . _y + tablearea . _height ){
sinkBall ( curball );
}else {
eval( 'ball' + curball ). xvel *=- 1 ;
eval( 'ball' + curball ). _x -=(eval( 'ball' + curball ). _x -eval( 'ball' + curball ). _width / 2 )- tablearea . _x ;
}
}
if(eval( 'ball' + curball ). _y +eval( 'ball' + curball ). _height / 2 > tablearea . _y + tablearea . _height ){
if(eval( 'ball' + curball ). _x -eval( 'ball' + curball ). _width * .75 < tablearea . _x ||eval( 'ball' + curball ). _x +eval( 'ball' + curball ). _width * .75 > tablearea . _x + tablearea . _width ||(eval( 'ball' + curball ). _x -eval( 'ball' + curball ). _width * .75 < tablearea . _x + tablearea . _width / 2 &&eval( 'ball' + curball ). _x +eval( 'ball' + curball ). _width * .75 > tablearea . _x + tablearea . _width / 2 )){
sinkBall ( curball );
}else {
eval( 'ball' + curball ). yvel *=- 1 ;
eval( 'ball' + curball ). _y -=(eval( 'ball' + curball ). _y +eval( 'ball' + curball ). _height / 2 -( tablearea . _y + tablearea . _height ));
}
}else if(eval( 'ball' + curball ). _y -eval( 'ball' + curball ). _height / 2 < tablearea . _y ){
if(eval( 'ball' + curball ). _x -eval( 'ball' + curball ). _width * .75 < tablearea . _x ||eval( 'ball' + curball ). _x +eval( 'ball' + curball ). _width * .75 > tablearea . _x + tablearea . _width ||(eval( 'ball' + curball ). _x -eval( 'ball' + curball ). _width * .75 < tablearea . _x + tablearea . _width / 2 &&eval( 'ball' + curball ). _x +eval( 'ball' + curball ). _width * .75 > tablearea . _x + tablearea . _width / 2 )){
sinkBall ( curball );
}else {
eval( 'ball' + curball ). yvel *=- 1 ;
eval( 'ball' + curball ). _y -=(eval( 'ball' + curball ). _y -eval( 'ball' + curball ). _height / 2 )- tablearea . _y ;
}
}
}
}
if(! ball0 . onPress ){
for( i = 0 ; i <= 15 ; i ++){
a = this [ "ball" + i ];
for( j = i + 1 ; j <= 15 ; j ++){
b = this [ "ball" + j ];
var dx = b . _x - a . _x ;
var dy = b . _y - a . _y ;
var dist = Math . sqrt ( dx * dx + dy * dy );
if( dist < a . _width / 2 + b . _width / 2 ){
_root . solveBalls ( a , b );
}
}
}
}
};
function solveBalls ( ballA , ballB ){
var x1 = ballA . _x ;
var y1 = ballA . _y ;
var dx = ballB . _x - x1 ;
var dy = ballB . _y - y1 ;
var dist = Math . sqrt ( dx * dx + dy * dy );
radius = ballA . _width / 4 + ballB . _width / 4 ;
normalX = dx / dist ;
normalY = dy / dist ;
midpointX =( x1 + ballB . _x )/ 2 ;
midpointY =( y1 + ballB . _y )/ 2 ;
ballA . _x = midpointX - normalX * radius ;
ballA . _y = midpointY - normalY * radius ;
ballB . _x = midpointX + normalX * radius ;
ballB . _y = midpointY + normalY * radius ;
dVector =( ballA . xvel - ballB . xvel )* normalX +( ballA . yvel - ballB . yvel )* normalY ;
dvx = dVector * normalX ;
dvy = dVector * normalY ;
ballA . xvel -= dvx ;
ballA . yvel -= dvy ;
ballB . xvel += dvx ;
ballB . yvel += dvy ;
}
function sinkBall ( curball ){
if( curball == 0 ){
scratch ();
}else {
if(eval( 'ball' + curball ). sunk == 0 ){
eval( 'ball' + curball ). sunk =(++ ballssunk );
eval( 'ball' + curball ). xvel = 0 ;
eval( 'ball' + curball ). yvel = 0 ;
eval( 'ball' + curball ). _y = trayarea . _y + trayarea . _height / 2 ;
eval( 'ball' + curball ). _x = trayarea . _x +eval( 'ball' + curball ). _width / 2 ;
}
}
}
function scratch (){
ball0 . xvel = 0 ;
ball0 . yvel = 0 ;
ball0 . _x = 170
ball0 . _y = 170
showStick ();
a = this ;
for( j = 1 ; j <= 15 ; j ++){
b = this . _parent [ "ball" + j ];
var dx = b . _x - a . _x ;
var dy = b . _y - a . _y ;
var dist = Math . sqrt ( dx * dx + dy * dy );
if( dist < a . _width / 2 + b . _width / 2 ){
return;
}
}
ball0 . stopDrag ();
delete ball0 . onPress ;
};
function showStick (){
if( poolstick ){
delete poolstick ;
}
this . attachMovie ( 'poolstick' , 'poolstick' , this . getNextHighestDepth (),{ _x : ball0 . _x , _y : ball0 . _y });
poolstick . power = 0 ;
poolstick . curdist = 0 ;
poolstick . onEnterFrame =function() {
if( poolstick . _alpha == 100 ){
poolstick . _x = ball0 . _x ;
poolstick . _y = ball0 . _y ;
}
if( poolstick . onPress ){
stickangle = Math . atan (-( _ymouse - ball0 . _y )/( _xmouse - ball0 . _x ))/( Math . PI / 180 );
if(( _xmouse - ball0 . _x )< 0 ){
stickangle += 180 ;
}
if(( _xmouse - ball0 . _x )>= 0 &&(-( _ymouse - ball0 . _y ))< 0 ){
stickangle += 360 ;
}
poolstick . _rotation =- stickangle - 90 ;
}else {
if( poolstick . onRelease ){
poolstick . power = Math . min ( 100 , Math . max ( 0 ,( Math . sqrt ( Math . pow ( _xmouse - ball0 . _x , 2 )+ Math . pow ( _ymouse - ball0 . _y , 2 ))- poolstick . clickdistance )));
poolstick . curdist = poolstick . power ;
}else {
poolstick . curdist = Math . max ( 0 , poolstick . curdist - 20 );
if( poolstick . curdist == 0 ){
if( poolstick . _alpha == 100 ){
ball0 . xvel = Math . sin ( poolstick . _rotation * degreestoradians )*( poolstick . power * powermultiplier );
ball0 . yvel =- Math . cos ( poolstick . _rotation * degreestoradians )*( poolstick . power * powermultiplier );
}
poolstick . _alpha -= 10 ;
if( poolstick . _alpha <= 0 ){
setMovementInterval ();
removeMovieClip ( poolstick );
}
}
}
}
if( poolstick . _alpha == 100 ){
poolstick . _x +=- Math . sin ( degreestoradians * poolstick . _rotation )*( ball0 . _width / 2 + poolstick . curdist );
poolstick . _y += Math . cos ( degreestoradians * poolstick . _rotation )*( ball0 . _width / 2 + poolstick . curdist );
}
};
poolstickAction ();
}
function poolstickAction (){
poolstick . onPress =function() {
poolstick . clickdistance = Math . sqrt ( Math . pow ( _xmouse - ball0 . _x , 2 )+ Math . pow ( _ymouse - ball0 . _y , 2 ));
poolstick . onRelease = poolstick . onReleaseOutside =function (){
delete poolstick . onRelease ;
delete poolstick . onReleaseOutside ;
if( poolstick . power <= 0 ){
poolstickAction ();
}
};
delete poolstick . onPress ;
};
}
function setMovementInterval (){
var movementinterval : Number = setInterval ( this , "checkMovement" , movetime );
}
function checkMovement (): Void {
if( poolstick ){
return;
}
for( i = 0 ; i <= 15 ; i ++){
if(eval( 'ball' + i ). xvel != 0 ||eval( 'ball' + i ). yvel != 0 ){
return;
}
}
if(! ball0 . onPress ){
showStick ();
}
}
newgame . onPress =function() {
if( ball0 ){
for( i = 0 ; i <= 15 ; i ++){
removeMovieClip ( 'ball' + i );
}
delete onEnterFrame ;
}
if( poolstick ){
removeMovieClip ( 'poolstick' );
}
newGame ();
};
Last edited by AS3.0; 02-21-2021 at 11:34 PM .
thank you AS3.0
i want the poolstick Horizontal to the left
Client Software Programmer
The var is called first_shot that allows the first shot to be a static hit.
PHP Code:
var first_shot = 0
degreestoradians = Math . PI / 180 ;
ballssunk = 0 ;
spacer = .2 ;
powermultiplier = .5 ;
friction = .965 ;
movetime = 30 ;
Array. prototype . shuffle =function() {
for( i = 0 ; i < this . length ; i ++){
this . push ( this . splice ( Math . floor ( Math . random ()* this . length ), 1 ));
}
};
function newGaormalY * radius ;
ballB . _x = midpointX + normalX * radius ;
ballB . _y = midpointY + normalY * radius ;
dVectorme (){
first_shot = 0
rackx = tablearea . _x + tablearea . _width * .75 ;
racky = tablearea . _y + tablearea . _height / 2 ;
this . attachMovie ( 'balls' , 'ball8' , this . getNextHighestDepth (),{ _x : rackx , _y : racky });
ball8 . gotoAndStop ( 8 );
ball8 . xvel = 0 ;
ball8 . yvel = 0 ;
ball8 . sunk = 0 ;
ballArray =[ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 9 , 10 , 11 , 12 , 13 , 14 , 15 ];
ballArray . shuffle ();
horizdiff = Math . sqrt ( Math . pow ( ball8 . _width + spacer , 2 )- Math . pow (( ball8 . _height + spacer )/ 2 , 2 ));
ballcoords =[[ rackx - horizdiff * 2 , racky ],[ rackx - horizdiff , racky -( ball8 . _height + spacer )/ 2 ],[ rackx - horizdiff , racky +( ball8 . _height + spacer )/ 2 ],[ rackx , racky -( ball8 . _height + spacer )],[ rackx , racky +( ball8 . _height + spacer )],[ rackx + horizdiff , racky -( ball8 . _height + spacer )* 1.5 ],[ rackx + horizdiff , racky -( ball8 . _height + spacer )* .5 ],[ rackx + horizdiff , racky +( ball8 . _height + spacer )* .5 ],[ rackx + horizdiff , racky +( ball8 . _height + spacer )* 1.5 ],[ rackx + horizdiff * 2 , racky -( ball8 . _height + spacer )* 2 ],[ rackx + horizdiff * 2 , racky -( ball8 . _height + spacer )],[ rackx + horizdiff * 2 , racky ],[ rackx + horizdiff * 2 , racky +( ball8 . _height + spacer )],[ rackx + horizdiff * 2 , racky +( ball8 . _height + spacer )* 2 ]];
for( ballpos = 0 ; ballpos < 14 ; ballpos ++){
this . attachMovie ( 'balls' , 'ball' + ballArray [ ballpos ], this . getNextHighestDepth (),{ _x : ballcoords [ ballpos ][ 0 ], _y : ballcoords [ ballpos ][ 1 ]});
eval( 'ball' + ballArray [ ballpos ]). xvel = 0 ;
eval( 'ball' + ballArray [ ballpos ]). yvel = 0 ;
eval( 'ball' + ballArray [ ballpos ]). sunk = 0 ;
eval( 'ball' + ballArray [ ballpos ]). gotoAndStop ( ballArray [ ballpos ]);
}
this . attachMovie ( 'balls' , 'ball0' , this . getNextHighestDepth (),{ _x : tablearea . _x + tablearea . _width / 4 , _y : tablearea . _y + tablearea . _height / 2 });
ball0 . gotoAndStop ( 16 );
scratch ();
var ballinterval : Number = setInterval ( this , "moveBalls" , movetime );
}
function moveBalls (){
for( curball = 0 ; curball <= 15 ; curball ++){
if(eval( 'ball' + curball ). sunk ){
eval( 'ball' + curball ). _x = Math . min ( trayarea . _x + trayarea . _width -eval( 'ball' + curball ). _width / 2 -eval( 'ball' + curball ). _width *(eval( 'ball' + curball ). sunk - 1 )- spacer *(eval( 'ball' + curball ). sunk - 1 ),eval( 'ball' + curball ). _x + 5 );
}else {
eval( 'ball' + curball ). _x +=eval( 'ball' + curball ). xvel ;
eval( 'ball' + curball ). _y +=eval( 'ball' + curball ). yvel ;
eval( 'ball' + curball ). xvel *= friction ;
eval( 'ball' + curball ). yvel *= friction ;
if( Math . abs (eval( 'ball' + curball ). xvel )< .02 && Math . abs (eval( 'ball' + curball ). yvel )< .02 ){
eval( 'ball' + curball ). xvel = 0 ;
eval( 'ball' + curball ). yvel = 0 ;
}
if(eval( 'ball' + curball ). _x +eval( 'ball' + curball ). _width / 2 > tablearea . _x + tablearea . _width ){
if(eval( 'ball' + curball ). _y -eval( 'ball' + curball ). _height * .75 < tablearea . _y ||eval( 'ball' + curball ). _y +eval( 'ball' + curball ). _height * .75 > tablearea . _y + tablearea . _height ){
sinkBall ( curball );
}else {
eval( 'ball' + curball ). xvel *=- 1 ;
eval( 'ball' + curball ). _x -=(eval( 'ball' + curball ). _x +eval( 'ball' + curball ). _width / 2 -( tablearea . _x + tablearea . _width ));
}
}else if(eval( 'ball' + curball ). _x -eval( 'ball' + curball ). _width / 2 < tablearea . _x ){
if(eval( 'ball' + curball ). _y -eval( 'ball' + curball ). _height * .75 < tablearea . _y ||eval( 'ball' + curball ). _y +eval( 'ball' + curball ). _height * .75 > tablearea . _y + tablearea . _height ){
sinkBall ( curball );
}else {
eval( 'ball' + curball ). xvel *=- 1 ;
eval( 'ball' + curball ). _x -=(eval( 'ball' + curball ). _x -eval( 'ball' + curball ). _width / 2 )- tablearea . _x ;
}
}
if(eval( 'ball' + curball ). _y +eval( 'ball' + curball ). _height / 2 > tablearea . _y + tablearea . _height ){
if(eval( 'ball' + curball ). _x -eval( 'ball' + curball ). _width * .75 < tablearea . _x ||eval( 'ball' + curball ). _x +eval( 'ball' + curball ). _width * .75 > tablearea . _x + tablearea . _width ||(eval( 'ball' + curball ). _x -eval( 'ball' + curball ). _width * .75 < tablearea . _x + tablearea . _width / 2 &&eval( 'ball' + curball ). _x +eval( 'ball' + curball ). _width * .75 > tablearea . _x + tablearea . _width / 2 )){
sinkBall ( curball );
}else {
eval( 'ball' + curball ). yvel *=- 1 ;
eval( 'ball' + curball ). _y -=(eval( 'ball' + curball ). _y +eval( 'ball' + curball ). _height / 2 -( tablearea . _y + tablearea . _height ));
}
}else if(eval( 'ball' + curball ). _y -eval( 'ball' + curball ). _height / 2 < tablearea . _y ){
if(eval( 'ball' + curball ). _x -eval( 'ball' + curball ). _width * .75 < tablearea . _x ||eval( 'ball' + curball ). _x +eval( 'ball' + curball ). _width * .75 > tablearea . _x + tablearea . _width ||(eval( 'ball' + curball ). _x -eval( 'ball' + curball ). _width * .75 < tablearea . _x + tablearea . _width / 2 &&eval( 'ball' + curball ). _x +eval( 'ball' + curball ). _width * .75 > tablearea . _x + tablearea . _width / 2 )){
sinkBall ( curball );
}else {
eval( 'ball' + curball ). yvel *=- 1 ;
eval( 'ball' + curball ). _y -=(eval( 'ball' + curball ). _y -eval( 'ball' + curball ). _height / 2 )- tablearea . _y ;
}
}
}
}
if(! ball0 . onPress ){
for( i = 0 ; i <= 15 ; i ++){
a = this [ "ball" + i ];
for( j = i + 1 ; j <= 15 ; j ++){
b = this [ "ball" + j ];
var dx = b . _x - a . _x ;
var dy = b . _y - a . _y ;
var dist = Math . sqrt ( dx * dx + dy * dy );
if( dist < a . _width / 2 + b . _width / 2 ){
_root . solveBalls ( a , b );
}
}
}
}
};
function solveBalls ( ballA , ballB ){
var x1 = ballA . _x ;
var y1 = ballA . _y ;
var dx = ballB . _x - x1 ;
var dy = ballB . _y - y1 ;
var dist = Math . sqrt ( dx * dx + dy * dy );
radius = ballA . _width / 4 + ballB . _width / 4 ;
normalX = dx / dist ;
normalY = dy / dist ;
midpointX =( x1 + ballB . _x )/ 2 ;
midpointY =( y1 + ballB . _y )/ 2 ;
ballA . _x = midpointX - normalX * radius ;
ballA . _y = midpointY - n =( ballA . xvel - ballB . xvel )* normalX +( ballA . yvel - ballB . yvel )* normalY ;
dvx = dVector * normalX ;
dvy = dVector * normalY ;
ballA . xvel -= dvx ;
ballA . yvel -= dvy ;
ballB . xvel += dvx ;
ballB . yvel += dvy ;
}
function sinkBall ( curball ){
if( curball == 0 ){
scratch ();
}else {
if(eval( 'ball' + curball ). sunk == 0 ){
eval( 'ball' + curball ). sunk =(++ ballssunk );
eval( 'ball' + curball ). xvel = 0 ;
eval( 'ball' + curball ). yvel = 0 ;
eval( 'ball' + curball ). _y = trayarea . _y + trayarea . _height / 2 ;
eval( 'ball' + curball ). _x = trayarea . _x +eval( 'ball' + curball ). _width / 2 ;
}
}
}
function scratch (){
ball0 . xvel = 0 ;
ball0 . yvel = 0 ;
ball0 . _x = 170
ball0 . _y = 170
showStick ();
a = this ;
for( j = 1 ; j <= 15 ; j ++){
b = this . _parent [ "ball" + j ];
var dx = b . _x - a . _x ;
var dy = b . _y - a . _y ;
var dist = Math . sqrt ( dx * dx + dy * dy );
if( dist < a . _width / 2 + b . _width / 2 ){
return;
}
}
ball0 . stopDrag ();
delete ball0 . onPress ;
};
function showStick (){
if( poolstick ){
delete poolstick ;
}
this . attachMovie ( 'poolstick' , 'poolstick' , this . getNextHighestDepth (),{ _x : ball0 . _x , _y : ball0 . _y });
poolstick . power = 0 ;
poolstick . curdist = 0 ;
poolstick . onEnterFrame =function() {
if( poolstick . _alpha == 100 ){
poolstick . _x = ball0 . _x ;
poolstick . _y = ball0 . _y ;
}
if( poolstick . onPress ){
stickangle = Math . atan (-( _ymouse - ball0 . _y )/( _xmouse - ball0 . _x ))/( Math . PI / 180 );
if(( _xmouse - ball0 . _x )< 0 ){
stickangle += 180 ;
}
if(( _xmouse - ball0 . _x )>= 0 &&(-( _ymouse - ball0 . _y ))< 0 ){
stickangle += 360 ;
}
if( first_shot == 0 ){
poolstick . _rotation = 90 ;
}else{
poolstick . _rotation =- stickangle - 90 ;
}
}else {
if( poolstick . onRelease ){
poolstick . power = Math . min ( 100 , Math . max ( 0 ,( Math . sqrt ( Math . pow ( _xmouse - ball0 . _x , 2 )+ Math . pow ( _ymouse - ball0 . _y , 2 ))- poolstick . clickdistance )));
poolstick . curdist = poolstick . power ;
}else {
poolstick . curdist = Math . max ( 0 , poolstick . curdist - 20 );
if( poolstick . curdist == 0 ){
if( poolstick . _alpha == 100 ){
ball0 . xvel = Math . sin ( poolstick . _rotation * degreestoradians )*( poolstick . power * powermultiplier );
ball0 . yvel =- Math . cos ( poolstick . _rotation * degreestoradians )*( poolstick . power * powermultiplier );
}
poolstick . _alpha -= 10 ;
first_shot ++
if( poolstick . _alpha <= 0 ){
setMovementInterval ();
removeMovieClip ( poolstick );
}
}
}
}
if( poolstick . _alpha == 100 ){
poolstick . _x +=- Math . sin ( degreestoradians * poolstick . _rotation )*( ball0 . _width / 2 + poolstick . curdist );
poolstick . _y += Math . cos ( degreestoradians * poolstick . _rotation )*( ball0 . _width / 2 + poolstick . curdist );
}
};
poolstickAction ();
}
function poolstickAction (){
poolstick . onPress =function() {
poolstick . clickdistance = Math . sqrt ( Math . pow ( _xmouse - ball0 . _x , 2 )+ Math . pow ( _ymouse - ball0 . _y , 2 ));
poolstick . onRelease = poolstick . onReleaseOutside =function (){
delete poolstick . onRelease ;
delete poolstick . onReleaseOutside ;
if( poolstick . power <= 0 ){
poolstickAction ();
}
};
delete poolstick . onPress ;
};
}
function setMovementInterval (){
var movementinterval : Number = setInterval ( this , "checkMovement" , movetime );
}
function checkMovement (): Void {
if( poolstick ){
return;
}
for( i = 0 ; i <= 15 ; i ++){
if(eval( 'ball' + i ). xvel != 0 ||eval( 'ball' + i ). yvel != 0 ){
return;
}
}
if(! ball0 . onPress ){
showStick ();
}
}
newgame . onPress =function() {
if( ball0 ){
for( i = 0 ; i <= 15 ; i ++){
removeMovieClip ( 'ball' + i );
}
delete onEnterFrame ;
}
if( poolstick ){
removeMovieClip ( 'poolstick' );
}
newGame ();
};
Client Software Programmer
Ok I fixed a bug I started from the last update... when you get the white ball into the hole is it good now with less limit?
PHP Code:
var first_shot = 0
degreestoradians = Math . PI / 180 ;
ballssunk = 0 ;
spacer = .2 ;
powermultiplier = .5 ;
friction = .965 ;
movetime = 30 ;
Array. prototype . shuffle =function() {
for( i = 0 ; i < this . length ; i ++){
this . push ( this . splice ( Math . floor ( Math . random ()* this . length ), 1 ));
}
};
function newGame (){
first_shot = 0
rackx = tablearea . _x + tablearea . _width * .75 ;
racky = tablearea . _y + tablearea . _height / 2 ;
this . attachMovie ( 'balls' , 'ball8' , this . getNextHighestDepth (),{ _x : rackx , _y : racky });
ball8 . gotoAndStop ( 8 );
ball8 . xvel = 0 ;
ball8 . yvel = 0 ;
ball8 . sunk = 0 ;
ballArray =[ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 9 , 10 , 11 , 12 , 13 , 14 , 15 ];
ballArray . shuffle ();
horizdiff = Math . sqrt ( Math . pow ( ball8 . _width + spacer , 2 )- Math . pow (( ball8 . _height + spacer )/ 2 , 2 ));
ballcoords =[[ rackx - horizdiff * 2 , racky ],[ rackx - horizdiff , racky -( ball8 . _height + spacer )/ 2 ],[ rackx - horizdiff , racky +( ball8 . _height + spacer )/ 2 ],[ rackx , racky -( ball8 . _height + spacer )],[ rackx , racky +( ball8 . _height + spacer )],[ rackx + horizdiff , racky -( ball8 . _height + spacer )* 1.5 ],[ rackx + horizdiff , racky -( ball8 . _height + spacer )* .5 ],[ rackx + horizdiff , racky +( ball8 . _height + spacer )* .5 ],[ rackx + horizdiff , racky +( ball8 . _height + spacer )* 1.5 ],[ rackx + horizdiff * 2 , racky -( ball8 . _height + spacer )* 2 ],[ rackx + horizdiff * 2 , racky -( ball8 . _height + spacer )],[ rackx + horizdiff * 2 , racky ],[ rackx + horizdiff * 2 , racky +( ball8 . _height + spacer )],[ rackx + horizdiff * 2 , racky +( ball8 . _height + spacer )* 2 ]];
for( ballpos = 0 ; ballpos < 14 ; ballpos ++){
this . attachMovie ( 'balls' , 'ball' + ballArray [ ballpos ], this . getNextHighestDepth (),{ _x : ballcoords [ ballpos ][ 0 ], _y : ballcoords [ ballpos ][ 1 ]});
eval( 'ball' + ballArray [ ballpos ]). xvel = 0 ;
eval( 'ball' + ballArray [ ballpos ]). yvel = 0 ;
eval( 'ball' + ballArray [ ballpos ]). sunk = 0 ;
eval( 'ball' + ballArray [ ballpos ]). gotoAndStop ( ballArray [ ballpos ]);
}
this . attachMovie ( 'balls' , 'ball0' , this . getNextHighestDepth (),{ _x : tablearea . _x + tablearea . _width / 4 , _y : tablearea . _y + tablearea . _height / 2 });
ball0 . gotoAndStop ( 16 );
scratch ();
var ballinterval : Number = setInterval ( this , "moveBalls" , movetime );
}
function moveBalls (){
for( curball = 0 ; curball <= 15 ; curball ++){
if(eval( 'ball' + curball ). sunk ){
eval( 'ball' + curball ). _x = Math . min ( trayarea . _x + trayarea . _width -eval( 'ball' + curball ). _width / 2 -eval( 'ball' + curball ). _width *(eval( 'ball' + curball ). sunk - 1 )- spacer *(eval( 'ball' + curball ). sunk - 1 ),eval( 'ball' + curball ). _x + 5 );
}else {
eval( 'ball' + curball ). _x +=eval( 'ball' + curball ). xvel ;
eval( 'ball' + curball ). _y +=eval( 'ball' + curball ). yvel ;
eval( 'ball' + curball ). xvel *= friction ;
eval( 'ball' + curball ). yvel *= friction ;
if( Math . abs (eval( 'ball' + curball ). xvel )< .02 && Math . abs (eval( 'ball' + curball ). yvel )< .02 ){
eval( 'ball' + curball ). xvel = 0 ;
eval( 'ball' + curball ). yvel = 0 ;
}
if(eval( 'ball' + curball ). _x +eval( 'ball' + curball ). _width / 2 > tablearea . _x + tablearea . _width ){
if(eval( 'ball' + curball ). _y -eval( 'ball' + curball ). _height * .75 < tablearea . _y ||eval( 'ball' + curball ). _y +eval( 'ball' + curball ). _height * .75 > tablearea . _y + tablearea . _height ){
sinkBall ( curball );
}else {
eval( 'ball' + curball ). xvel *=- 1 ;
eval( 'ball' + curball ). _x -=(eval( 'ball' + curball ). _x +eval( 'ball' + curball ). _width / 2 -( tablearea . _x + tablearea . _width ));
}
}else if(eval( 'ball' + curball ). _x -eval( 'ball' + curball ). _width / 2 < tablearea . _x ){
if(eval( 'ball' + curball ). _y -eval( 'ball' + curball ). _height * .75 < tablearea . _y ||eval( 'ball' + curball ). _y +eval( 'ball' + curball ). _height * .75 > tablearea . _y + tablearea . _height ){
sinkBall ( curball );
}else {
eval( 'ball' + curball ). xvel *=- 1 ;
eval( 'ball' + curball ). _x -=(eval( 'ball' + curball ). _x -eval( 'ball' + curball ). _width / 2 )- tablearea . _x ;
}
}
if(eval( 'ball' + curball ). _y +eval( 'ball' + curball ). _height / 2 > tablearea . _y + tablearea . _height ){
if(eval( 'ball' + curball ). _x -eval( 'ball' + curball ). _width * .75 < tablearea . _x ||eval( 'ball' + curball ). _x +eval( 'ball' + curball ). _width * .75 > tablearea . _x + tablearea . _width ||(eval( 'ball' + curball ). _x -eval( 'ball' + curball ). _width * .75 < tablearea . _x + tablearea . _width / 2 &&eval( 'ball' + curball ). _x +eval( 'ball' + curball ). _width * .75 > tablearea . _x + tablearea . _width / 2 )){
sinkBall ( curball );
}else {
eval( 'ball' + curball ). yvel *=- 1 ;
eval( 'ball' + curball ). _y -=(eval( 'ball' + curball ). _y +eval( 'ball' + curball ). _height / 2 -( tablearea . _y + tablearea . _height ));
}
}else if(eval( 'ball' + curball ). _y -eval( 'ball' + curball ). _height / 2 < tablearea . _y ){
if(eval( 'ball' + curball ). _x -eval( 'ball' + curball ). _width * .75 < tablearea . _x ||eval( 'ball' + curball ). _x +eval( 'ball' + curball ). _width * .75 > tablearea . _x + tablearea . _width ||(eval( 'ball' + curball ). _x -eval( 'ball' + curball ). _width * .75 < tablearea . _x + tablearea . _width / 2 &&eval( 'ball' + curball ). _x +eval( 'ball' + curball ). _width * .75 > tablearea . _x + tablearea . _width / 2 )){
sinkBall ( curball );
}else {
eval( 'ball' + curball ). yvel *=- 1 ;
eval( 'ball' + curball ). _y -=(eval( 'ball' + curball ). _y -eval( 'ball' + curball ). _height / 2 )- tablearea . _y ;
}
}
}
}
if(! ball0 . onPress ){
for( i = 0 ; i <= 15 ; i ++){
a = this [ "ball" + i ];
for( j = i + 1 ; j <= 15 ; j ++){
b = this [ "ball" + j ];
var dx = b . _x - a . _x ;
var dy = b . _y - a . _y ;
var dist = Math . sqrt ( dx * dx + dy * dy );
if( dist < a . _width / 2 + b . _width / 2 ){
_root . solveBalls ( a , b );
}
}
}
}
};
function solveBalls ( ballA , ballB ){
var x1 = ballA . _x ;
var y1 = ballA . _y ;
var dx = ballB . _x - x1 ;
var dy = ballB . _y - y1 ;
var dist = Math . sqrt ( dx * dx + dy * dy );
radius = ballA . _width / 4 + ballB . _width / 4 ;
normalX = dx / dist ;
normalY = dy / dist ;
midpointX =( x1 + ballB . _x )/ 2 ;
midpointY =( y1 + ballB . _y )/ 2 ;
ballA . _x = midpointX - normalX * radius ;
ballA . _y = midpointY - normalY * radius ;
ballB . _x = midpointX + normalX * radius ;
ballB . _y = midpointY + normalY * radius ;
dVector =( ballA . xvel - ballB . xvel )* normalX +( ballA . yvel - ballB . yvel )* normalY ;
dvx = dVector * normalX ;
dvy = dVector * normalY ;
ballA . xvel -= dvx ;
ballA . yvel -= dvy ;
ballB . xvel += dvx ;
ballB . yvel += dvy ;
}
function sinkBall ( curball ){
if( curball == 0 ){
scratch2 ();
}else {
if(eval( 'ball' + curball ). sunk == 0 ){
eval( 'ball' + curball ). sunk =(++ ballssunk );
eval( 'ball' + curball ). xvel = 0 ;
eval( 'ball' + curball ). yvel = 0 ;
eval( 'ball' + curball ). _y = trayarea . _y + trayarea . _height / 2 ;
eval( 'ball' + curball ). _x = trayarea . _x +eval( 'ball' + curball ). _width / 2 ;
}
}
}
function scratch (){
if( first_shot == 0 ){
showStick ();
ball0 . _x = 170
ball0 . _y = 170
}else{
}
a = ball0 ;
for( j = 1 ; j <= 15 ; j ++){
b = this . _parent [ "ball" + j ];
var dx = b . _x - a . _x ;
var dy = b . _y - a . _y ;
var dist = Math . sqrt ( dx * dx + dy * dy );
if( dist < a . _width / 2 + b . _width / 2 ){
return;
}
}
ball0 . stopDrag ();
delete ball0 . onPress ;
};
function showStick (){
if( poolstick ){
delete poolstick ;
}
this . attachMovie ( 'poolstick' , 'poolstick' , this . getNextHighestDepth (),{ _x : ball0 . _x , _y : ball0 . _y });
poolstick . power = 0 ;
poolstick . curdist = 0 ;
poolstick . onEnterFrame =function() {
if( poolstick . _alpha == 100 ){
poolstick . _x = ball0 . _x ;
poolstick . _y = ball0 . _y ;
}
if( poolstick . onPress ){
stickangle = Math . atan (-( _ymouse - ball0 . _y )/( _xmouse - ball0 . _x ))/( Math . PI / 180 );
if(( _xmouse - ball0 . _x )< 0 ){
stickangle += 180 ;
}
if(( _xmouse - ball0 . _x )>= 0 &&(-( _ymouse - ball0 . _y ))< 0 ){
stickangle += 360 ;
}
if( first_shot == 0 ){
poolstick . _rotation = 90 ;
}else{
poolstick . _rotation =- stickangle - 90 ;
}
}else {
if( poolstick . onRelease ){
poolstick . power = Math . min ( 100 , Math . max ( 0 ,( Math . sqrt ( Math . pow ( _xmouse - ball0 . _x , 2 )+ Math . pow ( _ymouse - ball0 . _y , 2 ))- poolstick . clickdistance )));
poolstick . curdist = poolstick . power ;
}else {
poolstick . curdist = Math . max ( 0 , poolstick . curdist - 20 );
if( poolstick . curdist == 0 ){
if( poolstick . _alpha == 100 ){
ball0 . xvel = Math . sin ( poolstick . _rotation * degreestoradians )*( poolstick . power * powermultiplier );
ball0 . yvel =- Math . cos ( poolstick . _rotation * degreestoradians )*( poolstick . power * powermultiplier );
}
poolstick . _alpha -= 10 ;
first_shot ++
if( poolstick . _alpha <= 0 ){
setMovementInterval ();
removeMovieClip ( poolstick );
}
}
}
}
if( poolstick . _alpha == 100 ){
poolstick . _x +=- Math . sin ( degreestoradians * poolstick . _rotation )*( ball0 . _width / 2 + poolstick . curdist );
poolstick . _y += Math . cos ( degreestoradians * poolstick . _rotation )*( ball0 . _width / 2 + poolstick . curdist );
}
};
poolstickAction ();
}
function poolstickAction (){
poolstick . onPress =function() {
poolstick . clickdistance = Math . sqrt ( Math . pow ( _xmouse - ball0 . _x , 2 )+ Math . pow ( _ymouse - ball0 . _y , 2 ));
poolstick . onRelease = poolstick . onReleaseOutside =function (){
delete poolstick . onRelease ;
delete poolstick . onReleaseOutside ;
if( poolstick . power <= 0 ){
poolstickAction ();
}
};
delete poolstick . onPress ;
};
}
function setMovementInterval (){
var movementinterval : Number = setInterval ( this , "checkMovement" , movetime );
}
function checkMovement (): Void {
if( poolstick ){
return;
}
for( i = 0 ; i <= 15 ; i ++){
if(eval( 'ball' + i ). xvel != 0 ||eval( 'ball' + i ). yvel != 0 ){
return;
}
}
if(! ball0 . onPress ){
showStick ();
}
}
newgame . onPress =function() {
if( ball0 ){
for( i = 0 ; i <= 15 ; i ++){
removeMovieClip ( 'ball' + i );
}
delete onEnterFrame ;
}
if( poolstick ){
removeMovieClip ( 'poolstick' );
}
newGame ();
};
function scratch2 (){
ball0 . startDrag ( true , tablearea . _x + ball0 . _width / 2 + spacer , tablearea . _y + ball0 . _height / 2 + spacer , tablearea . _x + tablearea . _width , tablearea . _y + tablearea . _height - ball0 . _height / 2 - spacer );
ball0 . xvel = 0 ;
ball0 . yvel = 0 ;
ball0 . onPress =function() {
a = this ;
for( j = 1 ; j <= 15 ; j ++){
b = this . _parent [ "ball" + j ];
var dx = b . _x - a . _x ;
var dy = b . _y - a . _y ;
var dist = Math . sqrt ( dx * dx + dy * dy );
if( dist < a . _width / 2 + b . _width / 2 ){
return;
}
}
ball0 . stopDrag ();
showStick ();
delete ball0 . onPress ;
};
}
Last edited by AS3.0; 02-22-2021 at 02:14 AM .
very good
it s working fine now
what about another modifications and improvements
thanks for help
can you return the white ball when it into the hole to start position ( like first time )
Client Software Programmer
ok
PHP Code:
var first_shot = 0
degreestoradians = Math . PI / 180 ;
ballssunk = 0 ;
spacer = .2 ;
powermultiplier = .5 ;
friction = .965 ;
movetime = 30 ;
Array. prototype . shuffle =function() {
for( i = 0 ; i < this . length ; i ++){
this . push ( this . splice ( Math . floor ( Math . random ()* this . length ), 1 ));
}
};
function newGame (){
first_shot = 0
rackx = tablearea . _x + tablearea . _width * .75 ;
racky = tablearea . _y + tablearea . _height / 2 ;
this . attachMovie ( 'balls' , 'ball8' , this . getNextHighestDepth (),{ _x : rackx , _y : racky });
ball8 . gotoAndStop ( 8 );
ball8 . xvel = 0 ;
ball8 . yvel = 0 ;
ball8 . sunk = 0 ;
ballArray =[ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 9 , 10 , 11 , 12 , 13 , 14 , 15 ];
ballArray . shuffle ();
horizdiff = Math . sqrt ( Math . pow ( ball8 . _width + spacer , 2 )- Math . pow (( ball8 . _height + spacer )/ 2 , 2 ));
ballcoords =[[ rackx - horizdiff * 2 , racky ],[ rackx - horizdiff , racky -( ball8 . _height + spacer )/ 2 ],[ rackx - horizdiff , racky +( ball8 . _height + spacer )/ 2 ],[ rackx , racky -( ball8 . _height + spacer )],[ rackx , racky +( ball8 . _height + spacer )],[ rackx + horizdiff , racky -( ball8 . _height + spacer )* 1.5 ],[ rackx + horizdiff , racky -( ball8 . _height + spacer )* .5 ],[ rackx + horizdiff , racky +( ball8 . _height + spacer )* .5 ],[ rackx + horizdiff , racky +( ball8 . _height + spacer )* 1.5 ],[ rackx + horizdiff * 2 , racky -( ball8 . _height + spacer )* 2 ],[ rackx + horizdiff * 2 , racky -( ball8 . _height + spacer )],[ rackx + horizdiff * 2 , racky ],[ rackx + horizdiff * 2 , racky +( ball8 . _height + spacer )],[ rackx + horizdiff * 2 , racky +( ball8 . _height + spacer )* 2 ]];
for( ballpos = 0 ; ballpos < 14 ; ballpos ++){
this . attachMovie ( 'balls' , 'ball' + ballArray [ ballpos ], this . getNextHighestDepth (),{ _x : ballcoords [ ballpos ][ 0 ], _y : ballcoords [ ballpos ][ 1 ]});
eval( 'ball' + ballArray [ ballpos ]). xvel = 0 ;
eval( 'ball' + ballArray [ ballpos ]). yvel = 0 ;
eval( 'ball' + ballArray [ ballpos ]). sunk = 0 ;
eval( 'ball' + ballArray [ ballpos ]). gotoAndStop ( ballArray [ ballpos ]);
}
this . attachMovie ( 'balls' , 'ball0' , this . getNextHighestDepth (),{ _x : tablearea . _x + tablearea . _width / 4 , _y : tablearea . _y + tablearea . _height / 2 });
ball0 . gotoAndStop ( 16 );
scratch ();
var ballinterval : Number = setInterval ( this , "moveBalls" , movetime );
}
function moveBalls (){
for( curball = 0 ; curball <= 15 ; curball ++){
if(eval( 'ball' + curball ). sunk ){
eval( 'ball' + curball ). _x = Math . min ( trayarea . _x + trayarea . _width -eval( 'ball' + curball ). _width / 2 -eval( 'ball' + curball ). _width *(eval( 'ball' + curball ). sunk - 1 )- spacer *(eval( 'ball' + curball ). sunk - 1 ),eval( 'ball' + curball ). _x + 5 );
}else {
eval( 'ball' + curball ). _x +=eval( 'ball' + curball ). xvel ;
eval( 'ball' + curball ). _y +=eval( 'ball' + curball ). yvel ;
eval( 'ball' + curball ). xvel *= friction ;
eval( 'ball' + curball ). yvel *= friction ;
if( Math . abs (eval( 'ball' + curball ). xvel )< .02 && Math . abs (eval( 'ball' + curball ). yvel )< .02 ){
eval( 'ball' + curball ). xvel = 0 ;
eval( 'ball' + curball ). yvel = 0 ;
}
if(eval( 'ball' + curball ). _x +eval( 'ball' + curball ). _width / 2 > tablearea . _x + tablearea . _width ){
if(eval( 'ball' + curball ). _y -eval( 'ball' + curball ). _height * .75 < tablearea . _y ||eval( 'ball' + curball ). _y +eval( 'ball' + curball ). _height * .75 > tablearea . _y + tablearea . _height ){
sinkBall ( curball );
}else {
eval( 'ball' + curball ). xvel *=- 1 ;
eval( 'ball' + curball ). _x -=(eval( 'ball' + curball ). _x +eval( 'ball' + curball ). _width / 2 -( tablearea . _x + tablearea . _width ));
}
}else if(eval( 'ball' + curball ). _x -eval( 'ball' + curball ). _width / 2 < tablearea . _x ){
if(eval( 'ball' + curball ). _y -eval( 'ball' + curball ). _height * .75 < tablearea . _y ||eval( 'ball' + curball ). _y +eval( 'ball' + curball ). _height * .75 > tablearea . _y + tablearea . _height ){
sinkBall ( curball );
}else {
eval( 'ball' + curball ). xvel *=- 1 ;
eval( 'ball' + curball ). _x -=(eval( 'ball' + curball ). _x -eval( 'ball' + curball ). _width / 2 )- tablearea . _x ;
}
}
if(eval( 'ball' + curball ). _y +eval( 'ball' + curball ). _height / 2 > tablearea . _y + tablearea . _height ){
if(eval( 'ball' + curball ). _x -eval( 'ball' + curball ). _width * .75 < tablearea . _x ||eval( 'ball' + curball ). _x +eval( 'ball' + curball ). _width * .75 > tablearea . _x + tablearea . _width ||(eval( 'ball' + curball ). _x -eval( 'ball' + curball ). _width * .75 < tablearea . _x + tablearea . _width / 2 &&eval( 'ball' + curball ). _x +eval( 'ball' + curball ). _width * .75 > tablearea . _x + tablearea . _width / 2 )){
sinkBall ( curball );
}else {
eval( 'ball' + curball ). yvel *=- 1 ;
eval( 'ball' + curball ). _y -=(eval( 'ball' + curball ). _y +eval( 'ball' + curball ). _height / 2 -( tablearea . _y + tablearea . _height ));
}
}else if(eval( 'ball' + curball ). _y -eval( 'ball' + curball ). _height / 2 < tablearea . _y ){
if(eval( 'ball' + curball ). _x -eval( 'ball' + curball ). _width * .75 < tablearea . _x ||eval( 'ball' + curball ). _x +eval( 'ball' + curball ). _width * .75 > tablearea . _x + tablearea . _width ||(eval( 'ball' + curball ). _x -eval( 'ball' + curball ). _width * .75 < tablearea . _x + tablearea . _width / 2 &&eval( 'ball' + curball ). _x +eval( 'ball' + curball ). _width * .75 > tablearea . _x + tablearea . _width / 2 )){
sinkBall ( curball );
}else {
eval( 'ball' + curball ). yvel *=- 1 ;
eval( 'ball' + curball ). _y -=(eval( 'ball' + curball ). _y -eval( 'ball' + curball ). _height / 2 )- tablearea . _y ;
}
}
}
}
if(! ball0 . onPress ){
for( i = 0 ; i <= 15 ; i ++){
a = this [ "ball" + i ];
for( j = i + 1 ; j <= 15 ; j ++){
b = this [ "ball" + j ];
var dx = b . _x - a . _x ;
var dy = b . _y - a . _y ;
var dist = Math . sqrt ( dx * dx + dy * dy );
if( dist < a . _width / 2 + b . _width / 2 ){
_root . solveBalls ( a , b );
}
}
}
}
};
function solveBalls ( ballA , ballB ){
var x1 = ballA . _x ;
var y1 = ballA . _y ;
var dx = ballB . _x - x1 ;
var dy = ballB . _y - y1 ;
var dist = Math . sqrt ( dx * dx + dy * dy );
radius = ballA . _width / 4 + ballB . _width / 4 ;
normalX = dx / dist ;
normalY = dy / dist ;
midpointX =( x1 + ballB . _x )/ 2 ;
midpointY =( y1 + ballB . _y )/ 2 ;
ballA . _x = midpointX - normalX * radius ;
ballA . _y = midpointY - normalY * radius ;
ballB . _x = midpointX + normalX * radius ;
ballB . _y = midpointY + normalY * radius ;
dVector =( ballA . xvel - ballB . xvel )* normalX +( ballA . yvel - ballB . yvel )* normalY ;
dvx = dVector * normalX ;
dvy = dVector * normalY ;
ballA . xvel -= dvx ;
ballA . yvel -= dvy ;
ballB . xvel += dvx ;
ballB . yvel += dvy ;
}
function sinkBall ( curball ){
if( curball == 0 ){
scratch2 ();
}else {
if(eval( 'ball' + curball ). sunk == 0 ){
eval( 'ball' + curball ). sunk =(++ ballssunk );
eval( 'ball' + curball ). xvel = 0 ;
eval( 'ball' + curball ). yvel = 0 ;
eval( 'ball' + curball ). _y = trayarea . _y + trayarea . _height / 2 ;
eval( 'ball' + curball ). _x = trayarea . _x +eval( 'ball' + curball ). _width / 2 ;
}
}
}
function scratch (){
if( first_shot == 0 ){
showStick ();
ball0 . _x = 170
ball0 . _y = 170
}else{
}
a = ball0 ;
for( j = 1 ; j <= 15 ; j ++){
b = this . _parent [ "ball" + j ];
var dx = b . _x - a . _x ;
var dy = b . _y - a . _y ;
var dist = Math . sqrt ( dx * dx + dy * dy );
if( dist < a . _width / 2 + b . _width / 2 ){
return;
}
}
ball0 . stopDrag ();
delete ball0 . onPress ;
};
function showStick (){
if( poolstick ){
delete poolstick ;
}
this . attachMovie ( 'poolstick' , 'poolstick' , this . getNextHighestDepth (),{ _x : ball0 . _x , _y : ball0 . _y });
poolstick . power = 0 ;
poolstick . curdist = 0 ;
poolstick . onEnterFrame =function() {
if( poolstick . _alpha == 100 ){
poolstick . _x = ball0 . _x ;
poolstick . _y = ball0 . _y ;
}
if( poolstick . onPress ){
stickangle = Math . atan (-( _ymouse - ball0 . _y )/( _xmouse - ball0 . _x ))/( Math . PI / 180 );
if(( _xmouse - ball0 . _x )< 0 ){
stickangle += 180 ;
}
if(( _xmouse - ball0 . _x )>= 0 &&(-( _ymouse - ball0 . _y ))< 0 ){
stickangle += 360 ;
}
if( first_shot == 0 ){
poolstick . _rotation = 90 ;
}else{
poolstick . _rotation =- stickangle - 90 ;
}
}else {
if( poolstick . onRelease ){
poolstick . power = Math . min ( 100 , Math . max ( 0 ,( Math . sqrt ( Math . pow ( _xmouse - ball0 . _x , 2 )+ Math . pow ( _ymouse - ball0 . _y , 2 ))- poolstick . clickdistance )));
poolstick . curdist = poolstick . power ;
}else {
poolstick . curdist = Math . max ( 0 , poolstick . curdist - 20 );
if( poolstick . curdist == 0 ){
if( poolstick . _alpha == 100 ){
ball0 . xvel = Math . sin ( poolstick . _rotation * degreestoradians )*( poolstick . power * powermultiplier );
ball0 . yvel =- Math . cos ( poolstick . _rotation * degreestoradians )*( poolstick . power * powermultiplier );
}
poolstick . _alpha -= 10 ;
first_shot ++
if( poolstick . _alpha <= 0 ){
setMovementInterval ();
removeMovieClip ( poolstick );
}
}
}
}
if( poolstick . _alpha == 100 ){
poolstick . _x +=- Math . sin ( degreestoradians * poolstick . _rotation )*( ball0 . _width / 2 + poolstick . curdist );
poolstick . _y += Math . cos ( degreestoradians * poolstick . _rotation )*( ball0 . _width / 2 + poolstick . curdist );
}
};
poolstickAction ();
}
function poolstickAction (){
poolstick . onPress =function() {
poolstick . clickdistance = Math . sqrt ( Math . pow ( _xmouse - ball0 . _x , 2 )+ Math . pow ( _ymouse - ball0 . _y , 2 ));
poolstick . onRelease = poolstick . onReleaseOutside =function (){
delete poolstick . onRelease ;
delete poolstick . onReleaseOutside ;
if( poolstick . power <= 0 ){
poolstickAction ();
}
};
delete poolstick . onPress ;
};
}
function setMovementInterval (){
var movementinterval : Number = setInterval ( this , "checkMovement" , movetime );
}
function checkMovement (): Void {
if( poolstick ){
return;
}
for( i = 0 ; i <= 15 ; i ++){
if(eval( 'ball' + i ). xvel != 0 ||eval( 'ball' + i ). yvel != 0 ){
return;
}
}
if(! ball0 . onPress ){
showStick ();
}
}
newgame . onPress =function() {
if( ball0 ){
for( i = 0 ; i <= 15 ; i ++){
removeMovieClip ( 'ball' + i );
}
delete onEnterFrame ;
}
if( poolstick ){
removeMovieClip ( 'poolstick' );
}
newGame ();
};
function scratch2 (){
//ball0.startDrag(true,tablearea._x+ball0._width/2+spacer,tablearea._y+ball0._height/2+spacer,tablearea._x+tablearea._width,tablearea._y+tablearea._height-ball0._height/2-spacer);
ball0 . xvel = 0 ;
ball0 . yvel = 0 ;
ball0 . _x = 170
ball0 . _y = 170
ball0 . onRelease =function() {
a = ball0 ;
for( j = 1 ; j <= 15 ; j ++){
b = this . _parent [ "ball" + j ];
var dx = b . _x - a . _x ;
var dy = b . _y - a . _y ;
var dist = Math . sqrt ( dx * dx + dy * dy );
if( dist < a . _width / 2 + b . _width / 2 ){
return;
}
}
ball0 . stopDrag ();
//showStick();
delete ball0 . onPress ;
};
}
thank you so much
you are a good man
Client Software Programmer
For number 3 the number of hits you need to make a text field called: score_text
PHP Code:
var first_shot = 0
degreestoradians = Math . PI / 180 ;
ballssunk = 0 ;
spacer = .2 ;
powermultiplier = .5 ;
friction = .965 ;
movetime = 30 ;
Array. prototype . shuffle =function() {
for( i = 0 ; i < this . length ; i ++){
this . push ( this . splice ( Math . floor ( Math . random ()* this . length ), 1 ));
}
};
function newGame (){
scores = 0
_root . score_text . text = "score: " + scores
first_shot = 0
rackx = tablearea . _x + tablearea . _width * .75 ;
racky = tablearea . _y + tablearea . _height / 2 ;
this . attachMovie ( 'balls' , 'ball8' , this . getNextHighestDepth (),{ _x : rackx , _y : racky });
ball8 . gotoAndStop ( 8 );
ball8 . xvel = 0 ;
ball8 . yvel = 0 ;
ball8 . sunk = 0 ;
ballArray =[ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 9 , 10 , 11 , 12 , 13 , 14 , 15 ];
ballArray . shuffle ();
horizdiff = Math . sqrt ( Math . pow ( ball8 . _width + spacer , 2 )- Math . pow (( ball8 . _height + spacer )/ 2 , 2 ));
ballcoords =[[ rackx - horizdiff * 2 , racky ],[ rackx - horizdiff , racky -( ball8 . _height + spacer )/ 2 ],[ rackx - horizdiff , racky +( ball8 . _height + spacer )/ 2 ],[ rackx , racky -( ball8 . _height + spacer )],[ rackx , racky +( ball8 . _height + spacer )],[ rackx + horizdiff , racky -( ball8 . _height + spacer )* 1.5 ],[ rackx + horizdiff , racky -( ball8 . _height + spacer )* .5 ],[ rackx + horizdiff , racky +( ball8 . _height + spacer )* .5 ],[ rackx + horizdiff , racky +( ball8 . _height + spacer )* 1.5 ],[ rackx + horizdiff * 2 , racky -( ball8 . _height + spacer )* 2 ],[ rackx + horizdiff * 2 , racky -( ball8 . _height + spacer )],[ rackx + horizdiff * 2 , racky ],[ rackx + horizdiff * 2 , racky +( ball8 . _height + spacer )],[ rackx + horizdiff * 2 , racky +( ball8 . _height + spacer )* 2 ]];
for( ballpos = 0 ; ballpos < 14 ; ballpos ++){
this . attachMovie ( 'balls' , 'ball' + ballArray [ ballpos ], this . getNextHighestDepth (),{ _x : ballcoords [ ballpos ][ 0 ], _y : ballcoords [ ballpos ][ 1 ]});
eval( 'ball' + ballArray [ ballpos ]). xvel = 0 ;
eval( 'ball' + ballArray [ ballpos ]). yvel = 0 ;
eval( 'ball' + ballArray [ ballpos ]). sunk = 0 ;
eval( 'ball' + ballArray [ ballpos ]). gotoAndStop ( ballArray [ ballpos ]);
}
this . attachMovie ( 'balls' , 'ball0' , this . getNextHighestDepth (),{ _x : tablearea . _x + tablearea . _width / 4 , _y : tablearea . _y + tablearea . _height / 2 });
ball0 . gotoAndStop ( 16 );
scratch ();
var ballinterval : Number = setInterval ( this , "moveBalls" , movetime );
}
function moveBalls (){
for( curball = 0 ; curball <= 15 ; curball ++){
if(eval( 'ball' + curball ). sunk ){
eval( 'ball' + curball ). _x = Math . min ( trayarea . _x + trayarea . _width -eval( 'ball' + curball ). _width / 2 -eval( 'ball' + curball ). _width *(eval( 'ball' + curball ). sunk - 1 )- spacer *(eval( 'ball' + curball ). sunk - 1 ),eval( 'ball' + curball ). _x + 5 );
}else {
eval( 'ball' + curball ). _x +=eval( 'ball' + curball ). xvel ;
eval( 'ball' + curball ). _y +=eval( 'ball' + curball ). yvel ;
eval( 'ball' + curball ). xvel *= friction ;
eval( 'ball' + curball ). yvel *= friction ;
if( Math . abs (eval( 'ball' + curball ). xvel )< .02 && Math . abs (eval( 'ball' + curball ). yvel )< .02 ){
eval( 'ball' + curball ). xvel = 0 ;
eval( 'ball' + curball ). yvel = 0 ;
}
if(eval( 'ball' + curball ). _x +eval( 'ball' + curball ). _width / 2 > tablearea . _x + tablearea . _width ){
if(eval( 'ball' + curball ). _y -eval( 'ball' + curball ). _height * .75 < tablearea . _y ||eval( 'ball' + curball ). _y +eval( 'ball' + curball ). _height * .75 > tablearea . _y + tablearea . _height ){
sinkBall ( curball );
}else {
eval( 'ball' + curball ). xvel *=- 1 ;
eval( 'ball' + curball ). _x -=(eval( 'ball' + curball ). _x +eval( 'ball' + curball ). _width / 2 -( tablearea . _x + tablearea . _width ));
}
}else if(eval( 'ball' + curball ). _x -eval( 'ball' + curball ). _width / 2 < tablearea . _x ){
if(eval( 'ball' + curball ). _y -eval( 'ball' + curball ). _height * .75 < tablearea . _y ||eval( 'ball' + curball ). _y +eval( 'ball' + curball ). _height * .75 > tablearea . _y + tablearea . _height ){
sinkBall ( curball );
}else {
eval( 'ball' + curball ). xvel *=- 1 ;
eval( 'ball' + curball ). _x -=(eval( 'ball' + curball ). _x -eval( 'ball' + curball ). _width / 2 )- tablearea . _x ;
}
}
if(eval( 'ball' + curball ). _y +eval( 'ball' + curball ). _height / 2 > tablearea . _y + tablearea . _height ){
if(eval( 'ball' + curball ). _x -eval( 'ball' + curball ). _width * .75 < tablearea . _x ||eval( 'ball' + curball ). _x +eval( 'ball' + curball ). _width * .75 > tablearea . _x + tablearea . _width ||(eval( 'ball' + curball ). _x -eval( 'ball' + curball ). _width * .75 < tablearea . _x + tablearea . _width / 2 &&eval( 'ball' + curball ). _x +eval( 'ball' + curball ). _width * .75 > tablearea . _x + tablearea . _width / 2 )){
sinkBall ( curball );
}else {
eval( 'ball' + curball ). yvel *=- 1 ;
eval( 'ball' + curball ). _y -=(eval( 'ball' + curball ). _y +eval( 'ball' + curball ). _height / 2 -( tablearea . _y + tablearea . _height ));
}
}else if(eval( 'ball' + curball ). _y -eval( 'ball' + curball ). _height / 2 < tablearea . _y ){
if(eval( 'ball' + curball ). _x -eval( 'ball' + curball ). _width * .75 < tablearea . _x ||eval( 'ball' + curball ). _x +eval( 'ball' + curball ). _width * .75 > tablearea . _x + tablearea . _width ||(eval( 'ball' + curball ). _x -eval( 'ball' + curball ). _width * .75 < tablearea . _x + tablearea . _width / 2 &&eval( 'ball' + curball ). _x +eval( 'ball' + curball ). _width * .75 > tablearea . _x + tablearea . _width / 2 )){
sinkBall ( curball );
}else {
eval( 'ball' + curball ). yvel *=- 1 ;
eval( 'ball' + curball ). _y -=(eval( 'ball' + curball ). _y -eval( 'ball' + curball ). _height / 2 )- tablearea . _y ;
}
}
}
}
if(! ball0 . onPress ){
for( i = 0 ; i <= 15 ; i ++){
a = this [ "ball" + i ];
for( j = i + 1 ; j <= 15 ; j ++){
b = this [ "ball" + j ];
var dx = b . _x - a . _x ;
var dy = b . _y - a . _y ;
var dist = Math . sqrt ( dx * dx + dy * dy );
if( dist < a . _width / 2 + b . _width / 2 ){
_root . solveBalls ( a , b );
}
}
}
}
};
function solveBalls ( ballA , ballB ){
var x1 = ballA . _x ;
var y1 = ballA . _y ;
var dx = ballB . _x - x1 ;
var dy = ballB . _y - y1 ;
var dist = Math . sqrt ( dx * dx + dy * dy );
radius = ballA . _width / 4 + ballB . _width / 4 ;
normalX = dx / dist ;
normalY = dy / dist ;
midpointX =( x1 + ballB . _x )/ 2 ;
midpointY =( y1 + ballB . _y )/ 2 ;
ballA . _x = midpointX - normalX * radius ;
ballA . _y = midpointY - normalY * radius ;
ballB . _x = midpointX + normalX * radius ;
ballB . _y = midpointY + normalY * radius ;
dVector =( ballA . xvel - ballB . xvel )* normalX +( ballA . yvel - ballB . yvel )* normalY ;
dvx = dVector * normalX ;
dvy = dVector * normalY ;
ballA . xvel -= dvx ;
ballA . yvel -= dvy ;
ballB . xvel += dvx ;
ballB . yvel += dvy ;
}
var scores = 0
var misses = 0 ;
function sinkBall ( curball ){
if( curball == 0 ){
scratch2 ();
}else {
if(eval( 'ball' + curball ). sunk == 0 ){
scores ++
trace ( "scores: " + scores )
_root . score_text . text = "score: " + scores
eval( 'ball' + curball ). sunk =(++ ballssunk );
eval( 'ball' + curball ). xvel = 0 ;
eval( 'ball' + curball ). yvel = 0 ;
eval( 'ball' + curball ). _y = trayarea . _y + trayarea . _height / 2 ;
eval( 'ball' + curball ). _x = trayarea . _x +eval( 'ball' + curball ). _width / 2 ;
}
}
}
function scratch (){
if( first_shot == 0 ){
showStick ();
ball0 . _x = 170
ball0 . _y = 170
}else{
}
a = ball0 ;
for( j = 1 ; j <= 15 ; j ++){
b = this . _parent [ "ball" + j ];
var dx = b . _x - a . _x ;
var dy = b . _y - a . _y ;
var dist = Math . sqrt ( dx * dx + dy * dy );
if( dist < a . _width / 2 + b . _width / 2 ){
return;
}
}
ball0 . stopDrag ();
delete ball0 . onPress ;
};
function showStick (){
if( poolstick ){
delete poolstick ;
}
this . attachMovie ( 'poolstick' , 'poolstick' , this . getNextHighestDepth (),{ _x : ball0 . _x , _y : ball0 . _y });
poolstick . power = 0 ;
poolstick . curdist = 0 ;
poolstick . onEnterFrame =function() {
if( poolstick . _alpha == 100 ){
poolstick . _x = ball0 . _x ;
poolstick . _y = ball0 . _y ;
}
if( poolstick . onPress ){
stickangle = Math . atan (-( _ymouse - ball0 . _y )/( _xmouse - ball0 . _x ))/( Math . PI / 180 );
if(( _xmouse - ball0 . _x )< 0 ){
stickangle += 180 ;
}
if(( _xmouse - ball0 . _x )>= 0 &&(-( _ymouse - ball0 . _y ))< 0 ){
stickangle += 360 ;
}
if( first_shot == 0 ){
poolstick . _rotation = 90 ;
}else{
poolstick . _rotation =- stickangle - 90 ;
}
}else {
if( poolstick . onRelease ){
poolstick . power = Math . min ( 100 , Math . max ( 0 ,( Math . sqrt ( Math . pow ( _xmouse - ball0 . _x , 2 )+ Math . pow ( _ymouse - ball0 . _y , 2 ))- poolstick . clickdistance )));
poolstick . curdist = poolstick . power ;
}else {
poolstick . curdist = Math . max ( 0 , poolstick . curdist - 20 );
if( poolstick . curdist == 0 ){
if( poolstick . _alpha == 100 ){
ball0 . xvel = Math . sin ( poolstick . _rotation * degreestoradians )*( poolstick . power * powermultiplier );
ball0 . yvel =- Math . cos ( poolstick . _rotation * degreestoradians )*( poolstick . power * powermultiplier );
}
poolstick . _alpha -= 10 ;
first_shot ++
if( poolstick . _alpha <= 0 ){
setMovementInterval ();
removeMovieClip ( poolstick );
}
}
}
}
if( poolstick . _alpha == 100 ){
poolstick . _x +=- Math . sin ( degreestoradians * poolstick . _rotation )*( ball0 . _width / 2 + poolstick . curdist );
poolstick . _y += Math . cos ( degreestoradians * poolstick . _rotation )*( ball0 . _width / 2 + poolstick . curdist );
}
};
poolstickAction ();
}
function poolstickAction (){
poolstick . onPress =function() {
poolstick . clickdistance = Math . sqrt ( Math . pow ( _xmouse - ball0 . _x , 2 )+ Math . pow ( _ymouse - ball0 . _y , 2 ));
poolstick . onRelease = poolstick . onReleaseOutside =function (){
delete poolstick . onRelease ;
delete poolstick . onReleaseOutside ;
if( poolstick . power <= 0 ){
poolstickAction ();
}
};
delete poolstick . onPress ;
};
}
function setMovementInterval (){
var movementinterval : Number = setInterval ( this , "checkMovement" , movetime );
}
function checkMovement (): Void {
if( poolstick ){
return;
}
for( i = 0 ; i <= 15 ; i ++){
if(eval( 'ball' + i ). xvel != 0 ||eval( 'ball' + i ). yvel != 0 ){
return;
}
}
if(! ball0 . onPress ){
showStick ();
}
}
newgame . onPress =function() {
if( ball0 ){
for( i = 0 ; i <= 15 ; i ++){
removeMovieClip ( 'ball' + i );
}
delete onEnterFrame ;
}
if( poolstick ){
removeMovieClip ( 'poolstick' );
}
newGame ();
};
function scratch2 (){
//ball0.startDrag(true,tablearea._x+ball0._width/2+spacer,tablearea._y+ball0._height/2+spacer,tablearea._x+tablearea._width,tablearea._y+tablearea._height-ball0._height/2-spacer);
ball0 . xvel = 0 ;
ball0 . yvel = 0 ;
ball0 . _x = 170
ball0 . _y = 170
ball0 . onRelease =function() {
a = ball0 ;
for( j = 1 ; j <= 15 ; j ++){
b = this . _parent [ "ball" + j ];
var dx = b . _x - a . _x ;
var dy = b . _y - a . _y ;
var dist = Math . sqrt ( dx * dx + dy * dy );
if( dist < a . _width / 2 + b . _width / 2 ){
return;
}
}
ball0 . stopDrag ();
//showStick();
delete ball0 . onPress ;
};
}
Client Software Programmer
For number 3 the number of hits you need to make a text field called: score_text
For number 3 the number of misses you need to make a text field called: misses_text
PHP Code:
var first_shot = 0
degreestoradians = Math . PI / 180 ;
ballssunk = 0 ;
spacer = .2 ;
powermultiplier = .5 ;
friction = .965 ;
movetime = 30 ;
Array. prototype . shuffle =function() {
for( i = 0 ; i < this . length ; i ++){
this . push ( this . splice ( Math . floor ( Math . random ()* this . length ), 1 ));
}
};
var scores = 0
var misses = 0 ;
function newGame (){
scores = 0
misses = 0
_root . score_text . text = "score: " + scores
_root . misses_text . text = "misses: " + misses
first_shot = 0
rackx = tablearea . _x + tablearea . _width * .75 ;
racky = tablearea . _y + tablearea . _height / 2 ;
this . attachMovie ( 'balls' , 'ball8' , this . getNextHighestDepth (),{ _x : rackx , _y : racky });
ball8 . gotoAndStop ( 8 );
ball8 . xvel = 0 ;
ball8 . yvel = 0 ;
ball8 . sunk = 0 ;
ballArray =[ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 9 , 10 , 11 , 12 , 13 , 14 , 15 ];
ballArray . shuffle ();
horizdiff = Math . sqrt ( Math . pow ( ball8 . _width + spacer , 2 )- Math . pow (( ball8 . _height + spacer )/ 2 , 2 ));
ballcoords =[[ rackx - horizdiff * 2 , racky ],[ rackx - horizdiff , racky -( ball8 . _height + spacer )/ 2 ],[ rackx - horizdiff , racky +( ball8 . _height + spacer )/ 2 ],[ rackx , racky -( ball8 . _height + spacer )],[ rackx , racky +( ball8 . _height + spacer )],[ rackx + horizdiff , racky -( ball8 . _height + spacer )* 1.5 ],[ rackx + horizdiff , racky -( ball8 . _height + spacer )* .5 ],[ rackx + horizdiff , racky +( ball8 . _height + spacer )* .5 ],[ rackx + horizdiff , racky +( ball8 . _height + spacer )* 1.5 ],[ rackx + horizdiff * 2 , racky -( ball8 . _height + spacer )* 2 ],[ rackx + horizdiff * 2 , racky -( ball8 . _height + spacer )],[ rackx + horizdiff * 2 , racky ],[ rackx + horizdiff * 2 , racky +( ball8 . _height + spacer )],[ rackx + horizdiff * 2 , racky +( ball8 . _height + spacer )* 2 ]];
for( ballpos = 0 ; ballpos < 14 ; ballpos ++){
this . attachMovie ( 'balls' , 'ball' + ballArray [ ballpos ], this . getNextHighestDepth (),{ _x : ballcoords [ ballpos ][ 0 ], _y : ballcoords [ ballpos ][ 1 ]});
eval( 'ball' + ballArray [ ballpos ]). xvel = 0 ;
eval( 'ball' + ballArray [ ballpos ]). yvel = 0 ;
eval( 'ball' + ballArray [ ballpos ]). sunk = 0 ;
eval( 'ball' + ballArray [ ballpos ]). gotoAndStop ( ballArray [ ballpos ]);
}
this . attachMovie ( 'balls' , 'ball0' , this . getNextHighestDepth (),{ _x : tablearea . _x + tablearea . _width / 4 , _y : tablearea . _y + tablearea . _height / 2 });
ball0 . gotoAndStop ( 16 );
scratch ();
var ballinterval : Number = setInterval ( this , "moveBalls" , movetime );
}
function moveBalls (){
for( curball = 0 ; curball <= 15 ; curball ++){
if(eval( 'ball' + curball ). sunk ){
eval( 'ball' + curball ). _x = Math . min ( trayarea . _x + trayarea . _width -eval( 'ball' + curball ). _width / 2 -eval( 'ball' + curball ). _width *(eval( 'ball' + curball ). sunk - 1 )- spacer *(eval( 'ball' + curball ). sunk - 1 ),eval( 'ball' + curball ). _x + 5 );
}else {
eval( 'ball' + curball ). _x +=eval( 'ball' + curball ). xvel ;
eval( 'ball' + curball ). _y +=eval( 'ball' + curball ). yvel ;
eval( 'ball' + curball ). xvel *= friction ;
eval( 'ball' + curball ). yvel *= friction ;
if( Math . abs (eval( 'ball' + curball ). xvel )< .02 && Math . abs (eval( 'ball' + curball ). yvel )< .02 ){
eval( 'ball' + curball ). xvel = 0 ;
eval( 'ball' + curball ). yvel = 0 ;
}
if(eval( 'ball' + curball ). _x +eval( 'ball' + curball ). _width / 2 > tablearea . _x + tablearea . _width ){
if(eval( 'ball' + curball ). _y -eval( 'ball' + curball ). _height * .75 < tablearea . _y ||eval( 'ball' + curball ). _y +eval( 'ball' + curball ). _height * .75 > tablearea . _y + tablearea . _height ){
sinkBall ( curball );
}else {
eval( 'ball' + curball ). xvel *=- 1 ;
eval( 'ball' + curball ). _x -=(eval( 'ball' + curball ). _x +eval( 'ball' + curball ). _width / 2 -( tablearea . _x + tablearea . _width ));
}
}else if(eval( 'ball' + curball ). _x -eval( 'ball' + curball ). _width / 2 < tablearea . _x ){
if(eval( 'ball' + curball ). _y -eval( 'ball' + curball ). _height * .75 < tablearea . _y ||eval( 'ball' + curball ). _y +eval( 'ball' + curball ). _height * .75 > tablearea . _y + tablearea . _height ){
sinkBall ( curball );
}else {
eval( 'ball' + curball ). xvel *=- 1 ;
eval( 'ball' + curball ). _x -=(eval( 'ball' + curball ). _x -eval( 'ball' + curball ). _width / 2 )- tablearea . _x ;
}
}
if(eval( 'ball' + curball ). _y +eval( 'ball' + curball ). _height / 2 > tablearea . _y + tablearea . _height ){
if(eval( 'ball' + curball ). _x -eval( 'ball' + curball ). _width * .75 < tablearea . _x ||eval( 'ball' + curball ). _x +eval( 'ball' + curball ). _width * .75 > tablearea . _x + tablearea . _width ||(eval( 'ball' + curball ). _x -eval( 'ball' + curball ). _width * .75 < tablearea . _x + tablearea . _width / 2 &&eval( 'ball' + curball ). _x +eval( 'ball' + curball ). _width * .75 > tablearea . _x + tablearea . _width / 2 )){
sinkBall ( curball );
}else {
eval( 'ball' + curball ). yvel *=- 1 ;
eval( 'ball' + curball ). _y -=(eval( 'ball' + curball ). _y +eval( 'ball' + curball ). _height / 2 -( tablearea . _y + tablearea . _height ));
}
}else if(eval( 'ball' + curball ). _y -eval( 'ball' + curball ). _height / 2 < tablearea . _y ){
if(eval( 'ball' + curball ). _x -eval( 'ball' + curball ). _width * .75 < tablearea . _x ||eval( 'ball' + curball ). _x +eval( 'ball' + curball ). _width * .75 > tablearea . _x + tablearea . _width ||(eval( 'ball' + curball ). _x -eval( 'ball' + curball ). _width * .75 < tablearea . _x + tablearea . _width / 2 &&eval( 'ball' + curball ). _x +eval( 'ball' + curball ). _width * .75 > tablearea . _x + tablearea . _width / 2 )){
sinkBall ( curball );
}else {
eval( 'ball' + curball ). yvel *=- 1 ;
eval( 'ball' + curball ). _y -=(eval( 'ball' + curball ). _y -eval( 'ball' + curball ). _height / 2 )- tablearea . _y ;
}
}
}
}
if(! ball0 . onPress ){
for( i = 0 ; i <= 15 ; i ++){
a = this [ "ball" + i ];
for( j = i + 1 ; j <= 15 ; j ++){
b = this [ "ball" + j ];
var dx = b . _x - a . _x ;
var dy = b . _y - a . _y ;
var dist = Math . sqrt ( dx * dx + dy * dy );
if( dist < a . _width / 2 + b . _width / 2 ){
_root . solveBalls ( a , b );
}
}
}
}
};
function solveBalls ( ballA , ballB ){
var x1 = ballA . _x ;
var y1 = ballA . _y ;
var dx = ballB . _x - x1 ;
var dy = ballB . _y - y1 ;
var dist = Math . sqrt ( dx * dx + dy * dy );
radius = ballA . _width / 4 + ballB . _width / 4 ;
normalX = dx / dist ;
normalY = dy / dist ;
midpointX =( x1 + ballB . _x )/ 2 ;
midpointY =( y1 + ballB . _y )/ 2 ;
ballA . _x = midpointX - normalX * radius ;
ballA . _y = midpointY - normalY * radius ;
ballB . _x = midpointX + normalX * radius ;
ballB . _y = midpointY + normalY * radius ;
dVector =( ballA . xvel - ballB . xvel )* normalX +( ballA . yvel - ballB . yvel )* normalY ;
dvx = dVector * normalX ;
dvy = dVector * normalY ;
ballA . xvel -= dvx ;
ballA . yvel -= dvy ;
ballB . xvel += dvx ;
ballB . yvel += dvy ;
}
function sinkBall ( curball ){
if( curball == 0 ){
scratch2 ();
}else {
if(eval( 'ball' + curball ). sunk == 0 ){
scores ++
trace ( "scores: " + scores )
_root . score_text . text = "score: " + scores
eval( 'ball' + curball ). sunk =(++ ballssunk );
eval( 'ball' + curball ). xvel = 0 ;
eval( 'ball' + curball ). yvel = 0 ;
eval( 'ball' + curball ). _y = trayarea . _y + trayarea . _height / 2 ;
eval( 'ball' + curball ). _x = trayarea . _x +eval( 'ball' + curball ). _width / 2 ;
}
}
}
function scratch (){
if( first_shot == 0 ){
showStick ();
ball0 . _x = 170
ball0 . _y = 170
}else{
}
a = ball0 ;
for( j = 1 ; j <= 15 ; j ++){
b = this . _parent [ "ball" + j ];
var dx = b . _x - a . _x ;
var dy = b . _y - a . _y ;
var dist = Math . sqrt ( dx * dx + dy * dy );
if( dist < a . _width / 2 + b . _width / 2 ){
return;
}
}
ball0 . stopDrag ();
delete ball0 . onPress ;
};
function showStick (){
if( poolstick ){
delete poolstick ;
}
this . attachMovie ( 'poolstick' , 'poolstick' , this . getNextHighestDepth (),{ _x : ball0 . _x , _y : ball0 . _y });
poolstick . power = 0 ;
poolstick . curdist = 0 ;
poolstick . onEnterFrame =function() {
if( poolstick . _alpha == 100 ){
poolstick . _x = ball0 . _x ;
poolstick . _y = ball0 . _y ;
}
if( poolstick . onPress ){
stickangle = Math . atan (-( _ymouse - ball0 . _y )/( _xmouse - ball0 . _x ))/( Math . PI / 180 );
if(( _xmouse - ball0 . _x )< 0 ){
stickangle += 180 ;
}
if(( _xmouse - ball0 . _x )>= 0 &&(-( _ymouse - ball0 . _y ))< 0 ){
stickangle += 360 ;
}
if( first_shot == 0 ){
poolstick . _rotation = 90 ;
}else{
poolstick . _rotation =- stickangle - 90 ;
}
}else {
if( poolstick . onRelease ){
poolstick . power = Math . min ( 100 , Math . max ( 0 ,( Math . sqrt ( Math . pow ( _xmouse - ball0 . _x , 2 )+ Math . pow ( _ymouse - ball0 . _y , 2 ))- poolstick . clickdistance )));
poolstick . curdist = poolstick . power ;
}else {
poolstick . curdist = Math . max ( 0 , poolstick . curdist - 20 );
if( poolstick . curdist == 0 ){
if( poolstick . _alpha == 100 ){
ball0 . xvel = Math . sin ( poolstick . _rotation * degreestoradians )*( poolstick . power * powermultiplier );
ball0 . yvel =- Math . cos ( poolstick . _rotation * degreestoradians )*( poolstick . power * powermultiplier );
}
poolstick . _alpha -= 10 ;
first_shot ++
if( poolstick . _alpha <= 0 ){
setMovementInterval ();
removeMovieClip ( poolstick );
}
}
}
}
if( poolstick . _alpha == 100 ){
poolstick . _x +=- Math . sin ( degreestoradians * poolstick . _rotation )*( ball0 . _width / 2 + poolstick . curdist );
poolstick . _y += Math . cos ( degreestoradians * poolstick . _rotation )*( ball0 . _width / 2 + poolstick . curdist );
}
};
poolstickAction ();
}
var wait_score = 0 ;
function poolstickAction (){
poolstick . onPress =function() {
poolstick . clickdistance = Math . sqrt ( Math . pow ( _xmouse - ball0 . _x , 2 )+ Math . pow ( _ymouse - ball0 . _y , 2 ));
poolstick . onRelease = poolstick . onReleaseOutside =function (){
delete poolstick . onRelease ;
delete poolstick . onReleaseOutside ;
if( poolstick . power <= 0 ){
poolstickAction ();
}else{
wait_score = scores ;
trace ( "started wait" )
}
};
delete poolstick . onPress ;
};
}
function setMovementInterval (){
var movementinterval : Number = setInterval ( this , "checkMovement" , movetime );
}
function checkMovement (): Void {
if( poolstick ){
return;
}
for( i = 0 ; i <= 15 ; i ++){
if(eval( 'ball' + i ). xvel != 0 ||eval( 'ball' + i ). yvel != 0 ){
return;
}
}
if(! ball0 . onPress ){
showStick ();
if( wait_score == scores ){
misses ++
trace ( "misses: " + misses )
misses_text . text = "misses: " + misses
}
}
}
newgame . onPress =function() {
if( ball0 ){
for( i = 0 ; i <= 15 ; i ++){
removeMovieClip ( 'ball' + i );
}
delete onEnterFrame ;
}
if( poolstick ){
removeMovieClip ( 'poolstick' );
}
newGame ();
};
function scratch2 (){
//ball0.startDrag(true,tablearea._x+ball0._width/2+spacer,tablearea._y+ball0._height/2+spacer,tablearea._x+tablearea._width,tablearea._y+tablearea._height-ball0._height/2-spacer);
ball0 . xvel = 0 ;
ball0 . yvel = 0 ;
ball0 . _x = 170
ball0 . _y = 170
ball0 . onRelease =function() {
a = ball0 ;
for( j = 1 ; j <= 15 ; j ++){
b = this . _parent [ "ball" + j ];
var dx = b . _x - a . _x ;
var dy = b . _y - a . _y ;
var dist = Math . sqrt ( dx * dx + dy * dy );
if( dist < a . _width / 2 + b . _width / 2 ){
return;
}
}
ball0 . stopDrag ();
//showStick();
delete ball0 . onPress ;
};
}
Client Software Programmer
For number 4 you need to make a text field called: game_over
line 145 and line 155 say scores<15 and score==15 is when the game end text appears.
PHP Code:
var first_shot = 0
degreestoradians = Math . PI / 180 ;
ballssunk = 0 ;
spacer = .2 ;
powermultiplier = .5 ;
friction = .965 ;
movetime = 30 ;
Array. prototype . shuffle =function() {
for( i = 0 ; i < this . length ; i ++){
this . push ( this . splice ( Math . floor ( Math . random ()* this . length ), 1 ));
}
};
var interv = null
var scores = 0
var misses = 0 ;
var ballinterval
game_over . text = ""
function newGame (){
game_over . text = ""
clearTimeout ( interv )
scores = 0
misses = 0
ballssunk = 0 ;
spacer = .2 ;
powermultiplier = .5 ;
friction = .965 ;
movetime = 30 ;
_root . score_text . text = "score: " + scores
_root . misses_text . text = "misses: " + misses
first_shot = 0
rackx = tablearea . _x + tablearea . _width * .75 ;
racky = tablearea . _y + tablearea . _height / 2 ;
this . attachMovie ( 'balls' , 'ball8' , this . getNextHighestDepth (),{ _x : rackx , _y : racky });
ball8 . gotoAndStop ( 8 );
ball8 . xvel = 0 ;
ball8 . yvel = 0 ;
ball8 . sunk = 0 ;
ballArray =[ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 9 , 10 , 11 , 12 , 13 , 14 , 15 ];
ballArray . shuffle ();
horizdiff = Math . sqrt ( Math . pow ( ball8 . _width + spacer , 2 )- Math . pow (( ball8 . _height + spacer )/ 2 , 2 ));
ballcoords =[[ rackx - horizdiff * 2 , racky ],[ rackx - horizdiff , racky -( ball8 . _height + spacer )/ 2 ],[ rackx - horizdiff , racky +( ball8 . _height + spacer )/ 2 ],[ rackx , racky -( ball8 . _height + spacer )],[ rackx , racky +( ball8 . _height + spacer )],[ rackx + horizdiff , racky -( ball8 . _height + spacer )* 1.5 ],[ rackx + horizdiff , racky -( ball8 . _height + spacer )* .5 ],[ rackx + horizdiff , racky +( ball8 . _height + spacer )* .5 ],[ rackx + horizdiff , racky +( ball8 . _height + spacer )* 1.5 ],[ rackx + horizdiff * 2 , racky -( ball8 . _height + spacer )* 2 ],[ rackx + horizdiff * 2 , racky -( ball8 . _height + spacer )],[ rackx + horizdiff * 2 , racky ],[ rackx + horizdiff * 2 , racky +( ball8 . _height + spacer )],[ rackx + horizdiff * 2 , racky +( ball8 . _height + spacer )* 2 ]];
for( ballpos = 0 ; ballpos < 14 ; ballpos ++){
this . attachMovie ( 'balls' , 'ball' + ballArray [ ballpos ], this . getNextHighestDepth (),{ _x : ballcoords [ ballpos ][ 0 ], _y : ballcoords [ ballpos ][ 1 ]});
eval( 'ball' + ballArray [ ballpos ]). xvel = 0 ;
eval( 'ball' + ballArray [ ballpos ]). yvel = 0 ;
eval( 'ball' + ballArray [ ballpos ]). sunk = 0 ;
eval( 'ball' + ballArray [ ballpos ]). gotoAndStop ( ballArray [ ballpos ]);
}
this . attachMovie ( 'balls' , 'ball0' , this . getNextHighestDepth (),{ _x : tablearea . _x + tablearea . _width / 4 , _y : tablearea . _y + tablearea . _height / 2 });
ball0 . gotoAndStop ( 16 );
scratch ();
interv = ballinterval = setInterval ( this , "moveBalls" , movetime );
}
function moveBalls (){
for( curball = 0 ; curball <= 15 ; curball ++){
if(eval( 'ball' + curball ). sunk ){
eval( 'ball' + curball ). _x = Math . min ( trayarea . _x + trayarea . _width -eval( 'ball' + curball ). _width / 2 -eval( 'ball' + curball ). _width *(eval( 'ball' + curball ). sunk - 1 )- spacer *(eval( 'ball' + curball ). sunk - 1 ),eval( 'ball' + curball ). _x + 5 );
}else {
eval( 'ball' + curball ). _x +=eval( 'ball' + curball ). xvel ;
eval( 'ball' + curball ). _y +=eval( 'ball' + curball ). yvel ;
eval( 'ball' + curball ). xvel *= friction ;
eval( 'ball' + curball ). yvel *= friction ;
if( Math . abs (eval( 'ball' + curball ). xvel )< .02 && Math . abs (eval( 'ball' + curball ). yvel )< .02 ){
eval( 'ball' + curball ). xvel = 0 ;
eval( 'ball' + curball ). yvel = 0 ;
}
if(eval( 'ball' + curball ). _x +eval( 'ball' + curball ). _width / 2 > tablearea . _x + tablearea . _width ){
if(eval( 'ball' + curball ). _y -eval( 'ball' + curball ). _height * .75 < tablearea . _y ||eval( 'ball' + curball ). _y +eval( 'ball' + curball ). _height * .75 > tablearea . _y + tablearea . _height ){
sinkBall ( curball );
}else {
eval( 'ball' + curball ). xvel *=- 1 ;
eval( 'ball' + curball ). _x -=(eval( 'ball' + curball ). _x +eval( 'ball' + curball ). _width / 2 -( tablearea . _x + tablearea . _width ));
}
}else if(eval( 'ball' + curball ). _x -eval( 'ball' + curball ). _width / 2 < tablearea . _x ){
if(eval( 'ball' + curball ). _y -eval( 'ball' + curball ). _height * .75 < tablearea . _y ||eval( 'ball' + curball ). _y +eval( 'ball' + curball ). _height * .75 > tablearea . _y + tablearea . _height ){
sinkBall ( curball );
}else {
eval( 'ball' + curball ). xvel *=- 1 ;
eval( 'ball' + curball ). _x -=(eval( 'ball' + curball ). _x -eval( 'ball' + curball ). _width / 2 )- tablearea . _x ;
}
}
if(eval( 'ball' + curball ). _y +eval( 'ball' + curball ). _height / 2 > tablearea . _y + tablearea . _height ){
if(eval( 'ball' + curball ). _x -eval( 'ball' + curball ). _width * .75 < tablearea . _x ||eval( 'ball' + curball ). _x +eval( 'ball' + curball ). _width * .75 > tablearea . _x + tablearea . _width ||(eval( 'ball' + curball ). _x -eval( 'ball' + curball ). _width * .75 < tablearea . _x + tablearea . _width / 2 &&eval( 'ball' + curball ). _x +eval( 'ball' + curball ). _width * .75 > tablearea . _x + tablearea . _width / 2 )){
sinkBall ( curball );
}else {
eval( 'ball' + curball ). yvel *=- 1 ;
eval( 'ball' + curball ). _y -=(eval( 'ball' + curball ). _y +eval( 'ball' + curball ). _height / 2 -( tablearea . _y + tablearea . _height ));
}
}else if(eval( 'ball' + curball ). _y -eval( 'ball' + curball ). _height / 2 < tablearea . _y ){
if(eval( 'ball' + curball ). _x -eval( 'ball' + curball ). _width * .75 < tablearea . _x ||eval( 'ball' + curball ). _x +eval( 'ball' + curball ). _width * .75 > tablearea . _x + tablearea . _width ||(eval( 'ball' + curball ). _x -eval( 'ball' + curball ). _width * .75 < tablearea . _x + tablearea . _width / 2 &&eval( 'ball' + curball ). _x +eval( 'ball' + curball ). _width * .75 > tablearea . _x + tablearea . _width / 2 )){
sinkBall ( curball );
}else {
eval( 'ball' + curball ). yvel *=- 1 ;
eval( 'ball' + curball ). _y -=(eval( 'ball' + curball ). _y -eval( 'ball' + curball ). _height / 2 )- tablearea . _y ;
}
}
}
}
if(! ball0 . onPress ){
for( i = 0 ; i <= 15 ; i ++){
a = this [ "ball" + i ];
for( j = i + 1 ; j <= 15 ; j ++){
b = this [ "ball" + j ];
var dx = b . _x - a . _x ;
var dy = b . _y - a . _y ;
var dist = Math . sqrt ( dx * dx + dy * dy );
if( dist < a . _width / 2 + b . _width / 2 ){
_root . solveBalls ( a , b );
}
}
}
}
};
function solveBalls ( ballA , ballB ){
var x1 = ballA . _x ;
var y1 = ballA . _y ;
var dx = ballB . _x - x1 ;
var dy = ballB . _y - y1 ;
var dist = Math . sqrt ( dx * dx + dy * dy );
radius = ballA . _width / 4 + ballB . _width / 4 ;
normalX = dx / dist ;
normalY = dy / dist ;
midpointX =( x1 + ballB . _x )/ 2 ;
midpointY =( y1 + ballB . _y )/ 2 ;
ballA . _x = midpointX - normalX * radius ;
ballA . _y = midpointY - normalY * radius ;
ballB . _x = midpointX + normalX * radius ;
ballB . _y = midpointY + normalY * radius ;
dVector =( ballA . xvel - ballB . xvel )* normalX +( ballA . yvel - ballB . yvel )* normalY ;
dvx = dVector * normalX ;
dvy = dVector * normalY ;
ballA . xvel -= dvx ;
ballA . yvel -= dvy ;
ballB . xvel += dvx ;
ballB . yvel += dvy ;
}
function sinkBall ( curball ){
if( curball == 0 ){
scratch2 ();
}else {
if(eval( 'ball' + curball ). sunk == 0 && scores < 15 ){
scores ++
trace ( "scores: " + scores )
_root . score_text . text = "score: " + scores
eval( 'ball' + curball ). sunk =(++ ballssunk );
eval( 'ball' + curball ). xvel = 0 ;
eval( 'ball' + curball ). yvel = 0 ;
eval( 'ball' + curball ). _y = trayarea . _y + trayarea . _height / 2 ;
eval( 'ball' + curball ). _x = trayarea . _x +eval( 'ball' + curball ). _width / 2 ;
}
if( scores == 15 ){
scratch2 ()
reset ()
game_over . text = "GAME END"
}
}
}
function scratch (){
if( first_shot == 0 ){
showStick ();
ball0 . _x = 170
ball0 . _y = 170
}else{
}
a = ball0 ;
for( j = 1 ; j <= 15 ; j ++){
b = this . _parent [ "ball" + j ];
var dx = b . _x - a . _x ;
var dy = b . _y - a . _y ;
var dist = Math . sqrt ( dx * dx + dy * dy );
if( dist < a . _width / 2 + b . _width / 2 ){
return;
}
}
ball0 . stopDrag ();
delete ball0 . onPress ;
};
function showStick (){
if( poolstick ){
delete poolstick ;
}
this . attachMovie ( 'poolstick' , 'poolstick' , this . getNextHighestDepth (),{ _x : ball0 . _x , _y : ball0 . _y });
poolstick . power = 0 ;
poolstick . curdist = 0 ;
poolstick . onEnterFrame =function() {
if( poolstick . _alpha == 100 ){
poolstick . _x = ball0 . _x ;
poolstick . _y = ball0 . _y ;
}
if( poolstick . onPress ){
stickangle = Math . atan (-( _ymouse - ball0 . _y )/( _xmouse - ball0 . _x ))/( Math . PI / 180 );
if(( _xmouse - ball0 . _x )< 0 ){
stickangle += 180 ;
}
if(( _xmouse - ball0 . _x )>= 0 &&(-( _ymouse - ball0 . _y ))< 0 ){
stickangle += 360 ;
}
if( first_shot == 0 ){
poolstick . _rotation = 90 ;
}else{
poolstick . _rotation =- stickangle - 90 ;
}
}else {
if( poolstick . onRelease ){
poolstick . power = Math . min ( 100 , Math . max ( 0 ,( Math . sqrt ( Math . pow ( _xmouse - ball0 . _x , 2 )+ Math . pow ( _ymouse - ball0 . _y , 2 ))- poolstick . clickdistance )));
poolstick . curdist = poolstick . power ;
}else {
poolstick . curdist = Math . max ( 0 , poolstick . curdist - 20 );
if( poolstick . curdist == 0 ){
if( poolstick . _alpha == 100 ){
ball0 . xvel = Math . sin ( poolstick . _rotation * degreestoradians )*( poolstick . power * powermultiplier );
ball0 . yvel =- Math . cos ( poolstick . _rotation * degreestoradians )*( poolstick . power * powermultiplier );
}
poolstick . _alpha -= 10 ;
first_shot ++
if( poolstick . _alpha <= 0 ){
setMovementInterval ();
removeMovieClip ( poolstick );
}
}
}
}
if( poolstick . _alpha == 100 ){
poolstick . _x +=- Math . sin ( degreestoradians * poolstick . _rotation )*( ball0 . _width / 2 + poolstick . curdist );
poolstick . _y += Math . cos ( degreestoradians * poolstick . _rotation )*( ball0 . _width / 2 + poolstick . curdist );
}
};
poolstickAction ();
}
var wait_score = 0 ;
function poolstickAction (){
poolstick . onPress =function() {
poolstick . clickdistance = Math . sqrt ( Math . pow ( _xmouse - ball0 . _x , 2 )+ Math . pow ( _ymouse - ball0 . _y , 2 ));
poolstick . onRelease = poolstick . onReleaseOutside =function (){
delete poolstick . onRelease ;
delete poolstick . onReleaseOutside ;
if( poolstick . power <= 0 ){
poolstickAction ();
}else{
wait_score = scores ;
trace ( "started wait" )
}
};
delete poolstick . onPress ;
};
}
function setMovementInterval (){
var movementinterval : Number = setInterval ( this , "checkMovement" , movetime );
}
function checkMovement (): Void {
if( poolstick ){
return;
}
for( i = 0 ; i <= 15 ; i ++){
if(eval( 'ball' + i ). xvel != 0 ||eval( 'ball' + i ). yvel != 0 ){
return;
}
}
if(! ball0 . onPress ){
showStick ();
if( wait_score == scores ){
misses ++
trace ( "misses: " + misses )
misses_text . text = "misses: " + misses
}
}
}
newgame . onPress =function() {
if( ball0 ){
for( i = 0 ; i <= 15 ; i ++){
removeMovieClip ( 'ball' + i );
}
delete onEnterFrame ;
}
if( poolstick ){
removeMovieClip ( 'poolstick' );
}
newGame ();
};
function reset (){
for( i = 0 ; i <= 15 ; i ++){
removeMovieClip ( 'ball' + i );
}
delete onEnterFrame ;
if( poolstick ){
removeMovieClip ( 'poolstick' );
}
//newGame();
}
function scratch2 (){
//ball0.startDrag(true,tablearea._x+ball0._width/2+spacer,tablearea._y+ball0._height/2+spacer,tablearea._x+tablearea._width,tablearea._y+tablearea._height-ball0._height/2-spacer);
ball0 . xvel = 0 ;
ball0 . yvel = 0 ;
ball0 . _x = 170
ball0 . _y = 170
ball0 . onRelease =function() {
a = ball0 ;
for( j = 1 ; j <= 15 ; j ++){
b = this . _parent [ "ball" + j ];
var dx = b . _x - a . _x ;
var dy = b . _y - a . _y ;
var dist = Math . sqrt ( dx * dx + dy * dy );
if( dist < a . _width / 2 + b . _width / 2 ){
return;
}
}
ball0 . stopDrag ();
//showStick();
delete ball0 . onPress ;
};
}
Client Software Programmer
For number 2 you need to add a text field called timer_text
for the var: var static_timeout_time=15, thats the time it will be for each duration if you need to modify it.
PHP Code:
var first_shot = 0
var timeout_time = null
var static_timeout_time = 15
degreestoradians = Math . PI / 180 ;
ballssunk = 0 ;
spacer = .2 ;
powermultiplier = .5 ;
friction = .965 ;
movetime = 30 ;
Array. prototype . shuffle =function() {
for( i = 0 ; i < this . length ; i ++){
this . push ( this . splice ( Math . floor ( Math . random ()* this . length ), 1 ));
}
};
var cd_interv = null
function countDown ( a ){
if( a == null ){
}else{
timeout_time = a
}
if( timeout_time > 0 ){
timer_text . text = timeout_time
timeout_time --
cd_interv = setTimeout ( countDown , 1000 );
}else{
timer_text . text = 0
scratch2 ()
reset ()
game_over . text = "GAME END"
}
}
var interv = null
var scores = 0
var misses = 0 ;
var ballinterval
game_over . text = ""
function newGame (){
clearInterval ( cd_interv )
countDown ( static_timeout_time )
game_over . text = ""
scores = 0
misses = 0
ballssunk = 0 ;
spacer = .2 ;
powermultiplier = .5 ;
friction = .965 ;
movetime = 30 ;
_root . score_text . text = "score: " + scores
_root . misses_text . text = "misses: " + misses
first_shot = 0
rackx = tablearea . _x + tablearea . _width * .75 ;
racky = tablearea . _y + tablearea . _height / 2 ;
this . attachMovie ( 'balls' , 'ball8' , this . getNextHighestDepth (),{ _x : rackx , _y : racky });
ball8 . gotoAndStop ( 8 );
ball8 . xvel = 0 ;
ball8 . yvel = 0 ;
ball8 . sunk = 0 ;
ballArray =[ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 9 , 10 , 11 , 12 , 13 , 14 , 15 ];
ballArray . shuffle ();
horizdiff = Math . sqrt ( Math . pow ( ball8 . _width + spacer , 2 )- Math . pow (( ball8 . _height + spacer )/ 2 , 2 ));
ballcoords =[[ rackx - horizdiff * 2 , racky ],[ rackx - horizdiff , racky -( ball8 . _height + spacer )/ 2 ],[ rackx - horizdiff , racky +( ball8 . _height + spacer )/ 2 ],[ rackx , racky -( ball8 . _height + spacer )],[ rackx , racky +( ball8 . _height + spacer )],[ rackx + horizdiff , racky -( ball8 . _height + spacer )* 1.5 ],[ rackx + horizdiff , racky -( ball8 . _height + spacer )* .5 ],[ rackx + horizdiff , racky +( ball8 . _height + spacer )* .5 ],[ rackx + horizdiff , racky +( ball8 . _height + spacer )* 1.5 ],[ rackx + horizdiff * 2 , racky -( ball8 . _height + spacer )* 2 ],[ rackx + horizdiff * 2 , racky -( ball8 . _height + spacer )],[ rackx + horizdiff * 2 , racky ],[ rackx + horizdiff * 2 , racky +( ball8 . _height + spacer )],[ rackx + horizdiff * 2 , racky +( ball8 . _height + spacer )* 2 ]];
for( ballpos = 0 ; ballpos < 14 ; ballpos ++){
this . attachMovie ( 'balls' , 'ball' + ballArray [ ballpos ], this . getNextHighestDepth (),{ _x : ballcoords [ ballpos ][ 0 ], _y : ballcoords [ ballpos ][ 1 ]});
eval( 'ball' + ballArray [ ballpos ]). xvel = 0 ;
eval( 'ball' + ballArray [ ballpos ]). yvel = 0 ;
eval( 'ball' + ballArray [ ballpos ]). sunk = 0 ;
eval( 'ball' + ballArray [ ballpos ]). gotoAndStop ( ballArray [ ballpos ]);
}
this . attachMovie ( 'balls' , 'ball0' , this . getNextHighestDepth (),{ _x : tablearea . _x + tablearea . _width / 4 , _y : tablearea . _y + tablearea . _height / 2 });
ball0 . gotoAndStop ( 16 );
scratch ();
interv = ballinterval = setInterval ( this , "moveBalls" , movetime );
}
function moveBalls (){
for( curball = 0 ; curball <= 15 ; curball ++){
if(eval( 'ball' + curball ). sunk ){
eval( 'ball' + curball ). _x = Math . min ( trayarea . _x + trayarea . _width -eval( 'ball' + curball ). _width / 2 -eval( 'ball' + curball ). _width *(eval( 'ball' + curball ). sunk - 1 )- spacer *(eval( 'ball' + curball ). sunk - 1 ),eval( 'ball' + curball ). _x + 5 );
}else {
eval( 'ball' + curball ). _x +=eval( 'ball' + curball ). xvel ;
eval( 'ball' + curball ). _y +=eval( 'ball' + curball ). yvel ;
eval( 'ball' + curball ). xvel *= friction ;
eval( 'ball' + curball ). yvel *= friction ;
if( Math . abs (eval( 'ball' + curball ). xvel )< .02 && Math . abs (eval( 'ball' + curball ). yvel )< .02 ){
eval( 'ball' + curball ). xvel = 0 ;
eval( 'ball' + curball ). yvel = 0 ;
}
if(eval( 'ball' + curball ). _x +eval( 'ball' + curball ). _width / 2 > tablearea . _x + tablearea . _width ){
if(eval( 'ball' + curball ). _y -eval( 'ball' + curball ). _height * .75 < tablearea . _y ||eval( 'ball' + curball ). _y +eval( 'ball' + curball ). _height * .75 > tablearea . _y + tablearea . _height ){
sinkBall ( curball );
}else {
eval( 'ball' + curball ). xvel *=- 1 ;
eval( 'ball' + curball ). _x -=(eval( 'ball' + curball ). _x +eval( 'ball' + curball ). _width / 2 -( tablearea . _x + tablearea . _width ));
}
}else if(eval( 'ball' + curball ). _x -eval( 'ball' + curball ). _width / 2 < tablearea . _x ){
if(eval( 'ball' + curball ). _y -eval( 'ball' + curball ). _height * .75 < tablearea . _y ||eval( 'ball' + curball ). _y +eval( 'ball' + curball ). _height * .75 > tablearea . _y + tablearea . _height ){
sinkBall ( curball );
}else {
eval( 'ball' + curball ). xvel *=- 1 ;
eval( 'ball' + curball ). _x -=(eval( 'ball' + curball ). _x -eval( 'ball' + curball ). _width / 2 )- tablearea . _x ;
}
}
if(eval( 'ball' + curball ). _y +eval( 'ball' + curball ). _height / 2 > tablearea . _y + tablearea . _height ){
if(eval( 'ball' + curball ). _x -eval( 'ball' + curball ). _width * .75 < tablearea . _x ||eval( 'ball' + curball ). _x +eval( 'ball' + curball ). _width * .75 > tablearea . _x + tablearea . _width ||(eval( 'ball' + curball ). _x -eval( 'ball' + curball ). _width * .75 < tablearea . _x + tablearea . _width / 2 &&eval( 'ball' + curball ). _x +eval( 'ball' + curball ). _width * .75 > tablearea . _x + tablearea . _width / 2 )){
sinkBall ( curball );
}else {
eval( 'ball' + curball ). yvel *=- 1 ;
eval( 'ball' + curball ). _y -=(eval( 'ball' + curball ). _y +eval( 'ball' + curball ). _height / 2 -( tablearea . _y + tablearea . _height ));
}
}else if(eval( 'ball' + curball ). _y -eval( 'ball' + curball ). _height / 2 < tablearea . _y ){
if(eval( 'ball' + curball ). _x -eval( 'ball' + curball ). _width * .75 < tablearea . _x ||eval( 'ball' + curball ). _x +eval( 'ball' + curball ). _width * .75 > tablearea . _x + tablearea . _width ||(eval( 'ball' + curball ). _x -eval( 'ball' + curball ). _width * .75 < tablearea . _x + tablearea . _width / 2 &&eval( 'ball' + curball ). _x +eval( 'ball' + curball ). _width * .75 > tablearea . _x + tablearea . _width / 2 )){
sinkBall ( curball );
}else {
eval( 'ball' + curball ). yvel *=- 1 ;
eval( 'ball' + curball ). _y -=(eval( 'ball' + curball ). _y -eval( 'ball' + curball ). _height / 2 )- tablearea . _y ;
}
}
}
}
if(! ball0 . onPress ){
for( i = 0 ; i <= 15 ; i ++){
a = this [ "ball" + i ];
for( j = i + 1 ; j <= 15 ; j ++){
b = this [ "ball" + j ];
var dx = b . _x - a . _x ;
var dy = b . _y - a . _y ;
var dist = Math . sqrt ( dx * dx + dy * dy );
if( dist < a . _width / 2 + b . _width / 2 ){
_root . solveBalls ( a , b );
}
}
}
}
};
function solveBalls ( ballA , ballB ){
var x1 = ballA . _x ;
var y1 = ballA . _y ;
var dx = ballB . _x - x1 ;
var dy = ballB . _y - y1 ;
var dist = Math . sqrt ( dx * dx + dy * dy );
radius = ballA . _width / 4 + ballB . _width / 4 ;
normalX = dx / dist ;
normalY = dy / dist ;
midpointX =( x1 + ballB . _x )/ 2 ;
midpointY =( y1 + ballB . _y )/ 2 ;
ballA . _x = midpointX - normalX * radius ;
ballA . _y = midpointY - normalY * radius ;
ballB . _x = midpointX + normalX * radius ;
ballB . _y = midpointY + normalY * radius ;
dVector =( ballA . xvel - ballB . xvel )* normalX +( ballA . yvel - ballB . yvel )* normalY ;
dvx = dVector * normalX ;
dvy = dVector * normalY ;
ballA . xvel -= dvx ;
ballA . yvel -= dvy ;
ballB . xvel += dvx ;
ballB . yvel += dvy ;
}
function sinkBall ( curball ){
if( curball == 0 ){
scratch2 ();
}else {
if(eval( 'ball' + curball ). sunk == 0 && scores < 15 ){
scores ++
trace ( "scores: " + scores )
_root . score_text . text = "score: " + scores
eval( 'ball' + curball ). sunk =(++ ballssunk );
eval( 'ball' + curball ). xvel = 0 ;
eval( 'ball' + curball ). yvel = 0 ;
eval( 'ball' + curball ). _y = trayarea . _y + trayarea . _height / 2 ;
eval( 'ball' + curball ). _x = trayarea . _x +eval( 'ball' + curball ). _width / 2 ;
}
if( scores == 15 ){
scratch2 ()
reset ()
game_over . text = "GAME END"
}
}
}
function scratch (){
if( first_shot == 0 ){
showStick ();
ball0 . _x = 170
ball0 . _y = 170
}else{
}
a = ball0 ;
for( j = 1 ; j <= 15 ; j ++){
b = this . _parent [ "ball" + j ];
var dx = b . _x - a . _x ;
var dy = b . _y - a . _y ;
var dist = Math . sqrt ( dx * dx + dy * dy );
if( dist < a . _width / 2 + b . _width / 2 ){
return;
}
}
ball0 . stopDrag ();
delete ball0 . onPress ;
};
function showStick (){
if( poolstick ){
delete poolstick ;
}
this . attachMovie ( 'poolstick' , 'poolstick' , this . getNextHighestDepth (),{ _x : ball0 . _x , _y : ball0 . _y });
poolstick . power = 0 ;
poolstick . curdist = 0 ;
poolstick . onEnterFrame =function() {
if( poolstick . _alpha == 100 ){
poolstick . _x = ball0 . _x ;
poolstick . _y = ball0 . _y ;
}
if( poolstick . onPress ){
stickangle = Math . atan (-( _ymouse - ball0 . _y )/( _xmouse - ball0 . _x ))/( Math . PI / 180 );
if(( _xmouse - ball0 . _x )< 0 ){
stickangle += 180 ;
}
if(( _xmouse - ball0 . _x )>= 0 &&(-( _ymouse - ball0 . _y ))< 0 ){
stickangle += 360 ;
}
if( first_shot == 0 ){
poolstick . _rotation = 90 ;
}else{
poolstick . _rotation =- stickangle - 90 ;
}
}else {
if( poolstick . onRelease ){
poolstick . power = Math . min ( 100 , Math . max ( 0 ,( Math . sqrt ( Math . pow ( _xmouse - ball0 . _x , 2 )+ Math . pow ( _ymouse - ball0 . _y , 2 ))- poolstick . clickdistance )));
poolstick . curdist = poolstick . power ;
}else {
poolstick . curdist = Math . max ( 0 , poolstick . curdist - 20 );
if( poolstick . curdist == 0 ){
if( poolstick . _alpha == 100 ){
ball0 . xvel = Math . sin ( poolstick . _rotation * degreestoradians )*( poolstick . power * powermultiplier );
ball0 . yvel =- Math . cos ( poolstick . _rotation * degreestoradians )*( poolstick . power * powermultiplier );
}
poolstick . _alpha -= 10 ;
first_shot ++
if( poolstick . _alpha <= 0 ){
setMovementInterval ();
removeMovieClip ( poolstick );
}
}
}
}
if( poolstick . _alpha == 100 ){
poolstick . _x +=- Math . sin ( degreestoradians * poolstick . _rotation )*( ball0 . _width / 2 + poolstick . curdist );
poolstick . _y += Math . cos ( degreestoradians * poolstick . _rotation )*( ball0 . _width / 2 + poolstick . curdist );
}
};
poolstickAction ();
}
var wait_score = 0 ;
function poolstickAction (){
poolstick . onPress =function() {
poolstick . clickdistance = Math . sqrt ( Math . pow ( _xmouse - ball0 . _x , 2 )+ Math . pow ( _ymouse - ball0 . _y , 2 ));
poolstick . onRelease = poolstick . onReleaseOutside =function (){
delete poolstick . onRelease ;
delete poolstick . onReleaseOutside ;
if( poolstick . power <= 0 ){
poolstickAction ();
}else{
wait_score = scores ;
clearInterval ( cd_interv )
trace ( "started wait" )
}
};
delete poolstick . onPress ;
};
}
function setMovementInterval (){
var movementinterval : Number = setInterval ( this , "checkMovement" , movetime );
}
function checkMovement (): Void {
if( poolstick ){
return;
}
for( i = 0 ; i <= 15 ; i ++){
if(eval( 'ball' + i ). xvel != 0 ||eval( 'ball' + i ). yvel != 0 ){
return;
}
}
if(! ball0 . onPress ){
showStick ();
countDown ( static_timeout_time )
if( wait_score == scores ){
misses ++
trace ( "misses: " + misses )
misses_text . text = "misses: " + misses
}
}
}
newgame . onPress =function() {
if( ball0 ){
for( i = 0 ; i <= 15 ; i ++){
removeMovieClip ( 'ball' + i );
}
delete onEnterFrame ;
}
if( poolstick ){
removeMovieClip ( 'poolstick' );
}
newGame ();
};
function reset (){
for( i = 0 ; i <= 15 ; i ++){
removeMovieClip ( 'ball' + i );
}
delete onEnterFrame ;
if( poolstick ){
removeMovieClip ( 'poolstick' );
}
//newGame();
}
function scratch2 (){
//ball0.startDrag(true,tablearea._x+ball0._width/2+spacer,tablearea._y+ball0._height/2+spacer,tablearea._x+tablearea._width,tablearea._y+tablearea._height-ball0._height/2-spacer);
ball0 . xvel = 0 ;
ball0 . yvel = 0 ;
ball0 . _x = 170
ball0 . _y = 170
ball0 . onRelease =function() {
a = ball0 ;
for( j = 1 ; j <= 15 ; j ++){
b = this . _parent [ "ball" + j ];
var dx = b . _x - a . _x ;
var dy = b . _y - a . _y ;
var dist = Math . sqrt ( dx * dx + dy * dy );
if( dist < a . _width / 2 + b . _width / 2 ){
return;
}
}
ball0 . stopDrag ();
//showStick();
delete ball0 . onPress ;
};
}
You really are a genius
can you add a game total time
thanks for help
Client Software Programmer
You need to make a textfield called time_total_text
PHP Code:
var first_shot = 0
var timeout_time = null
var static_timeout_time = 15
degreestoradians = Math . PI / 180 ;
ballssunk = 0 ;
spacer = .2 ;
powermultiplier = .5 ;
friction = .965 ;
movetime = 30 ;
Array. prototype . shuffle =function() {
for( i = 0 ; i < this . length ; i ++){
this . push ( this . splice ( Math . floor ( Math . random ()* this . length ), 1 ));
}
};
var upTime = null
var seconds = 0 ;
var minutes = 0 ;
var hours = 0 ;
var days = 0 ;
upTime = setTimeout ( serverTime , 1 )
function serverTime (){
seconds ++;
if( seconds == 60 ){
seconds = 0 ;
minutes ++;
}
if( minutes == 60 ){
minutes = 0 ;
hours ++;
}
if( hours == 24 ){
hours = 0 ;
days ++;
}
upTime = setTimeout ( serverTime , 1000 )
time_total_text . text = "time: " + hours + ":" + minutes + ":" + seconds
}
var cd_interv = null
function countDown ( a ){
if( a == null ){
}else{
timeout_time = a
}
if( timeout_time > 0 ){
timer_text . text = timeout_time
timeout_time --
cd_interv = setTimeout ( countDown , 1000 );
}else{
timer_text . text = 0
scratch2 ()
reset ()
game_over . text = "GAME END"
}
}
var interv = null
var scores = 0
var misses = 0 ;
var ballinterval
game_over . text = ""
function newGame (){
clearInterval ( cd_interv )
countDown ( static_timeout_time )
game_over . text = ""
scores = 0
misses = 0
ballssunk = 0 ;
spacer = .2 ;
powermultiplier = .5 ;
friction = .965 ;
movetime = 30 ;
_root . score_text . text = "score: " + scores
_root . misses_text . text = "misses: " + misses
first_shot = 0
rackx = tablearea . _x + tablearea . _width * .75 ;
racky = tablearea . _y + tablearea . _height / 2 ;
this . attachMovie ( 'balls' , 'ball8' , this . getNextHighestDepth (),{ _x : rackx , _y : racky });
ball8 . gotoAndStop ( 8 );
ball8 . xvel = 0 ;
ball8 . yvel = 0 ;
ball8 . sunk = 0 ;
ballArray =[ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 9 , 10 , 11 , 12 , 13 , 14 , 15 ];
ballArray . shuffle ();
horizdiff = Math . sqrt ( Math . pow ( ball8 . _width + spacer , 2 )- Math . pow (( ball8 . _height + spacer )/ 2 , 2 ));
ballcoords =[[ rackx - horizdiff * 2 , racky ],[ rackx - horizdiff , racky -( ball8 . _height + spacer )/ 2 ],[ rackx - horizdiff , racky +( ball8 . _height + spacer )/ 2 ],[ rackx , racky -( ball8 . _height + spacer )],[ rackx , racky +( ball8 . _height + spacer )],[ rackx + horizdiff , racky -( ball8 . _height + spacer )* 1.5 ],[ rackx + horizdiff , racky -( ball8 . _height + spacer )* .5 ],[ rackx + horizdiff , racky +( ball8 . _height + spacer )* .5 ],[ rackx + horizdiff , racky +( ball8 . _height + spacer )* 1.5 ],[ rackx + horizdiff * 2 , racky -( ball8 . _height + spacer )* 2 ],[ rackx + horizdiff * 2 , racky -( ball8 . _height + spacer )],[ rackx + horizdiff * 2 , racky ],[ rackx + horizdiff * 2 , racky +( ball8 . _height + spacer )],[ rackx + horizdiff * 2 , racky +( ball8 . _height + spacer )* 2 ]];
for( ballpos = 0 ; ballpos < 14 ; ballpos ++){
this . attachMovie ( 'balls' , 'ball' + ballArray [ ballpos ], this . getNextHighestDepth (),{ _x : ballcoords [ ballpos ][ 0 ], _y : ballcoords [ ballpos ][ 1 ]});
eval( 'ball' + ballArray [ ballpos ]). xvel = 0 ;
eval( 'ball' + ballArray [ ballpos ]). yvel = 0 ;
eval( 'ball' + ballArray [ ballpos ]). sunk = 0 ;
eval( 'ball' + ballArray [ ballpos ]). gotoAndStop ( ballArray [ ballpos ]);
}
this . attachMovie ( 'balls' , 'ball0' , this . getNextHighestDepth (),{ _x : tablearea . _x + tablearea . _width / 4 , _y : tablearea . _y + tablearea . _height / 2 });
ball0 . gotoAndStop ( 16 );
scratch ();
interv = ballinterval = setInterval ( this , "moveBalls" , movetime );
}
function moveBalls (){
for( curball = 0 ; curball <= 15 ; curball ++){
if(eval( 'ball' + curball ). sunk ){
eval( 'ball' + curball ). _x = Math . min ( trayarea . _x + trayarea . _width -eval( 'ball' + curball ). _width / 2 -eval( 'ball' + curball ). _width *(eval( 'ball' + curball ). sunk - 1 )- spacer *(eval( 'ball' + curball ). sunk - 1 ),eval( 'ball' + curball ). _x + 5 );
}else {
eval( 'ball' + curball ). _x +=eval( 'ball' + curball ). xvel ;
eval( 'ball' + curball ). _y +=eval( 'ball' + curball ). yvel ;
eval( 'ball' + curball ). xvel *= friction ;
eval( 'ball' + curball ). yvel *= friction ;
if( Math . abs (eval( 'ball' + curball ). xvel )< .02 && Math . abs (eval( 'ball' + curball ). yvel )< .02 ){
eval( 'ball' + curball ). xvel = 0 ;
eval( 'ball' + curball ). yvel = 0 ;
}
if(eval( 'ball' + curball ). _x +eval( 'ball' + curball ). _width / 2 > tablearea . _x + tablearea . _width ){
if(eval( 'ball' + curball ). _y -eval( 'ball' + curball ). _height * .75 < tablearea . _y ||eval( 'ball' + curball ). _y +eval( 'ball' + curball ). _height * .75 > tablearea . _y + tablearea . _height ){
sinkBall ( curball );
}else {
eval( 'ball' + curball ). xvel *=- 1 ;
eval( 'ball' + curball ). _x -=(eval( 'ball' + curball ). _x +eval( 'ball' + curball ). _width / 2 -( tablearea . _x + tablearea . _width ));
}
}else if(eval( 'ball' + curball ). _x -eval( 'ball' + curball ). _width / 2 < tablearea . _x ){
if(eval( 'ball' + curball ). _y -eval( 'ball' + curball ). _height * .75 < tablearea . _y ||eval( 'ball' + curball ). _y +eval( 'ball' + curball ). _height * .75 > tablearea . _y + tablearea . _height ){
sinkBall ( curball );
}else {
eval( 'ball' + curball ). xvel *=- 1 ;
eval( 'ball' + curball ). _x -=(eval( 'ball' + curball ). _x -eval( 'ball' + curball ). _width / 2 )- tablearea . _x ;
}
}
if(eval( 'ball' + curball ). _y +eval( 'ball' + curball ). _height / 2 > tablearea . _y + tablearea . _height ){
if(eval( 'ball' + curball ). _x -eval( 'ball' + curball ). _width * .75 < tablearea . _x ||eval( 'ball' + curball ). _x +eval( 'ball' + curball ). _width * .75 > tablearea . _x + tablearea . _width ||(eval( 'ball' + curball ). _x -eval( 'ball' + curball ). _width * .75 < tablearea . _x + tablearea . _width / 2 &&eval( 'ball' + curball ). _x +eval( 'ball' + curball ). _width * .75 > tablearea . _x + tablearea . _width / 2 )){
sinkBall ( curball );
}else {
eval( 'ball' + curball ). yvel *=- 1 ;
eval( 'ball' + curball ). _y -=(eval( 'ball' + curball ). _y +eval( 'ball' + curball ). _height / 2 -( tablearea . _y + tablearea . _height ));
}
}else if(eval( 'ball' + curball ). _y -eval( 'ball' + curball ). _height / 2 < tablearea . _y ){
if(eval( 'ball' + curball ). _x -eval( 'ball' + curball ). _width * .75 < tablearea . _x ||eval( 'ball' + curball ). _x +eval( 'ball' + curball ). _width * .75 > tablearea . _x + tablearea . _width ||(eval( 'ball' + curball ). _x -eval( 'ball' + curball ). _width * .75 < tablearea . _x + tablearea . _width / 2 &&eval( 'ball' + curball ). _x +eval( 'ball' + curball ). _width * .75 > tablearea . _x + tablearea . _width / 2 )){
sinkBall ( curball );
}else {
eval( 'ball' + curball ). yvel *=- 1 ;
eval( 'ball' + curball ). _y -=(eval( 'ball' + curball ). _y -eval( 'ball' + curball ). _height / 2 )- tablearea . _y ;
}
}
}
}
if(! ball0 . onPress ){
for( i = 0 ; i <= 15 ; i ++){
a = this [ "ball" + i ];
for( j = i + 1 ; j <= 15 ; j ++){
b = this [ "ball" + j ];
var dx = b . _x - a . _x ;
var dy = b . _y - a . _y ;
var dist = Math . sqrt ( dx * dx + dy * dy );
if( dist < a . _width / 2 + b . _width / 2 ){
_root . solveBalls ( a , b );
}
}
}
}
};
function solveBalls ( ballA , ballB ){
var x1 = ballA . _x ;
var y1 = ballA . _y ;
var dx = ballB . _x - x1 ;
var dy = ballB . _y - y1 ;
var dist = Math . sqrt ( dx * dx + dy * dy );
radius = ballA . _width / 4 + ballB . _width / 4 ;
normalX = dx / dist ;
normalY = dy / dist ;
midpointX =( x1 + ballB . _x )/ 2 ;
midpointY =( y1 + ballB . _y )/ 2 ;
ballA . _x = midpointX - normalX * radius ;
ballA . _y = midpointY - normalY * radius ;
ballB . _x = midpointX + normalX * radius ;
ballB . _y = midpointY + normalY * radius ;
dVector =( ballA . xvel - ballB . xvel )* normalX +( ballA . yvel - ballB . yvel )* normalY ;
dvx = dVector * normalX ;
dvy = dVector * normalY ;
ballA . xvel -= dvx ;
ballA . yvel -= dvy ;
ballB . xvel += dvx ;
ballB . yvel += dvy ;
}
function sinkBall ( curball ){
if( curball == 0 ){
scratch2 ();
}else {
if(eval( 'ball' + curball ). sunk == 0 && scores < 15 ){
scores ++
trace ( "scores: " + scores )
_root . score_text . text = "score: " + scores
eval( 'ball' + curball ). sunk =(++ ballssunk );
eval( 'ball' + curball ). xvel = 0 ;
eval( 'ball' + curball ). yvel = 0 ;
eval( 'ball' + curball ). _y = trayarea . _y + trayarea . _height / 2 ;
eval( 'ball' + curball ). _x = trayarea . _x +eval( 'ball' + curball ). _width / 2 ;
}
if( scores == 15 ){
scratch2 ()
reset ()
game_over . text = "GAME END"
}
}
}
function scratch (){
if( first_shot == 0 ){
showStick ();
ball0 . _x = 170
ball0 . _y = 170
}else{
}
a = ball0 ;
for( j = 1 ; j <= 15 ; j ++){
b = this . _parent [ "ball" + j ];
var dx = b . _x - a . _x ;
var dy = b . _y - a . _y ;
var dist = Math . sqrt ( dx * dx + dy * dy );
if( dist < a . _width / 2 + b . _width / 2 ){
return;
}
}
ball0 . stopDrag ();
delete ball0 . onPress ;
};
function showStick (){
if( poolstick ){
delete poolstick ;
}
this . attachMovie ( 'poolstick' , 'poolstick' , this . getNextHighestDepth (),{ _x : ball0 . _x , _y : ball0 . _y });
poolstick . power = 0 ;
poolstick . curdist = 0 ;
poolstick . onEnterFrame =function() {
if( poolstick . _alpha == 100 ){
poolstick . _x = ball0 . _x ;
poolstick . _y = ball0 . _y ;
}
if( poolstick . onPress ){
stickangle = Math . atan (-( _ymouse - ball0 . _y )/( _xmouse - ball0 . _x ))/( Math . PI / 180 );
if(( _xmouse - ball0 . _x )< 0 ){
stickangle += 180 ;
}
if(( _xmouse - ball0 . _x )>= 0 &&(-( _ymouse - ball0 . _y ))< 0 ){
stickangle += 360 ;
}
if( first_shot == 0 ){
poolstick . _rotation = 90 ;
}else{
poolstick . _rotation =- stickangle - 90 ;
}
}else {
if( poolstick . onRelease ){
poolstick . power = Math . min ( 100 , Math . max ( 0 ,( Math . sqrt ( Math . pow ( _xmouse - ball0 . _x , 2 )+ Math . pow ( _ymouse - ball0 . _y , 2 ))- poolstick . clickdistance )));
poolstick . curdist = poolstick . power ;
}else {
poolstick . curdist = Math . max ( 0 , poolstick . curdist - 20 );
if( poolstick . curdist == 0 ){
if( poolstick . _alpha == 100 ){
ball0 . xvel = Math . sin ( poolstick . _rotation * degreestoradians )*( poolstick . power * powermultiplier );
ball0 . yvel =- Math . cos ( poolstick . _rotation * degreestoradians )*( poolstick . power * powermultiplier );
}
poolstick . _alpha -= 10 ;
first_shot ++
if( poolstick . _alpha <= 0 ){
setMovementInterval ();
removeMovieClip ( poolstick );
}
}
}
}
if( poolstick . _alpha == 100 ){
poolstick . _x +=- Math . sin ( degreestoradians * poolstick . _rotation )*( ball0 . _width / 2 + poolstick . curdist );
poolstick . _y += Math . cos ( degreestoradians * poolstick . _rotation )*( ball0 . _width / 2 + poolstick . curdist );
}
};
poolstickAction ();
}
var wait_score = 0 ;
function poolstickAction (){
poolstick . onPress =function() {
poolstick . clickdistance = Math . sqrt ( Math . pow ( _xmouse - ball0 . _x , 2 )+ Math . pow ( _ymouse - ball0 . _y , 2 ));
poolstick . onRelease = poolstick . onReleaseOutside =function (){
delete poolstick . onRelease ;
delete poolstick . onReleaseOutside ;
if( poolstick . power <= 0 ){
poolstickAction ();
}else{
wait_score = scores ;
clearInterval ( cd_interv )
trace ( "started wait" )
}
};
delete poolstick . onPress ;
};
}
function setMovementInterval (){
var movementinterval : Number = setInterval ( this , "checkMovement" , movetime );
}
function checkMovement (): Void {
if( poolstick ){
return;
}
for( i = 0 ; i <= 15 ; i ++){
if(eval( 'ball' + i ). xvel != 0 ||eval( 'ball' + i ). yvel != 0 ){
return;
}
}
if(! ball0 . onPress ){
showStick ();
countDown ( static_timeout_time )
if( wait_score == scores ){
misses ++
trace ( "misses: " + misses )
misses_text . text = "misses: " + misses
}
}
}
newgame . onPress =function() {
if( ball0 ){
for( i = 0 ; i <= 15 ; i ++){
removeMovieClip ( 'ball' + i );
}
delete onEnterFrame ;
}
if( poolstick ){
removeMovieClip ( 'poolstick' );
}
newGame ();
};
function reset (){
for( i = 0 ; i <= 15 ; i ++){
removeMovieClip ( 'ball' + i );
}
delete onEnterFrame ;
if( poolstick ){
removeMovieClip ( 'poolstick' );
}
//newGame();
}
function scratch2 (){
//ball0.startDrag(true,tablearea._x+ball0._width/2+spacer,tablearea._y+ball0._height/2+spacer,tablearea._x+tablearea._width,tablearea._y+tablearea._height-ball0._height/2-spacer);
ball0 . xvel = 0 ;
ball0 . yvel = 0 ;
ball0 . _x = 170
ball0 . _y = 170
ball0 . onRelease =function() {
a = ball0 ;
for( j = 1 ; j <= 15 ; j ++){
b = this . _parent [ "ball" + j ];
var dx = b . _x - a . _x ;
var dy = b . _y - a . _y ;
var dist = Math . sqrt ( dx * dx + dy * dy );
if( dist < a . _width / 2 + b . _width / 2 ){
return;
}
}
ball0 . stopDrag ();
//showStick();
delete ball0 . onPress ;
};
}
Client Software Programmer
Always? It happened to me once but the ball didnt go in the hole. I think the game came with that error, I will find it later.
Posting Permissions
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
Forum Rules
Click Here to Expand Forum to Full Width