ColorRunner/core/src/de/samdev/colorrunner/input/CRGameInputProcessor.java

166 lines
3.5 KiB
Java
Raw Normal View History

package de.samdev.colorrunner.input;
2014-08-10 19:41:06 +02:00
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input;
import com.badlogic.gdx.InputProcessor;
import com.badlogic.gdx.input.GestureDetector.GestureListener;
import com.badlogic.gdx.math.Vector2;
2014-08-11 00:24:55 +02:00
import de.samdev.colorrunner.game.world.SwipeDirection;
public class CRGameInputProcessor implements InputProcessor, GestureListener {
private GameInputListener owner;
public CRGameInputProcessor(GameInputListener gsc) {
this.owner = gsc;
}
2014-08-10 19:41:06 +02:00
public void update() {
if (Gdx.input.isKeyPressed(Input.Keys.SPACE) || Gdx.input.isTouched()) {
owner.doFly();
}
}
@Override
public boolean keyDown(int keycode) {
if (keycode == Input.Keys.UP) {
owner.switchColor(SwipeDirection.UP);
return true;
}
if (keycode == Input.Keys.RIGHT) {
owner.switchColor(SwipeDirection.RIGHT);
return true;
}
if (keycode == Input.Keys.DOWN) {
owner.switchColor(SwipeDirection.DOWN);
return true;
}
if (keycode == Input.Keys.LEFT) {
owner.switchColor(SwipeDirection.LEFT);
return true;
}
if (keycode == Input.Keys.SPACE) {
owner.doJump();
return true;
}
return false;
}
@Override
public boolean keyUp(int keycode) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean keyTyped(char character) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean touchDown(int screenX, int screenY, int pointer, int button) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean touchUp(int screenX, int screenY, int pointer, int button) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean touchDragged(int screenX, int screenY, int pointer) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean mouseMoved(int screenX, int screenY) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean scrolled(int amount) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean touchDown(float x, float y, int pointer, int button) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean tap(float x, float y, int count, int button) {
owner.doJump();
return false;
}
@Override
public boolean longPress(float x, float y) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean fling(float velocityX, float velocityY, int button) {
if (velocityX == velocityY) return false;
if (velocityY > Math.abs(velocityX)) {
owner.switchColor(SwipeDirection.UP);
return true;
}
if (Math.abs(velocityY) < velocityX) {
owner.switchColor(SwipeDirection.LEFT);
return true;
}
if (velocityY < Math.abs(velocityX)) {
owner.switchColor(SwipeDirection.DOWN);
return true;
}
if (Math.abs(velocityY) > velocityX) {
owner.switchColor(SwipeDirection.RIGHT);
return true;
}
return false;
}
@Override
public boolean pan(float x, float y, float deltaX, float deltaY) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean panStop(float x, float y, int pointer, int button) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean zoom(float initialDistance, float distance) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean pinch(Vector2 initialPointer1, Vector2 initialPointer2, Vector2 pointer1, Vector2 pointer2) {
// TODO Auto-generated method stub
return false;
}
}