package net.plastboks.sneikhelpers;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.InputProcessor;
import net.plastboks.shared.Directions;
import net.plastboks.gameobjects.Snake;
import net.plastboks.gameworld.GameWorld;

/**
 * Created by alex on 12/12/14.
 */
public class InputHandler implements InputProcessor {

    private GameWorld world;
    private Snake snake;

    public InputHandler(GameWorld world) {
        this.world = world;
        this.snake = world.getSnake();
    }

    @Override
    public boolean touchDown(int screenX, int screenY, int pointer, int button) {
        if (world.isReady()) {
            world.start();
        }
        //Gdx.app.log("Height: ", Gdx.graphics.getHeight() + "");
        //Gdx.app.log("Width: ", Gdx.graphics.getWidth() + "");
        snake.onClick(screenX/2.f, screenY/2.f);
        if (world.isGameOver() || world.isHighScore()) {
            world.restart();
        }
        return true;
    }

    @Override
    public boolean keyDown(int keycode) {
        switch (keycode) {
            case 19:
                world.getSnake().changeDir(Directions.NORTH);
                break;
            case 20:
                world.getSnake().changeDir(Directions.SOUTH);
                break;
            case 21:
                world.getSnake().changeDir(Directions.WEST);
                break;
            case 22:
                world.getSnake().changeDir(Directions.EAST);
                break;

        }
        return false;
    }
    @Override
    public boolean keyUp(int keycode) { return false; }
    @Override
    public boolean keyTyped(char character) { return false; }
    @Override
    public boolean touchUp(int screenX, int screenY, int pointer, int button) { return false; }
    @Override
    public boolean touchDragged(int screenX, int screenY, int pointer) { return false; }
    @Override
    public boolean mouseMoved(int screenX, int screenY) { return false; }
    @Override
    public boolean scrolled(int amount) { return false; }
}

@@ -54,19 +54,30 @@
 gic.gdx.
-Gdx
+InputProcessor
 ;%0Aimport
@@ -90,37 +90,80 @@
 adlogic.gdx.
-InputProcesso
+math.Vector3;%0Aimport net.plastboks.gameworld.GameRendere
 r;%0Aimport ne
@@ -416,19 +416,78 @@
 ate 
-Snake snake
+GameRenderer renderer;%0A    private Snake snake;%0A    Vector3 touchPoint
 ;%0A%0A 
@@ -524,16 +524,39 @@
 ld world
+, GameRenderer renderer
 ) %7B%0A    
@@ -614,24 +614,99 @@
 getSnake();%0A
+        this.renderer = renderer;%0A        this.touchPoint = new Vector3();%0A
     %7D%0A%0A    @
@@ -808,142 +808,83 @@
     
-if (world.isReady()) %7B%0A            world.start();%0A        %7D%0A        //Gdx.app.log(%22Height: %22, Gdx.graphics.getHeight() + %22%22
+renderer.getCam().unproject(touchPoint.set(screenX, screenY, 0)
 );%0A
+%0A
         
 //Gd
@@ -883,113 +883,101 @@
     
-//Gdx.app.log(%22Width: %22, Gdx.graphics.getWidth() + %22%22);%0A        snake.onClick(screenX/2.f, screenY/2.f
+if (world.isReady()) %7B world.start(); %7D%0A%0A        snake.onClick(touchPoint.x, touchPoint.y
 );%0A
+%0A
     
@@ -1028,28 +1028,16 @@
 ore()) %7B
-%0A           
  world.r
@@ -1045,27 +1045,20 @@
 start();
-%0A       
  %7D%0A
+%0A
         
@@ -1617,24 +1617,25 @@
 alse;%0A    %7D%0A
+%0A
     @Overrid

use gamerenderers cam object to calculate touch x,y coordinates