A Flash Developer Resource Site

Page 2 of 5 FirstFirst 12345 LastLast
Results 21 to 40 of 91

Thread: pool game need help

  1. #21
    Senior Member
    Join Date
    May 2016
    Posts
    232
    thanks for your time

  2. #22
    Client Software Programmer AS3.0's Avatar
    Join Date
    Apr 2011
    Posts
    1,202
    Does the stick not show up each time the white ball goes in the hole? Send me your swish file so it can be easier to test.

  3. #23
    Senior Member
    Join Date
    May 2016
    Posts
    232

  4. #24
    Client Software Programmer AS3.0's Avatar
    Join Date
    Apr 2011
    Posts
    1,202
    Remove line 501: ball0.onPress=function()

    and line 514: } curly bracket.

    Good idea with the timer. This project is looking good.

    use this:

    PHP Code:
    onFrame (1) {
    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();
    intervballinterval=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;
    };
    }  

    Last edited by AS3.0; 02-23-2021 at 01:04 PM.

  5. #25
    Senior Member
    Join Date
    May 2016
    Posts
    232
    very very good
    thank you so much my friend

    can you add sound when balls touch

  6. #26
    Client Software Programmer AS3.0's Avatar
    Join Date
    Apr 2011
    Posts
    1,202
    Repost continue on this thread:

    swish file with ball sound: download

  7. #27
    Senior Member
    Join Date
    May 2016
    Posts
    232

  8. #28
    Senior Member
    Join Date
    May 2016
    Posts
    232
    is this problem in the game or not ?

    when i start a new game again ( not closed the game , press the button again )

    The game gets fast !!!! ????

  9. #29
    Client Software Programmer AS3.0's Avatar
    Join Date
    Apr 2011
    Posts
    1,202
    Might be to many enterframes running at once. Let me fix.

  10. #30
    Client Software Programmer AS3.0's Avatar
    Join Date
    Apr 2011
    Posts
    1,202
    Ok in the first few lines in the function newGame() before calling setInterval for the moveBalls function it needs this line:

    PHP Code:
     clearInterval(interv
    calling the newGame function wants to run too many intervals at once without ever clearing it.
    Last edited by AS3.0; 02-24-2021 at 01:33 AM.

  11. #31
    Senior Member
    Join Date
    May 2016
    Posts
    232
    you mean in line 71 or not ?

  12. #32
    Senior Member
    Join Date
    May 2016
    Posts
    232
    i added in line 71 and working fine
    is it true ?

  13. #33
    Client Software Programmer AS3.0's Avatar
    Join Date
    Apr 2011
    Posts
    1,202
    It should look like this.
    PHP Code:
    function newGame(){
        
    clearInterval(cd_interv)
        
    clearInterval(interv
    Yes.

  14. #34
    Senior Member
    Join Date
    May 2016
    Posts
    232
    excuse me for my bad english
    i use google to translate your answer

    and there are a lot of things can not understand it

    thanks for help my friend

  15. #35
    Senior Member
    Join Date
    May 2016
    Posts
    232
    ok

  16. #36
    Client Software Programmer AS3.0's Avatar
    Join Date
    Apr 2011
    Posts
    1,202
    What language are you.

  17. #37
    Senior Member
    Join Date
    May 2016
    Posts
    232
    actionscript 2

  18. #38
    Client Software Programmer AS3.0's Avatar
    Join Date
    Apr 2011
    Posts
    1,202
    oh.

    Alright im going to work on the as2 > as3 convertor abit.
    Last edited by AS3.0; 02-24-2021 at 02:06 AM.

  19. #39
    Senior Member
    Join Date
    May 2016
    Posts
    232
    no

    I am just a beginner student who loves to learn

  20. #40
    Client Software Programmer AS3.0's Avatar
    Join Date
    Apr 2011
    Posts
    1,202
    I would love to add some multiplayer to the game but not before you agree on a feature like that.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center