#include	"SpaceShooter.h"

using namespace AGK;

void	CreateBackground()
{
	agk::LoadImage(1, "space/space.jpg");
	agk::CreateSprite(1, 1);
	agk::FixSpriteToScreen(1, 1);
}

void	CreateStarField()
{
	agk::LoadImage(4, "space/particle.png");

	agk::CreateParticles(1, 550.0, 0.0);
	agk::SetParticlesImage(1, 4);
	agk::SetParticlesStartZone(1, 0, 10, 0, 400);
	agk::SetParticlesDirection(1, -50.0, 0.0);
	agk::SetParticlesLife(1, 15);
	agk::SetParticlesSize(1, 4);
	agk::SetParticlesAngle(1, 0);
	agk::SetParticlesFrequency(1, 60);
	agk::SetParticlesVelocityRange(1, 0.5, 4.0);
	agk::FixParticlesToScreen(1, 1);
}

void	CreateLevel()
{
	int j = agk::LoadImage("space/MetalBlock1.png");

	// top random
	CreateStrip(j, 32.0f, 0.0f, 0);

	// bottom random
	CreateStrip(j, 25.0f, 0.0f, 1);

	// top and bottom straight
	CreateStrip(j, 0.0f, 0.0f, 2);
}

void CreateStrip(int iImage, float fX, float fY, int iMode)
{
	for (int i = 0; i <= 250; i++)
	{
		int built = 0;
		int	iSprite = -1;
		int	iSpriteB = -1;

		if (iMode == 0)
		{
			if (agk::Random(1, 2) == 1)
			{
				iSprite = agk::CreateSprite(iImage);
				agk::SetSpritePosition(iSprite, fX, float(368 - agk::Random(64, 64 + 32)));
				//SetSpriteUVBorder ( iSprite, 0 )
				built = 1;
			}

			if (fX > 300 && agk::Random(1, 5) == 3)
			{
				iSpriteB = agk::CreateSprite(iImage);
				agk::SetSpritePosition(iSpriteB, fX, float(agk::Random(120, 200)));
				agk::SetSpriteColor(iSpriteB, 255, 255, 255, 200);
				agk::SetSpriteAngle(iSpriteB, float(agk::Random(0, 360)));
				//SetSpriteUVBorder ( iSpriteB, 0 )
				built = 1;
			}
		}

		if (iMode == 1)
		{
			if (agk::Random(1, 3) == 1)
			{
				iSprite = agk::CreateSprite(iImage);
				agk::SetSpritePosition(iSprite, fX, float(agk::Random(32, 64)));
				//SetSpriteUVBorder ( iSprite, 0 )
				built = 1;
			}
		}

		if (iMode == 2)
		{
			iSprite = agk::CreateSprite(iImage);
			agk::SetSpritePosition(iSprite, fX, 0.0);

			iSpriteB = agk::CreateSprite(iImage);
			agk::SetSpritePosition(iSpriteB, fX, 400 - 64);

			//SetSpriteUVBorder ( iSpriteB, 0 )
			built = 1;
		}

		if (built == 1)
		{

			if (iSprite != -1)
			{
				g_iScenery[g_iSceneryCount] = iSprite;
				g_iSceneryCount++;
			}

			if (iSpriteB != -1)
			{
				g_iScenery[g_iSceneryCount] = iSpriteB;
				g_iSceneryCount++;
			}
		}

		fX = fX + 64;
	}
}
