package edu.smcm.ButterSealGame;

import android.content.Context;
import android.util.DisplayMetrics;
import android.view.Display;
import android.view.WindowManager;

import com.badlogic.gdx.ApplicationListener;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.audio.Music;
import com.badlogic.gdx.graphics.GL10;
import com.badlogic.gdx.graphics.Mesh;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.VertexAttribute;
import com.badlogic.gdx.graphics.VertexAttributes;
import com.badlogic.gdx.graphics.VertexAttributes.Usage;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.tiled.TileAtlas;
import com.badlogic.gdx.graphics.g2d.tiled.TileMapRenderer;
import com.badlogic.gdx.graphics.g2d.tiled.TiledLoader;
import com.badlogic.gdx.graphics.g2d.tiled.TiledMap;
import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.math.Vector3;

public class Seal implements ApplicationListener
{
	private int WIDTH;
	private int HEIGHT;
	private int cWIDTH = 400;
	private int cHEIGHT = 240;
	private int mWIDTH;
	private int mHEIGHT;
	
	private Texture buzzImage;
	private Music DreamMusic;
	private OrthographicCamera camera;
	private SpriteBatch batch;
	private Vector3 touchPos;
	private TileMapRenderer tileMapRenderer;
	
	@Override
	public void create() 
	{
		WIDTH = Gdx.graphics.getWidth();
		HEIGHT = Gdx.graphics.getHeight();
		
		Gdx.gl.glClearColor(0f,0,0.0f,1);
		
		buzzImage = new Texture(Gdx.files.internal("buzz.png"));
		DreamMusic = Gdx.audio.newMusic(Gdx.files.internal("Dream.mp3"));
		
		touchPos = new Vector3();
		
		TiledMap tiledMap = TiledLoader.createMap(Gdx.files.internal("maps/desertTest.tmx"));
		TileAtlas tileAtlas = new TileAtlas(tiledMap, Gdx.files.internal("maps"));
		tileMapRenderer = new TileMapRenderer(tiledMap, tileAtlas, 12, 12);
		
		mWIDTH = tiledMap.width * tiledMap.tileWidth;
		mHEIGHT = tiledMap.height * tiledMap.tileHeight;
		
		//DreamMusic.setLooping(true);
		//DreamMusic.play();
		
		camera = new OrthographicCamera();
		camera.setToOrtho(false, cWIDTH*2, cHEIGHT*2);
		camera.position.set(cWIDTH, cHEIGHT, 0);
	}

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

	@Override
	public void render() 
	{
		handleInput();

		
		Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT );
		camera.update();
		tileMapRenderer.render(camera);
		
		
	}
	
	private void handleInput()
	{
		if(Gdx.input.isTouched()) 
		{
			touchPos.set(Gdx.input.getX(), Gdx.input.getY(), 0);
			
			if(touchPos.y < (HEIGHT/2))
			{
				if(touchPos.x < touchPos.y)					//move left
				{
					if(camera.position.x > (cWIDTH))			//out of bounds check
						camera.translate(-3, 0, 0);
				}
				else if(touchPos.y > (WIDTH - touchPos.x)) 	//move right
				{
					if(camera.position.x < (mWIDTH-cWIDTH))
						camera.translate(3, 0, 0);
				}
				else										//move up
				{
					if(camera.position.y < (mHEIGHT-cHEIGHT))		//out of bounds check
						camera.translate(0, 3, 0);
				}
			}
			
			else
			{
				if(touchPos.x < (HEIGHT - touchPos.y))			//move left
				{
					if(camera.position.x > (cWIDTH))			//check
						camera.translate(-3, 0, 0);
				}
				else if((HEIGHT - touchPos.y) < (WIDTH - touchPos.x))	//move right
				{
					if(camera.position.y > (cHEIGHT))
						camera.translate(0, -3, 0);					
				}
				else											//move down
				{
					if(camera.position.x < (mWIDTH-cWIDTH))
						camera.translate(3, 0, 0);
				}
			}
			
		}
	}

	@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
		
	}

}
@@ -2638,25 +2638,24 @@
 chPos.y)%09%09%09%09
-%09
 //move left%0A
@@ -2693,25 +2693,24 @@
  %3E (cWIDTH))
-%09
 %09%09//out of b
@@ -2809,16 +2809,17 @@
 os.x)) %09
+%09
 //move r
@@ -2865,32 +2865,55 @@
 (mWIDTH-cWIDTH))
+%09%09//out of bounds check
 %0A%09%09%09%09%09%09camera.tr
@@ -2947,27 +2947,24 @@
 %09else%09%09%09%09%09%09%09
-%09%09%09
 //move up%0A%09%09
@@ -3013,17 +3013,16 @@
 HEIGHT))
-%09
 %09//out o
@@ -3199,19 +3199,32 @@
 IDTH))%09%09
-%09
 //
+out of bounds 
 check%0A%09%09
@@ -3318,37 +3318,36 @@
 hPos.x))%09//move 
-right
+down
 %0A%09%09%09%09%7B%0A%09%09%09%09%09if(c
@@ -3375,16 +3375,39 @@
 HEIGHT))
+%09%09//out of bounds check
 %0A%09%09%09%09%09%09c
@@ -3463,23 +3463,20 @@
 %09%09%09%09
-%09%09%09%09
 //move 
-down
+right
 %0A%09%09%09
@@ -3522,16 +3522,39 @@
 cWIDTH))
+%09%09//out of bounds check
 %0A%09%09%09%09%09%09c
@@ -3840,8 +3840,9 @@
 %09%09%0A%09%7D%0A%0A%7D
+%0A

Update Seal.java