#include "BreakoutLGLines.h"

#include <math.h>
#include "SDL.h"

BreakoutLGLines::BreakoutLGLines()
{
}

BreakoutLGLines::~BreakoutLGLines()
{
}

BreakoutLevel* BreakoutLGLines::GenerateLevel(BreakoutLocationArray* pAvailableLocations, const Vector2i &boxSize, const int &maxHealth)
{
	srand(SDL_GetTicks());
	bool bHorizontalLines = (rand() % 2) > 0 ? true : false;

	BreakoutLevel* pLevel = new BreakoutLevel();

	if(bHorizontalLines)
	{
		for(int y = 0; y < pAvailableLocations->GetHeight(); y += 2) //Alternate lines.
		{
			for(int x = 0; x < pAvailableLocations->GetWidth(); x++)
			{
				Vector2i pos = pAvailableLocations->GetLocation(x, y);
				int health = static_cast<int>((((float)y / (float)pAvailableLocations->GetHeight()) * (float)maxHealth) + 0.5f); //Round up
				health = maxHealth - health;
				pLevel->push_back(new BreakoutBox(pos, boxSize, health));
			}
		}
	}
	else
	{
		for(int x = 0; x < pAvailableLocations->GetHeight(); x += 2) //Alternate lines.
		{
			for(int y = 0; y < pAvailableLocations->GetWidth(); y++)
			{
				Vector2i pos = pAvailableLocations->GetLocation(x, y);
				int health = static_cast<int>((((float)y / (float)pAvailableLocations->GetHeight()) * (float)maxHealth) + 0.5f); //Round up
				health = maxHealth - health;
				pLevel->push_back(new BreakoutBox(pos, boxSize, health));
			}
		}
	}

	return pLevel;
}
