paperJS (paper.js) JavaScript Library walk through by Brett Paufler - 9-10-13

JavaScript Primer & paper.js tutorial

BEG: Beg To Differ Bubble Drop Game - 05


Sliding the Rows Over - Bubble Game Logic


There's a lot going on in this code, but I don't think it's that complicated.  Seriously, the only bug I had while writing it was in getting the less than / greater than sign in the first for loop right.  I had it the other way at first and so the code didn't throw and error, but the block inside the for loop was impossible to reach.


            // slides empty columns over to RIGHT
            var emptyColumn = true;
            while (emptyColumn){  // wrapping while function, fire at least once
                emptyColumn = false;
                for (j = gTNH; j >= 1; j--){  // note, stops at 1  // accessing the columns from left to right
                    if (gameCircle[gTNV][j].visible === false){  // if the bottom circle is NOT visible, rest of block fires
                                                // gTNV is the highest numbered vertical gameCircle, and so is located on bottom of the board
                        for (i = 0; i <= gTNV; i++){  // if above is false, we are interested in the column, and this cycles through each vertical item
                       
                        gameCircle[i][j].visible = gameCircle[i][j - 1].visible;   // for all of these, the item to the right (current selected)
                        gameCircle[i][j].fillColor = gameCircle[i][j - 1].fillColor;    // takes on the attributes of the item on the left
                        gameCircle[i][j].strokeColor = gameCircle[i][j - 1].strokeColor;
                       
                        gameCircle[i][j - 1].visible = false;   // having shifted the [j - 1] gameCircles to the right
                        gameCircle[i][j - 1].fillColor = 'black';  // this code 'zeroes' those gameCircles out, to non-playing gameCircles
                        gameCircle[i][j - 1].strokeColor = 'black';
                       
                            if (gameCircle[i][j].visible === true){
                                emptyColumn = true;  // while looping variable is set to true, so while will loop again
                            }                                    // we had a change, so let's check again for another possible change
                        }
                    }
                }
            }  // right shift of columns wrapping while ends


Ease of coding doesn't always have that much to do with the time it takes me to code something, but in this case it did.
This was a short day for me.



previous  -- BEG: Beg to Differ - Bubble Drop #4      paper.js tutorial index       next -- BEG: Beg to Differ - Bubble Drop #6




Back to BrettCode Home



Brett Words
my writing site (Home to the writing of Celli the Happy Go Lucky Celaphopod, Eddie Takosori, Fritz Heinmillerstein, Morgan Feldstone, Kevin Stillwater, and of course, me, your host, Brett Paufler)

paper.js official site = http://www.paperJS.org


© Copyright 2013 Brett Paufler