Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 1st, 2012  |  syntax: C++  |  size: 1.39 KB  |  hits: 19  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. void CalculateSlopesUp()
  2. {
  3.  
  4.         for (int x = 0; x < GRID_SIZE; ++x)
  5.         {
  6.  
  7.                 for (int y = 0; y < GRID_SIZE; ++y)
  8.                 {
  9.  
  10.                         int tileheight = gameTiles[x][y].GetHeight();
  11.  
  12.                         //no need for an upward slope if we are at max height
  13.                         if (tileheight < 2)
  14.                         {
  15.  
  16.                                 bool IsSlopeAvailable = true;
  17.  
  18.                                 //check if we are next to a sloped tile
  19.                                 if (AreSurroundingTilesSloped(x,y))
  20.                                 {
  21.                                         IsSlopeAvailable = false;
  22.                                 }
  23.  
  24.                                 HexTile* TileUp = GetTileInDirection(x, y, UP);
  25.  
  26.                                 if (TileUp)
  27.                                 {
  28.                                         if (TileUp->GetHeight() != tileheight + 1)
  29.                                         {
  30.                                                 IsSlopeAvailable = false;
  31.                                         }
  32.                                 }
  33.                                 else
  34.                                 {
  35.                                         IsSlopeAvailable = false;
  36.                                 }
  37.  
  38.                                 HexTile* TileUpLeft = GetTileInDirection(x, y, UPLEFT);
  39.  
  40.                                 if (TileUpLeft)
  41.                                 {
  42.                                         if (TileUpLeft->GetHeight() <= tileheight)
  43.                                         {
  44.                                                 IsSlopeAvailable = false;
  45.                                         }
  46.                                 }
  47.  
  48.                                 HexTile* TileUpRight = GetTileInDirection(x, y, UPRIGHT);
  49.  
  50.                                 if (TileUpRight)
  51.                                 {
  52.                                         if (TileUpRight->GetHeight() <= tileheight)
  53.                                         {
  54.                                                 IsSlopeAvailable = false;
  55.                                         }
  56.                                 }
  57.  
  58.                                 HexTile* TileDown = GetTileInDirection(x, y, DOWN);
  59.  
  60.                                 if (TileDown)
  61.                                 {
  62.                                         if (TileDown->GetHeight() != tileheight)
  63.                                         {
  64.                                                 IsSlopeAvailable = false;
  65.                                         }
  66.                                 }
  67.                                 else
  68.                                 {
  69.                                         IsSlopeAvailable = false;
  70.                                 }
  71.  
  72.                                 if (IsSlopeAvailable)
  73.                                 {
  74.                                         gameTiles[x][y].SetSloped(UP);
  75.                                 }
  76.  
  77.                         }
  78.  
  79.                 }
  80.  
  81.         }
  82.  
  83. }