module vs.scene.gameover;



private import std.math;
private import gedo.gui.label;
private import gedo.gui.cursor;
private import gedo.gui.component;
private import gedo.audio.sound;
private import gedo.audio.music;
private import gedo.video.ggl;
private import gedo.video.rect;
private import gedo.video.color;
private import gedo.video.texture;
private import gedo.video.staticmesh;
private import gedo.input.joystick;
private import gedo.system.scene;
private import vs.scene.action;
private import vs.action.field;
private import vs.scene.characterselect;



private const float[2] CANVAS_SIZE = [640, 480];



alias Scene delegate() OnQuit;



public class GameOver : Scene
{
public:
	this(OnQuit dg)
	{
		_onQuit = dg;

		_bg   = Texture("$LIB/gameover/bg.png", false);
		_logo = Texture("$LIB/gameover/logo.png", false);

		_bgm = new Music("$LIB/gameover/bgm.txt");
		_bgm.play();

		_time = 0;
	}


	override void update()
	{
		const auto SCENE_END_TIME = 60*10;

		if(_time >= SCENE_END_TIME)
		{
			_nextScene = _onQuit();
		}
		else
		{
			if(_time >= 60 && Joysticks().detectPressed())
			{
				_time = SCENE_END_TIME;
			}
			else
			{
				++_time;
			}
		}
	}


	override void draw()
	{
		const auto FADE_TIME = 60;

		GGL_enableDepthBuffer(0);

		GGL_enableAlphaBlend(1);

		GGL_enter2DMode(CANVAS_SIZE[0], CANVAS_SIZE[1]);

		auto color = WHITE;
		if(_time < FADE_TIME)
		{
			auto y = cast(int)(_time * (255.0/FADE_TIME));

			color = rgba(y, y, y, 255);
		}
		_bg.draw(color);
		_logo.draw(color);
	}


private:
	Texture _bg;
	Texture _logo;
	OnQuit  _onQuit;
	Music   _bgm;
	int     _time;
}
