I've got a design question/problem!

Talk about making games.

I've got a design question/problem!

Postby Fuzzy » Sun May 07, 2006 4:30 am

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?
Mortal Enemy of IF....THEN(and Inspector Gadget)

Still ThreeFingerPete to tekdino
User avatar
Fuzzy
 
Posts: 1068
Joined: Thu Mar 03, 2005 9:32 am
Location: Plymostic Programmer
Score: 95 Give a positive score

Postby WauloK » Mon May 08, 2006 3:16 pm

I wrote a game like this for Palm called "Quirl".
Image

I stored all the data in an array then matched the characters.

Code: Select all
// 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


It'd match up to 5 shapes across and three down.

Code: Select all
XXXXX
  X
  X

Two to the left, two to the right and two underneath.
Available for Beta-testing.. PM me!
Black 16Gb iPhone 3GS
Windows 7: 2Gb RAM. Dell 9150.
WauloK
 
Posts: 42
Joined: Wed Apr 19, 2006 3:19 am
Location: Sydney, Aussieland
Score: 0 Give a positive score

Postby Fuzzy » Mon May 08, 2006 8:58 pm

Wow! I had no idea it would be so complex!

Thanks a lot!
Mortal Enemy of IF....THEN(and Inspector Gadget)

Still ThreeFingerPete to tekdino
User avatar
Fuzzy
 
Posts: 1068
Joined: Thu Mar 03, 2005 9:32 am
Location: Plymostic Programmer
Score: 95 Give a positive score

Postby WauloK » Tue May 09, 2006 9:11 pm

well you can leave out bits of my code. it not only does matching but other things as well.

I'll try cutting out bits

Code: Select all
// 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
Last edited by WauloK on Tue May 09, 2006 9:13 pm, edited 1 time in total.
Available for Beta-testing.. PM me!
Black 16Gb iPhone 3GS
Windows 7: 2Gb RAM. Dell 9150.
WauloK
 
Posts: 42
Joined: Wed Apr 19, 2006 3:19 am
Location: Sydney, Aussieland
Score: 0 Give a positive score

Postby WauloK » Tue May 09, 2006 9:12 pm

gamestate.CheckerBoard[] is the array holding all pieces on the board.
Available for Beta-testing.. PM me!
Black 16Gb iPhone 3GS
Windows 7: 2Gb RAM. Dell 9150.
WauloK
 
Posts: 42
Joined: Wed Apr 19, 2006 3:19 am
Location: Sydney, Aussieland
Score: 0 Give a positive score


Return to Game Development

Who is online

Users browsing this forum: No registered users and 1 guest

cron