Skip to content
Browse files

Added input processing

  • Loading branch information...
1 parent 742148b commit 0ab13e9fe2e5ec26bce49098d20e07c10ff28f75 Impaler committed
View
3 star-assault/src/net/obviam/starassault/controller/WorldController.java
@@ -92,8 +92,5 @@ private void processInput() {
// horizontal speed is 0
bob.getVelocity().x = 0;
}
- if (!keys.get(Keys.LEFT) && !(keys.get(Keys.RIGHT))) {
- bob.setState(State.IDLE);
- }
}
}
View
2 star-assault/src/net/obviam/starassault/model/Bob.java
@@ -10,7 +10,7 @@
}
public static final float SPEED = 4f; // unit per second
- public static final float JUMP_VELOCITY = 1f;
+ public static final float JUMP_VELOCITY = 4f;
public static final float SIZE = 0.5f; // half a unit
Vector2 position = new Vector2();
View
27 star-assault/src/net/obviam/starassault/screens/GameScreen.java
@@ -4,6 +4,7 @@
import net.obviam.starassault.model.World;
import net.obviam.starassault.view.WorldRenderer;
+import com.badlogic.gdx.Application.ApplicationType;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input.Keys;
import com.badlogic.gdx.InputProcessor;
@@ -16,6 +17,8 @@
private WorldRenderer renderer;
private WorldController controller;
+ private int width, height;
+
@Override
public void show() {
world = new World();
@@ -36,6 +39,8 @@ public void render(float delta) {
@Override
public void resize(int width, int height) {
renderer.setSize(width, height);
+ this.width = width;
+ this.height = height;
}
@Override
@@ -94,14 +99,28 @@ public boolean keyTyped(char character) {
@Override
public boolean touchDown(int x, int y, int pointer, int button) {
- // TODO Auto-generated method stub
- return false;
+ if (!Gdx.app.getType().equals(ApplicationType.Android))
+ return false;
+ if (x < width / 2 && y > height / 2) {
+ controller.leftPressed();
+ }
+ if (x > width / 2 && y > height / 2) {
+ controller.rightPressed();
+ }
+ return true;
}
@Override
public boolean touchUp(int x, int y, int pointer, int button) {
- // TODO Auto-generated method stub
- return false;
+ if (!Gdx.app.getType().equals(ApplicationType.Android))
+ return false;
+ if (x < width / 2 && y > height / 2) {
+ controller.leftReleased();
+ }
+ if (x > width / 2 && y > height / 2) {
+ controller.rightReleased();
+ }
+ return true;
}
@Override

0 comments on commit 0ab13e9

Please sign in to comment.
Something went wrong with that request. Please try again.