Android Open Source - catchanimals Input Basket






From Project

Back to project page catchanimals.

License

The source code is released under:

GNU General Public License

If you think the Android project catchanimals listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.ricardorb.inputs;
//from  w w w.j a  v a2 s . c  om
import com.badlogic.gdx.Input;
import com.badlogic.gdx.InputAdapter;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.math.Vector3;
import com.ricardorb.catchanimals.CatchAnimals;
import com.ricardorb.controllers.ControllerBasket;

public class InputBasket extends InputAdapter {
  
  private ControllerBasket conBucket;
  private final CatchAnimals GAME;
  
  public InputBasket(ControllerBasket conBucket, CatchAnimals game){
    this.conBucket = conBucket;
    this.GAME = game;
  }
  
  @Override
  public boolean touchDragged(int screenX, int screenY, int pointer) {
    conBucket.setMoveL(false);
    conBucket.setMoveR(false);
    conBucket.setDrag(true);
    
    OrthographicCamera camera = new OrthographicCamera();
    camera.setToOrtho(false, GAME.WINDOWX, GAME.WINDOWY);
    
    Vector3 touchPos = new Vector3();
    touchPos.set(screenX, screenY, 0);
    camera.unproject(touchPos);
    
    conBucket.setDragX(touchPos.x);
    conBucket.setDragY(touchPos.y);
    return true;
  }
  
  @Override
  public boolean keyDown(int keycode) {
    conBucket.setDrag(false);
    switch (keycode) {
    case Input.Keys.RIGHT:
      if(!conBucket.isMoveL()){
        conBucket.setMoveR(true);
      }
      break;
    case Input.Keys.LEFT:
      if(!conBucket.isMoveR()){
        conBucket.setMoveL(true);
      }
      break;
    default:
      return false;
    }
    return true;
  }
  
  @Override
  public boolean keyUp(int keycode) {
    switch (keycode) {
    case Input.Keys.RIGHT:
      conBucket.setMoveR(false);
      break;
    case Input.Keys.LEFT:
      conBucket.setMoveL(false);
      break;
    default:
      return false;
    }
    return true;
  }
}




Java Source Code List

com.ricardorb.catchanimals.Assets.java
com.ricardorb.catchanimals.CatchAnimals.java
com.ricardorb.catchanimals.android.AndroidLauncher.java
com.ricardorb.catchanimals.desktop.DesktopLauncher.java
com.ricardorb.controllers.ControllerBasket.java
com.ricardorb.controllers.ControllerOption.java
com.ricardorb.inputs.InputBasket.java
com.ricardorb.screens.GameScreen.java
com.ricardorb.screens.MainMenuScreen.java
com.ricardorb.screens.OptionScreen.java
com.ricardorb.sprites.Animal.java
com.ricardorb.sprites.Basket.java
com.ricardorb.sprites.Element.java