Skip to main content
Post Closed as "too localized" by Sean Middleditch, bummzack, Trevor Powell, Ali1S232, API-Beast
edited tags
Link
Kevin Reid
  • 5.7k
  • 22
  • 30
deleted 402 characters in body
Source Link
Vaughan Hilts
  • 5.5k
  • 1
  • 34
  • 58

What actually happens: The ball replaceswill sometimes set to the ballwrong cell, and my "dropping" code will detect it should stick toas a loner and drop it off the stage.

        //Counstruct our bounding rectangle for use
    var nX = currentBall.x + ballvX * gameTime;
    var nY = currentBall.y - ballvY * gameTime;
    var movingRect = new BoundingRectangle(nX, nY, 32, 32);
    var able = false;

    //Iterate over the cells and draw our bubbles
    for (var x = 0; x < 8; x++) {
        for (var y = 0; y < 12; y++) {
            //Get the bubble at this layout
            var bubble = bubbleLayout[x][y];
            var rowHeight = 27;

            //If this slot isn't empty, draw
            if (bubble != null) {
                var bx = 0, by = 0;

                if (y % 2 == 0) {

                    bx = x * 32 + 270;
                    by = y * rowHeight32 + 45;

                } else {
                    bx = x * 32 + 270 + 16;
                    by = y * rowHeight32 + 45;
                }

                //Check
                var targetBox = new BoundingRectangle(bx, by, 32, 32);
                if (targetBox.intersects(movingRect)) {
                    able = true;

                }
            }

        }

    }

            
        
            cellXcellY = Math.round((nXcurrentBall.y - 27045) / 32);
   
if (cellY % 2 == 0)
    cellYcellX = Math.round((nYcurrentBall.x - 45270) / 32);


 
else
    var pointsThisFramecellX = 0;

    //TODO: This is a new collision mechanism, should hopefully solve a bug..Math.
    var isEven = cellY % 2 == 0;

    if round(true) {
        //Check the bubble layout
        if (cellYcurrentBall.x ==- 0270 ||- able16) {

            //TODO: Finish game losing conditions
            if (cellY == 9) {
                winGame(32);
                //  cellY++;
            }

            //Safety check
            //if(cellX == rCellX && cellY == rCellY && cellY > 0)
            //  return;

            //Assign the grid
            bubbleLayout[cellX][cellY] = currentBall;
            ballvX = 0;
            ballvY = 0;

What actually happens: The ball replaces the ball it should stick to.

        //Counstruct our bounding rectangle for use
    var nX = currentBall.x + ballvX * gameTime;
    var nY = currentBall.y - ballvY * gameTime;
    var movingRect = new BoundingRectangle(nX, nY, 32, 32);
    var able = false;

    //Iterate over the cells and draw our bubbles
    for (var x = 0; x < 8; x++) {
        for (var y = 0; y < 12; y++) {
            //Get the bubble at this layout
            var bubble = bubbleLayout[x][y];
            var rowHeight = 27;

            //If this slot isn't empty, draw
            if (bubble != null) {
                var bx = 0, by = 0;

                if (y % 2 == 0) {

                    bx = x * 32 + 270;
                    by = y * rowHeight + 45;

                } else {
                    bx = x * 32 + 270 + 16;
                    by = y * rowHeight + 45;
                }

                //Check
                var targetBox = new BoundingRectangle(bx, by, 32, 32);
                if (targetBox.intersects(movingRect)) {
                    able = true;

                }
            }

        }

    }

            
        
            cellX = Math.round((nX - 270) / 32);
            cellY = Math.round((nY - 45) / 32);


 

    var pointsThisFrame = 0;

    //TODO: This is a new collision mechanism, should hopefully solve a bug...
    var isEven = cellY % 2 == 0;

    if (true) {
        //Check the bubble layout
        if (cellY == 0 || able) {

            //TODO: Finish game losing conditions
            if (cellY == 9) {
                winGame();
                //  cellY++;
            }

            //Safety check
            //if(cellX == rCellX && cellY == rCellY && cellY > 0)
            //  return;

            //Assign the grid
            bubbleLayout[cellX][cellY] = currentBall;
            ballvX = 0;
            ballvY = 0;

What actually happens: The ball will sometimes set to the wrong cell, and my "dropping" code will detect it as a loner and drop it off the stage.

    //Counstruct our bounding rectangle for use
    var nX = currentBall.x + ballvX * gameTime;
    var nY = currentBall.y - ballvY * gameTime;
    var movingRect = new BoundingRectangle(nX, nY, 32, 32);
    var able = false;

    //Iterate over the cells and draw our bubbles
    for (var x = 0; x < 8; x++) {
        for (var y = 0; y < 12; y++) {
            //Get the bubble at this layout
            var bubble = bubbleLayout[x][y];
            var rowHeight = 27;

            //If this slot isn't empty, draw
            if (bubble != null) {
                var bx = 0, by = 0;

                if (y % 2 == 0) {

                    bx = x * 32 + 270;
                    by = y * 32 + 45;

                } else {
                    bx = x * 32 + 270 + 16;
                    by = y * 32 + 45;
                }

                //Check
                var targetBox = new BoundingRectangle(bx, by, 32, 32);
                if (targetBox.intersects(movingRect)) {
                    able = true;

                }
            }

        }

    }

    

   cellY = Math.round((currentBall.y - 45) / 32);

if (cellY % 2 == 0)
    cellX = Math.round((currentBall.x - 270) / 32);
else
    cellX = Math.round((currentBall.x - 270 - 16) / 32);
    
 
    
added 341 characters in body; edited title
Source Link
Vaughan Hilts
  • 5.5k
  • 1
  • 34
  • 58

Collision response issue Creating a frozen bubble clone

**There are many implementations of "Frozen Bubble" on the web, but I can't for the life of me find a good explanation as to how the algorithm for the "Bubble Sticking" works. **

I see this: http://www.wikiflashed.com/wiki/BubbleBobble https://frozenbubblexna.svn.codeplex.com/svn/FrozenBubble/

But I can't figure out the algorithims... could anyone explain possibly the general idea behind getting the balls to stick?

Code in question:

        //DoCounstruct someour reversalsbounding ifrectangle neededfor onuse
 the x-axis
  var nX if= (currentBall.x <+ 195ballvX +* 80gameTime;
 ||   var nY = currentBall.x >y 405- +ballvY 80)* {gameTime;
    var movingRect = new BoundingRectangle(nX, nY, 32, 32);
    var able = false;

    //ReverseIterate over the ball
cells and draw our bubbles
    ballvXfor (var x = ballvX0; *x -1;< 8; x++) {
        currentBall.xfor +=(var ballvXy *= gameTime;0; y < 12; y++) {
            //ballvYGet =the ballvYbubble *at 0.8;
this layout
            var bubble = bubbleLayout[x][y];
    }        var rowHeight = 27;

            //DoIf somethis reversalsslot ifisn't neededempty, ondraw
 the y-axis
          if (currentBall.ybubble <!= 45null) {
        ballvY *= -      var bx = 0.2;, by = 0;

    }            if (y % 2 == 0) {

    //Check if there's an intersection, move to approriate node
    //Compute cellY   bx = x * 32 + 270;
    var cellY               by = Math.round((currentBall.y -* 45)rowHeight /+ 32);45;

    var cellX;

    if (cellY % 2 == 0)  } else {
        cellX            bx = Math.round((currentBall.x -* 32 + 270) /+ 32);16;
    else
        cellX        by = Math.round((currentBall.xy -* 270rowHeight -+ 16)45;
 / 32);              }

                //GetCheck
 the request cellX and cellY
    var rCellY = Math.round((currentBall.y + (-ballvY * gameTime)var -targetBox 45)= /new BoundingRectangle(bx, by, 32, 32);
    rCellY = cellY - 1;
    
     if(rCellY < 0(targetBox.intersects(movingRect)) {
    {
        rCellY        able = 0;true;

    }
    
     var rCellX = 0; }
    

     var pointsThisFrame = 0; }

        }

    }

    if (rCellY % 2 == 0)   
        rCellX
            cellX = Math.round((currentBall.x + (ballvX * gameTime)nX - 270) / 32);
    else
        rCellXcellY = Math.round((currentBall.x + (ballvX * gameTime) - 270nY - 1645) / 32); 




    ifvar (rCellXpointsThisFrame >= -10;

 && rCellY > -1//TODO: &&This cellXis >a -1new &&collision mechanism, should hopefully solve a bug...
    var isEven = cellY >% -12 == 0;

    if (true) {
        //Check the bubble layout
        if (cellY == 0 || bubbleLayout[rCellX][rCellY] != null able) {

    //console.log("Approximating: " + rCellX + ", " + rCellY);
    //console.log("vs... " + cellX +TODO: ",Finish "game +losing cellY);
conditions
            if (cellY >== 9) {
                winGame();
 
                //Safety check cellY++;
            //if(cellX}

 == rCellX && cellY == rCellY && cellY > 0)  //Safety check
            //  return;

if(cellX == rCellX && cellY == rCellY && cellY > 0)
      
       //  return;

            //Assign the grid
            bubbleLayout[cellX][cellY] = currentBall;
            ballvX = 0;
            ballvY = 0;

Collision response issue

Code in question:

//Do some reversals if needed on the x-axis
    if (currentBall.x < 195 + 80 || currentBall.x > 405 + 80) {

        //Reverse the ball
        ballvX = ballvX * -1;
        currentBall.x += ballvX * gameTime;
        //ballvY = ballvY * 0.8;

        
    }

    //Do some reversals if needed on the y-axis
    if (currentBall.y < 45) {
        ballvY *= -0.2;
    }

    //Check if there's an intersection, move to approriate node
    //Compute cellY
    var cellY = Math.round((currentBall.y - 45) / 32);
    var cellX;

    if (cellY % 2 == 0)
        cellX = Math.round((currentBall.x - 270) / 32);
    else
        cellX = Math.round((currentBall.x - 270 - 16) / 32);

    //Get the request cellX and cellY
    var rCellY = Math.round((currentBall.y + (-ballvY * gameTime) - 45) / 32)
    rCellY = cellY - 1;
    
     if(rCellY < 0)
    {
        rCellY = 0;
    }
    
     var rCellX = 0;
    

     var pointsThisFrame = 0;

    
    

    if (rCellY % 2 == 0)
        rCellX = Math.round((currentBall.x + (ballvX * gameTime) - 270) / 32);
    else
        rCellX = Math.round((currentBall.x + (ballvX * gameTime) - 270 - 16) / 32);



    if (rCellX > -1 && rCellY > -1 && cellX > -1 && cellY > -1) {
        //Check the bubble layout
        if (cellY == 0 || bubbleLayout[rCellX][rCellY] != null ) {

    //console.log("Approximating: " + rCellX + ", " + rCellY);
    //console.log("vs... " + cellX + ", " + cellY);

            if (cellY > 9)
                winGame();
 
            //Safety check
            //if(cellX == rCellX && cellY == rCellY && cellY > 0)
            //  return;

                
         

            //Assign the grid
            bubbleLayout[cellX][cellY] = currentBall;
            ballvX = 0;
            ballvY = 0;

Creating a frozen bubble clone

**There are many implementations of "Frozen Bubble" on the web, but I can't for the life of me find a good explanation as to how the algorithm for the "Bubble Sticking" works. **

I see this: http://www.wikiflashed.com/wiki/BubbleBobble https://frozenbubblexna.svn.codeplex.com/svn/FrozenBubble/

But I can't figure out the algorithims... could anyone explain possibly the general idea behind getting the balls to stick?

Code in question:

        //Counstruct our bounding rectangle for use
    var nX = currentBall.x + ballvX * gameTime;
    var nY = currentBall.y - ballvY * gameTime;
    var movingRect = new BoundingRectangle(nX, nY, 32, 32);
    var able = false;

    //Iterate over the cells and draw our bubbles
    for (var x = 0; x < 8; x++) {
        for (var y = 0; y < 12; y++) {
            //Get the bubble at this layout
            var bubble = bubbleLayout[x][y];
            var rowHeight = 27;

            //If this slot isn't empty, draw
            if (bubble != null) {
                var bx = 0, by = 0;

                if (y % 2 == 0) {

                    bx = x * 32 + 270;
                    by = y * rowHeight + 45;

                } else {
                    bx = x * 32 + 270 + 16;
                    by = y * rowHeight + 45;
                }

                //Check
                var targetBox = new BoundingRectangle(bx, by, 32, 32);
                if (targetBox.intersects(movingRect)) {
                    able = true;

                }
            }

        }

    }

            
        
            cellX = Math.round((nX - 270) / 32);
            cellY = Math.round((nY - 45) / 32); 




    var pointsThisFrame = 0;

    //TODO: This is a new collision mechanism, should hopefully solve a bug...
    var isEven = cellY % 2 == 0;

    if (true) {
        //Check the bubble layout
        if (cellY == 0 || able) {

            //TODO: Finish game losing conditions
            if (cellY == 9) {
                winGame();
                //  cellY++;
            }

            //Safety check
            //if(cellX == rCellX && cellY == rCellY && cellY > 0)
            //  return;

            //Assign the grid
            bubbleLayout[cellX][cellY] = currentBall;
            ballvX = 0;
            ballvY = 0;
edited title
Link
Jari Komppa
  • 7.9k
  • 3
  • 32
  • 62
Loading
Source Link
Vaughan Hilts
  • 5.5k
  • 1
  • 34
  • 58
Loading