Guest User

InputManager.java

a guest
Aug 25th, 2016
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.39 KB | None | 0 0
  1. public class InputManager extends InputAdapter{
  2.  
  3.     private Vector3 touchPoint;
  4.     private OrthographicCamera cam;
  5.     private Body playerBody;
  6.     private Array<Body> clouds;
  7.     private Rope rope;
  8.  
  9.     public InputManager(OrthographicCamera cam, Body playerBody, Array clouds, Rope rope){
  10.         this.cam = cam;
  11.         this.playerBody = playerBody;
  12.         this.clouds = clouds;
  13.         this.rope = rope;
  14.         touchPoint = new Vector3();
  15.     }
  16.  
  17.     @Override
  18.     public boolean keyDown(int keycode) {
  19.         return true;
  20.     }
  21.  
  22.     @Override
  23.     public boolean keyUp(int keycode) {
  24.         return true;
  25.     }
  26.  
  27.     @Override
  28.     public boolean keyTyped(char character) {
  29.         return true;
  30.  
  31.     }
  32.  
  33.     @Override
  34.     public boolean touchDown(int screenX, int screenY, int pointer, int button) {
  35.         cam.unproject(touchPoint.set(screenX, screenY, 0));
  36.  
  37.         for (int i = 0; i < clouds.size; i++) {
  38.             if(overlapsOnX(playerBody, clouds.get(i))){
  39.                 rope.createRope(playerBody, clouds.get(i + 5));
  40.             }
  41.         }
  42.         return true;
  43.     }
  44.  
  45.     @Override
  46.     public boolean touchUp(int screenX, int screenY, int pointer, int button) {
  47.         rope.destroyRope();
  48.         playerBody.applyLinearImpulse(5 / PPM, 10 / PPM, playerBody.getPosition().x, playerBody.getPosition().y, true);
  49.  
  50.         return true;
  51.     }
  52.  
  53.     @Override
  54.     public boolean touchDragged(int screenX, int screenY, int pointer) {
  55.         return true;
  56.     }
  57.  
  58.     @Override
  59.     public boolean mouseMoved(int screenX, int screenY) {
  60.         return true;
  61.     }
  62.  
  63.     @Override
  64.     public boolean scrolled(int amount) {
  65.         return true;
  66.     }
  67.  
  68.     private boolean overlapsOnX(Body player, Body cloud){ //check if the player is currently in the same X position than a cloud
  69.         if(player.getPosition().x >= cloud.getPosition().x && player.getPosition().x <= cloud.getPosition().x){
  70.             return true;
  71.         }
  72.         return false;
  73.     }
  74.  
  75.     private boolean overlaps(Body cloud, Vector3 touch){ //check if touch overlaps with a cloud body
  76.         if(touch.x >= cloud.getPosition().x - (20 / PPM) && touch.x <= cloud.getPosition().x + (20 / PPM)){
  77.             if(touch.y >= cloud.getPosition().y - (4 / PPM) && touch.y <= cloud.getPosition().y + (4 / PPM)){
  78.                 return true;
  79.             }
  80.         }
  81.         return false;
  82.     }
  83.  
  84. }
Add Comment
Please, Sign In to add comment