package uk.co.beercave.gunboat.screens;

import uk.co.beercave.gunboat.GunBoat;
import uk.co.beercave.gunboat.GunBoat.ScreenType;
import uk.co.beercave.gunboat.ResourceManager;
import uk.co.beercave.gunboat.entities.GameWorld;
import uk.co.beercave.gunboat.renderers.FaderRenderer;
import uk.co.beercave.gunboat.renderers.GuiRenderer;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input.Keys;
import com.badlogic.gdx.Screen;

public class TitleScreen extends abstractScreen{

	
	private float time = 0;
	public int bestScore = 0;
	public int lastScore = 0;
	private boolean transition = false;
	private float switchTime;
	private GunBoat parent;
	public TitleScreen(GunBoat parent) {
		this.parent = parent;
	}

	@Override
	public void onRender(float delta) {
		
		GuiRenderer.Text("GUN", 320, 400);
		GuiRenderer.Text("BOAT", 300, 300);
		GuiRenderer.Text("A game about guns.", 0, 200, .5f);
		GuiRenderer.Text("And boats.", 0, 150, .5f);
		GuiRenderer.Text(String.format("LAST GAME : %06d", lastScore), 10, 470, .2f);
		GuiRenderer.Text(String.format("BEST : %06d", bestScore), 620, 470, .2f);
		GuiRenderer.Sprite(ResourceManager.logo, 0, -30, 1);
		time += delta;
		if ((Gdx.input.justTouched()
				|| Gdx.input.isKeyPressed(Keys.SPACE)
				|| GuiRenderer.Button("PLAY", 500, 100) )
			&& !transition ){
			transition = true;
			FaderRenderer.fadeOut(1);
			switchTime = time + 1.5f;
		}
		if (transition && time >= switchTime){
			parent.switchScreen(ScreenType.GAME);
		}
	}

	@Override
	public void resize(int width, int height) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void show() {
		transition = false;
		time = 0;
		if (GameWorld.score > bestScore) bestScore = GameWorld.score;
		lastScore = GameWorld.score;
		
	}

	@Override
	public void hide() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void pause() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void resume() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void dispose() {
		// TODO Auto-generated method stub
		
	}

}
