You know those games, like Bejeweled, Tetris, and whatnot? I cannot figure out an effective way to make a list of what squares are linked.
Can someone else help me out please?
// This code checks if pieces around the current piece do match
static Boolean CheckForMatches(UInt8 pos) {
UInt8 MatchesFound = 0, MatchedCounter = 0; // MatchesFound is for score calculations, MatchedCounter how many pieces disappear
Boolean MatchXminus1 = false, MatchX = false, MatchXplus1 = false; // have we already matched x-1,x,x+1 ?
Boolean Matched=false;
// Check matches x-2, x-1, x
if ((gamestate.CurrentBlock == NOMATCH1) || (gamestate.CurrentBlock == NOMATCH2)) {
return Matched;
}
if ((gamestuff.Dx / BLOCKWIDTH) > 1) {
// Check matches x-2, x-1, x XX*
if ((gamestate.CheckerBoard[pos-2] == gamestate.CurrentBlock) && (gamestate.CheckerBoard[pos-1] == gamestate.CurrentBlock)) {
Matched = true;
MatchesFound++;
DecreaseMatchesMade();
gamestuff.MatchedShapes[MatchedCounter] = pos-2; MatchedCounter++;
gamestuff.MatchedShapes[MatchedCounter] = pos-1; MatchedCounter++;
gamestuff.MatchedShapes[MatchedCounter] = pos; MatchedCounter++;
MatchXminus1 = true;
MatchX = true;
}
}
// Check matches x-1, x, x+1 X*X
if ((gamestuff.Dx / BLOCKWIDTH) && ((gamestuff.Dx / BLOCKWIDTH) < (BLOCKSACROSS-1))) {
if ((gamestate.CheckerBoard[pos-1] == gamestate.CurrentBlock) && (gamestate.CheckerBoard[pos+1] == gamestate.CurrentBlock)) {
Matched = true;
MatchesFound++;
DecreaseMatchesMade();
if (MatchXminus1 == false) { gamestuff.MatchedShapes[MatchedCounter] = pos-1; MatchedCounter++; }
if (MatchX == false) { gamestuff.MatchedShapes[MatchedCounter] = pos; MatchedCounter++; }
gamestuff.MatchedShapes[MatchedCounter] = pos+1; MatchedCounter++;
MatchXminus1 = true;
MatchX = true;
MatchXplus1 = true;
}
}
// Check matches x, x+1, x+2 *XX
if ((gamestuff.Dx / BLOCKWIDTH) < BLOCKSACROSS - 2) {
if ((gamestate.CheckerBoard[pos+1] == gamestate.CurrentBlock) && (gamestate.CheckerBoard[pos+2] == gamestate.CurrentBlock)) {
Matched = true;
MatchesFound++;
DecreaseMatchesMade();
if (MatchX == false) { gamestuff.MatchedShapes[MatchedCounter] = pos; MatchedCounter++; }
if (MatchXplus1 == false) { gamestuff.MatchedShapes[MatchedCounter] = pos+1; MatchedCounter++; }
gamestuff.MatchedShapes[MatchedCounter] = pos+2; MatchedCounter++;
MatchX = true;
}
}
// Check matches y, y+1, y+2
// *
// X
// X
if ((gamestuff.Dy / BLOCKHEIGHT) < BLOCKSDOWN -2) {
if ( (gamestate.CheckerBoard[pos+BLOCKSACROSS] == gamestate.CurrentBlock) && (gamestate.CheckerBoard[pos+BLOCKSACROSS+BLOCKSACROSS] == gamestate.CurrentBlock)) {
if ((Matched==true) && (MatchesFound==1)) { // Make Brockie happier
MatchesFound++;
}
Matched = true;
MatchesFound++;
DecreaseMatchesMade();
if (MatchX == false) { gamestuff.MatchedShapes[MatchedCounter] = pos; MatchedCounter++; }
gamestuff.MatchedShapes[MatchedCounter] = pos+BLOCKSACROSS;
MatchedCounter++;
gamestuff.MatchedShapes[MatchedCounter] = pos+BLOCKSACROSS+BLOCKSACROSS;
MatchedCounter++;
}
}
if (Matched == true) {
switch (MatchesFound) {
case 1: gamestate.Score+=MATCHBONUS1*gamestate.MatchesInARowMultiplier;
gamestate.MatchesInARow+=1;
break;
case 2: gamestate.Score+=MATCHBONUS2*gamestate.MatchesInARowMultiplier;
gamestate.MatchesInARow+=2;
break;
case 3: gamestate.Score+=MATCHBONUS3*gamestate.MatchesInARowMultiplier;
gamestate.MatchesInARow+=3;
break;
case 4: gamestate.Score+=MATCHBONUS4*gamestate.MatchesInARowMultiplier;
gamestate.MatchesInARow+=4;
break;
default:break;
}
DrawScore(); // Update the scores
FlyUpScore(pos, MatchesFound-1);
AnimateShapes(MatchedCounter); // Animate matched shapes
FillHoles(MatchedCounter); // drop shapes down if there's a space below them.
} // End Matched == true
else { // Reset MatchesInARow stuff
if (gamestate.MatchesInARowMultiplier != 1) {
PlaySoundFx(MULTIDEACTIVATEWAV);
}
gamestate.MatchesInARowMultiplier=1;
gamestate.MatchesInARow=0;
}
// Bump up the Multiplier if we are doing well
if ((gamestate.MatchesInARow > MATCHESINROW2X) && (gamestate.MatchesInARow < MATCHESINROW3X)) {
if (gamestate.MatchesInARowMultiplier != 2) {
PlaySoundFx(MULTIACTIVATEWAV);
gamestate.MatchesInARowMultiplier=2;
StrPrintF(gamestuff.Multiplier,"Super Bonus");
if (gamestate.AdvancedNo) {
PlaySoundFx(RETREATWAV);
RetreatShapes();
}
}
}
if ((gamestate.MatchesInARow > MATCHESINROW3X) && (gamestate.MatchesInARow < MATCHESINROW4X)) {
if (gamestate.MatchesInARowMultiplier != 3) {
PlaySoundFx(MULTIACTIVATEWAV);
gamestate.MatchesInARowMultiplier=3;
StrPrintF(gamestuff.Multiplier,"Mega Bonus");
}
}
if ((gamestate.MatchesInARow > MATCHESINROW4X) && (gamestate.MatchesInARow < MATCHESINROW5X)) {
if (gamestate.MatchesInARowMultiplier != 4) {
PlaySoundFx(MULTIACTIVATEWAV);
gamestate.MatchesInARowMultiplier=4;
StrPrintF(gamestuff.Multiplier,"Ultra Bonus");
}
}
if (gamestate.MatchesInARow > MATCHESINROW5X) {
if (gamestate.MatchesInARowMultiplier != 5) {
PlaySoundFx(MULTIACTIVATEWAV);
gamestate.MatchesInARowMultiplier=5;
StrPrintF(gamestuff.Multiplier,"QUIRL 10,000 pts");
gamestate.Score+=10000;
DrawScore();
}
}
if ((MatchesFound) && (gamestate.MatchesInARowMultiplier > 1)) {
ShowMultiplier();
}
else {
EraseMultiplier();
}
return Matched;
} // End of CheckForMatches function
XXXXX
X
X
// This code checks if pieces around the current piece do match
static Boolean CheckForMatches(UInt8 pos) {
// Only check current position and two to the left if current position is two across from the left side
if ((gamestuff.Dx / BLOCKWIDTH) > 1) {
// Check matches x-2, x-1, x XX*
if ((gamestate.CheckerBoard[pos-2] == gamestate.CurrentBlock) && (gamestate.CheckerBoard[pos-1] == gamestate.CurrentBlock)) {
// Matched the current position and the two to the left of it
}
}
// Check matches x-1, x, x+1 X*X
if ((gamestuff.Dx / BLOCKWIDTH) && ((gamestuff.Dx / BLOCKWIDTH) < (BLOCKSACROSS-1))) {
if ((gamestate.CheckerBoard[pos-1] == gamestate.CurrentBlock) && (gamestate.CheckerBoard[pos+1] == gamestate.CurrentBlock)) {
// Matched the current position and one either side of it
}
}
// Check matches x, x+1, x+2 *XX
// Only check if current position is two left of the right-hand side
if ((gamestuff.Dx / BLOCKWIDTH) < BLOCKSACROSS - 2) {
if ((gamestate.CheckerBoard[pos+1] == gamestate.CurrentBlock) && (gamestate.CheckerBoard[pos+2] == gamestate.CurrentBlock)) {
// Matched the current position and two to the right
}
}
// Check matches y, y+1, y+2
// *
// X
// X
if ((gamestuff.Dy / BLOCKHEIGHT) < BLOCKSDOWN -2) {
if ( (gamestate.CheckerBoard[pos+BLOCKSACROSS] == gamestate.CurrentBlock) && (gamestate.CheckerBoard[pos+BLOCKSACROSS+BLOCKSACROSS] == gamestate.CurrentBlock)) {
// Matched the current position and two under it
}
}
return Matched;
} // End of CheckForMatches function
Users browsing this forum: No registered users and 1 guest