package com.jln.ld;

import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator;
import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator.FreeTypeFontParameter;

import menus.GameMenu;
import menus.TitleMenu;

public class Game extends ApplicationAdapter {
	SpriteBatch gameBatch, menuBatch;
	Texture img;
	private GameMenu gameMenu;
	private TitleMenu titleMenu;
	
	private int mode = 0;
	private int bestScore = 0;
	private String bestScoreString = "";
	
	@Override
	public void create () {
		gameBatch = new SpriteBatch();
		menuBatch = new SpriteBatch();
		gameMenu = new GameMenu();
		titleMenu = new TitleMenu();
		Shared.GAME_BATCH = gameBatch;
		Shared.MENU_BATCH = menuBatch;

		// Generation de la font
		FreeTypeFontGenerator generator = new FreeTypeFontGenerator(Gdx.files.internal("hud/pixelOperator8.ttf"));
		FreeTypeFontParameter parameter = new FreeTypeFontParameter();
		parameter.size = 14;
		parameter.spaceX = 0;
		Shared.FONT = generator.generateFont(parameter);
		Shared.FONT.setColor(Color.WHITE);
		
		FreeTypeFontParameter parameter2 = new FreeTypeFontParameter();
		parameter2.size = 10;
		parameter2.spaceX = 0;
		Shared.FONT_SMALL = generator.generateFont(parameter2);
		Shared.FONT_SMALL.setColor(Color.WHITE);
		generator.dispose();
	}

	@Override
	public void render () {
		Gdx.gl.glClearColor(1, 0, 0, 1);
		Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
		
		if(mode == 0){
			titleMenu.update(this);
			titleMenu.render(this);
		}else if(mode == 1){
			gameMenu.update(this);
			gameMenu.render(this);
		}
	}
	
	public void goToGameMenu(){
		gameMenu.initGame();
		mode = 1;
	}
	
	public void goToTitleMenu(int newScore, String newScoreString){
		if(newScore>bestScore){
			bestScore = newScore;
			bestScoreString = newScoreString;
		}
		mode = 0;
	}

	public int getBestScore() {
		return bestScore;
	}

	public String getBestScoreString() {
		return bestScoreString;
	}
	
	
	
	
}
