A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: TonyPa, Ed Mack, Vengeance, anyone!?

  1. #1
    Senior Member
    Join Date
    Aug 2005
    Posts
    238

    TonyPa, Ed Mack, Vengeance, anyone!?

    Hey guys.. I have a problem thats driving me nuts, and I am hoping one of you can propose a modification or a better way. I am making a tilebased breakout engine (using ideas from tonypas tutorial) and I am up to the part that checks for collisions, richochets the ball, and deletes brick. My code seems to work but if the ball happens to hit a certain spot (maybe right in between too bricks) it will kind of zig zag through them and annhilate way more than it should. Perhaps this is because I am using the basic hitTest which involves the bounding box of the ball, and maybe the problem would resolve itself if I used the other type of hittest (which i am not quite sure how too). Another idea i thought of was maybe having like a very very small weight timer, that only lets a brick be destroyed if some increment of time has gone by since the last destruction (i dont like this idea though, could cause problems) My code for the hittest part is below. If you guys have any suggested modifications or alternate methods of approach I would reaaaallly appreciate it. Thank you very much in advance.

    ---Keith


    code:

    function getMyCorners(x, y, ob) {
    // find corner points
    ob.upY = Math.floor((y+ob.height-1)/game.tileH);
    ob.downY = Math.floor((y-ob.height)/game.tileH);
    ob.rightX = Math.floor((x-ob.width)/game.tileW);
    ob.leftX = Math.floor((x+ob.width-1)/game.tileW);
    // check if they are walls
    ob.downright = game["t_"+ob.downY+"_"+ob.rightX].walkable;
    ob.upright = game["t_"+ob.upY+"_"+ob.rightX].walkable;
    ob.downleft = game["t_"+ob.downY+"_"+ob.leftX].walkable;
    ob.upleft = game["t_"+ob.upY+"_"+ob.leftX].walkable;
    }

    function moveBall(ob) {

    //check horizontal collisions first
    getMyCorners (ob._x + ob.xspeed, ob._y, ob);

    if ( !(ob.downright && ob.upright && ob.downleft && ob.upleft))
    {
    if (game.clip["t_"+ob.downY+"_"+ob.rightX].hitTest(ball)) {

    ball.xspeed *= -1;
    removeMovieClip(game.clip["t_"+ob.downY+"_"+ob.rightX]);
    }

    if (game.clip["t_"+ob.upY+"_"+ob.rightX].hitTest(ball)) {

    ball.xspeed *= -1;
    removeMovieClip(game.clip["t_"+ob.upY+"_"+ob.rightX]);
    }

    if (game.clip["t_"+ob.downY+"_"+ob.leftX].hitTest(ball)) {

    ball.xspeed *= -1;
    removeMovieClip(game.clip["t_"+ob.downY+"_"+ob.leftX]);
    }

    if (game.clip["t_"+ob.upY+"_"+ob.leftX].hitTest(ball)) {

    ball.xspeed *= -1;
    removeMovieClip(game.clip["t_"+ob.upY+"_"+ob.leftX]);
    }


    }

    //check vertical collisions
    getMyCorners (ob._x, ob._y + ob.yspeed, ob);

    if ( !(ob.downright && ob.upright && ob.downleft && ob.upleft))
    {
    if (game.clip["t_"+ob.downY+"_"+ob.rightX].hitTest(ball)) {

    ball.yspeed *= -1;
    removeMovieClip(game.clip["t_"+ob.downY+"_"+ob.rightX]);
    }

    if (game.clip["t_"+ob.upY+"_"+ob.rightX].hitTest(ball)) {

    ball.yspeed *= -1;
    removeMovieClip(game.clip["t_"+ob.upY+"_"+ob.rightX]);
    }

    if (game.clip["t_"+ob.downY+"_"+ob.leftX].hitTest(ball)) {

    ball.yspeed *= -1;
    removeMovieClip(game.clip["t_"+ob.downY+"_"+ob.leftX]);
    }

    if (game.clip["t_"+ob.upY+"_"+ob.leftX].hitTest(ball)) {

    ball.yspeed *= -1;
    removeMovieClip(game.clip["t_"+ob.upY+"_"+ob.leftX]);
    }


    }


    ball._x += ball.xspeed; //move depending on our xspeed
    ball._y += ball.yspeed; //move depending on our yspeed





    P.S. I know i could clean this up a bit by making better use of functions... but I'll save that till I actually have it right....
    Last edited by Scotopia; 09-18-2005 at 12:41 AM.

  2. #2
    Senior Member tonypa's Avatar
    Join Date
    Jul 2001
    Location
    Estonia
    Posts
    8,223
    I am pretty sure you should use if...else statements so only 1 block is destroyed at each step.

  3. #3
    Senior Member
    Join Date
    Aug 2005
    Posts
    238
    usually only one block does get destroyed, unless it happens to hit in a certain way, then it does what i said. Also, if you do if/else, wouldn't you be giving precedence to one kind of collision over the other?

  4. #4
    Senior Member
    Join Date
    Aug 2005
    Posts
    238
    What say you, tonypa? (or anyone else)

  5. #5
    Senior Member
    Join Date
    Aug 2002
    Posts
    349
    use ifs to detect the problem, even use double ifs, If the ball hits in that area and will create that bug the do this, ie, if this block is hit and this block is there do this action that will lead it away from your bug.
    Free Flash Multiplayer Gaming
    http://www.gecko-games.com

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