- Main Page
- Classes
- Files

- File List
- File Members

# C:/Users/Public/AGS Final Folder/BFLETCHER D4010283/Source/Game/Source/BreakoutLGCircle.cpp

Go to the documentation of this file.

    00001 #include "BreakoutLGCircle.h"
    00002
    00003 #include "SDL.h"
    00004 #include <math.h>
    00005
    00006 #define max(a,b) (((a) > (b)) ? (a) : (b))
    00007 #define min(a,b) (((a) < (b)) ? (a) : (b))
    00008
    00009 BreakoutLGCircle::BreakoutLGCircle()
    00010 {
    00011 }
    00012
    00013 BreakoutLGCircle::~BreakoutLGCircle()
    00014 {
    00015 }
    00016
    00017 BreakoutLevel* BreakoutLGCircle::GenerateLevel(BreakoutLocationArray* pAvailableLocations, const Vector2i &boxSize, const int &maxHealth)
    00018 {
    00019         srand(SDL_GetTicks());
    00020         bool bInwardIncreasingHealth = (rand() % 2) > 0 ? true : false;
    00021
    00022         BreakoutLevel* pLevel = new BreakoutLevel();
    00023
    00024         int width = pAvailableLocations->GetWidth();
    00025         int height = pAvailableLocations->GetHeight();
    00026
    00027         //So it fits while being somewhat circular within the area.
    00028         int radius = height / 3;
    00029
    00030         //Health values, also acts as a map of where objects are to prevent multiple
    00031         //blocks being created at the same spot.
    00032         int** locationUsedArray = new int*[width];
    00033         for(int i = 0; i < width; i++)
    00034                 locationUsedArray[i] = new int[height];
    00035
    00036         for(int x = 0; x < width; x++)
    00037         {
    00038                 for(int y = 0; y < width; y++)
    00039                 {
    00040                         locationUsedArray[x][y] = 0;
    00041                 }
    00042         }
    00043
    00044         Vector2i centre = Vector2i(pAvailableLocations->GetWidth() / 2, pAvailableLocations->GetHeight() / 2);
    00045
    00046         float fRad = (float)radius;
    00047         for(int r = 0; r < radius; r++)
    00048         {
    00049                 fRad = (float)r;
    00050                 for(int i = 0; i < 360; i++)
    00051                 {
    00052                         float degInRad = DEGTORAD(i);
    00053
    00054                         int x = radius - (int)(cos(degInRad) * fRad);
    00055                         int y = radius - (int)(sin(degInRad) * fRad);
    00056                         float pecentageOfTotalRadius = (float)r / (float)radius;
    00057                         int resultantHealthValue = static_cast<int>((pecentageOfTotalRadius * (float)maxHealth) + 0.5f) + 1;
    00058
    00059                         if(x < width && y < height && locationUsedArray[x][y] == 0)
    00060                         {
    00061                                 if(bInwardIncreasingHealth)
    00062                                 {
    00063                                         int health = maxHealth - resultantHealthValue;
    00064                                         locationUsedArray[x][y] = max(health, 1);
    00065                                 }
    00066                                 else
    00067                                         locationUsedArray[x][y] = max(resultantHealthValue, 1);
    00068                         }
    00069                 }
    00070         }
    00071
    00072         for(int x = 0; x < width; x++)
    00073         {
    00074                 for(int y = 0; y < width; y++)
    00075                 {
    00076                         if(locationUsedArray[x][y] > 0)
    00077                         {
    00078                                 Vector2i pos = pAvailableLocations->GetLocation(x, y);
    00079                                 int health = locationUsedArray[x][y];
    00080                                 pLevel->push_back(new BreakoutBox(pos, boxSize, health));
    00081                         }
    00082                 }
    00083         }
    00084
    00085         return pLevel;
    00086 }