00001 #include "BreakoutLGLines.h" 00002 00003 #include <math.h> 00004 #include "SDL.h" 00005 00006 BreakoutLGLines::BreakoutLGLines() 00007 { 00008 } 00009 00010 BreakoutLGLines::~BreakoutLGLines() 00011 { 00012 } 00013 00014 BreakoutLevel* BreakoutLGLines::GenerateLevel(BreakoutLocationArray* pAvailableLocations, const Vector2i &boxSize, const int &maxHealth) 00015 { 00016 srand(SDL_GetTicks()); 00017 bool bHorizontalLines = (rand() % 2) > 0 ? true : false; 00018 00019 BreakoutLevel* pLevel = new BreakoutLevel(); 00020 00021 if(bHorizontalLines) 00022 { 00023 for(int y = 0; y < pAvailableLocations->GetHeight(); y += 2) //Alternate lines. 00024 { 00025 for(int x = 0; x < pAvailableLocations->GetWidth(); x++) 00026 { 00027 Vector2i pos = pAvailableLocations->GetLocation(x, y); 00028 int health = static_cast<int>((((float)y / (float)pAvailableLocations->GetHeight()) * (float)maxHealth) + 0.5f); //Round up 00029 health = maxHealth - health; 00030 pLevel->push_back(new BreakoutBox(pos, boxSize, health)); 00031 } 00032 } 00033 } 00034 else 00035 { 00036 for(int x = 0; x < pAvailableLocations->GetHeight(); x += 2) //Alternate lines. 00037 { 00038 for(int y = 0; y < pAvailableLocations->GetWidth(); y++) 00039 { 00040 Vector2i pos = pAvailableLocations->GetLocation(x, y); 00041 int health = static_cast<int>((((float)y / (float)pAvailableLocations->GetHeight()) * (float)maxHealth) + 0.5f); //Round up 00042 health = maxHealth - health; 00043 pLevel->push_back(new BreakoutBox(pos, boxSize, health)); 00044 } 00045 } 00046 } 00047 00048 return pLevel; 00049 }
1.5.9