/**
 * 
 */
package com.mygdx.game.screens;

import com.badlogic.gdx.Game;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL20;
import com.mygdx.game.MyGamePereference;
import com.mygdx.game.MyWorldController;
import com.mygdx.game.MyWorldRender;

/**
 * @author qinD
 *
 * 2015-1-21
 */
public class MyGameScreen extends MyAbstractGameScreen{
	
	private static final String TAG = MyGameScreen.class.getName();
	
	private MyWorldController worldController;
	private MyWorldRender worldRender;
	
	private boolean isPaused = false;
	
	/**
	 * @param game
	 */
	public MyGameScreen(Game game) {
		super(game);
	}

	/* (non-Javadoc)
	 * @see com.badlogic.gdx.Screen#show()
	 */
	@Override
	public void show() {
		MyGamePereference.instance.load();
		worldController = new MyWorldController(game);
		worldRender = new MyWorldRender(worldController);
		Gdx.input.setCatchBackKey(true);
	}

	/* (non-Javadoc)
	 * @see com.badlogic.gdx.Screen#render(float)
	 */
	@Override
	public void render(float delta) {
		if (!isPaused) {
			worldController.update(delta);
		}
		Gdx.gl.glClearColor(0x64 / 255.0f, 0x95 / 255.0f, 0xed / 255.0f, 0xff / 255.0f);
		Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
		worldRender.render(delta);
	}

	/* (non-Javadoc)
	 * @see com.badlogic.gdx.Screen#resize(int, int)
	 */
	@Override
	public void resize(int width, int height) {
		worldRender.resize(width, height);
	}

	/* (non-Javadoc)
	 * @see com.badlogic.gdx.Screen#hide()
	 */
	@Override
	public void hide() {
		worldRender.dispose();
		Gdx.input.setCatchBackKey(false);
	}

	/* (non-Javadoc)
	 * @see com.badlogic.gdx.Screen#dispose()
	 */
	@Override
	public void dispose() {
		worldController.dispose();
		worldRender.dispose();
	}

	
	/* (non-Javadoc)
	 * @see com.mygdx.game.screens.MyAbstractGameScreen#pause()
	 */
	@Override
	public void pause() {
		super.pause();
		isPaused = true;
	}
	/* (non-Javadoc)
	 * @see com.mygdx.game.screens.MyAbstractGameScreen#resume()
	 */
	@Override
	public void resume() {
		super.resume();
		isPaused = false;
	}
}
