package ei.game.gamestate;

import ei.engine.LWJGLGameWindow;
import ei.engine.effects.Fade;
import ei.engine.math.Vector2f;
import ei.engine.scene.Sprite;
import ei.engine.state.GameState;
import ei.engine.state.GameStateManager;

public class SplashState extends GameState{
	private Fade splash;
	private boolean fadeInDone;
	private int time;
	private String nextState;

	public SplashState(String name,String next) {
		super(name);
		nextState = next;
		fadeInDone = false;
		time = 200;
	}


	@Override
	public void init() {
		splash = new Fade("Splash");
		
		Sprite s = new Sprite("Splash","data/splash.png");
		s.setLocation(new Vector2f(LWJGLGameWindow.getWidth()/2,LWJGLGameWindow.getHeight()/2));
		splash.setEntity(s);
		splash.fadeOut(false);		
	}
	
	@Override
	public void render() {
		splash.render();		
	}

	@Override
	public void update() {
		splash.update();
		if(!fadeInDone && splash.isDone()){
			time--;
			if(time <= 0){
				fadeInDone = true;
				splash.fadeOut(true);
			}
		}
		else if(fadeInDone && splash.isDone()){
			GameStateManager.getInstance().removeState(this);
			GameStateManager.getInstance().setActive(nextState);
		}
	}

}
