import lime.ui.GamepadButton;
import lime.ui.KeyCode;
import lime.ui.KeyModifier;
import menu.MainMenu;
import openfl.Assets;
import openfl.display.Bitmap;

class Survived extends State {
	var bmp:Bitmap;

	var t:Float = 0;

	final TIME:Float = 2;

	public function new() {
		super();

		addChild(bmp = new Bitmap(Assets.getBitmapData('assets/ui/survived.png')));
		bmp.alpha = 0;
	}

	override function keyDown(keyCode:KeyCode, keyModifier:KeyModifier) {
		switch (keyCode) {
			case(E | RETURN | SPACE):
				Main.instance.setState(new MainMenu());
			case _:
		}
	}

	override function gamepadButtonDown(button:GamepadButton) {
		Main.instance.setState(new MainMenu());
	}

	override function update(delta:Float) {
		if (t < TIME) {
			bmp.alpha = Math.pow(t / TIME, 2);
			t += delta;

			if (t >= TIME) {
				bmp.alpha = 1;
				t = TIME;
			}
		}
	}
}
