#include "intro_frame.h"

IntroFrame::IntroFrame()
	: GenericFrame("Intro")
	, t(0)
	, loaded(false)
{
	tex = TextureManager::get("miniboss"+String::IntegerToString(rand()%6)+".png")->GetId();
}

void IntroFrame::Init()
{
	Audio::get()->play("miniboss.ogg");
}

void IntroFrame::DeInit()
{

}

bool IntroFrame::DoUpdate(float time)
{
	t += time;

	if (t > 1 && !loaded) {
		loaded = true;

		// Preload big textures
		TextureManager::get("sky.png");
		TextureManager::get("planet1.png");
		TextureManager::get("planet2.png");
		TextureManager::get("planet3.png");
		TextureManager::get("halo0.png");
		TextureManager::get("halo1.png");
		TextureManager::get("halo2.png");
		TextureManager::get("title_screen.jpg");
		TextureManager::get("controls_screen.jpg");
		TextureManager::get("credits_screen.jpg");
		TextureManager::get("thanks_screen.jpg");

		MusicManager::get("music01.ogg");
	}

	if (t > 5) {
		Switch("title");
	}
	return true;
}

void IntroFrame::DoRender()
{
	glClearColor(1, 1, 1, 0);
	glClear(GL_COLOR_BUFFER_BIT);

	float alpha = max(0.0f, min(t, 5.0f-t));
	renderer.drawImage(Vector2f(512, 320), Vector2f(0.5f, 0.5f), tex, 0, 1, 0, false, Colour(1, 1, 1, alpha));
}
