Skip to content

Commit

Permalink
Added input processing
Browse files Browse the repository at this point in the history
  • Loading branch information
Impaler committed Feb 28, 2012
1 parent 742148b commit 0ab13e9
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 8 deletions.
Expand Up @@ -92,8 +92,5 @@ private void processInput() {
// horizontal speed is 0 // horizontal speed is 0
bob.getVelocity().x = 0; bob.getVelocity().x = 0;
} }
if (!keys.get(Keys.LEFT) && !(keys.get(Keys.RIGHT))) {
bob.setState(State.IDLE);
}
} }
} }
2 changes: 1 addition & 1 deletion star-assault/src/net/obviam/starassault/model/Bob.java
Expand Up @@ -10,7 +10,7 @@ public enum State {
} }


public static final float SPEED = 4f; // unit per second 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 public static final float SIZE = 0.5f; // half a unit


Vector2 position = new Vector2(); Vector2 position = new Vector2();
Expand Down
27 changes: 23 additions & 4 deletions star-assault/src/net/obviam/starassault/screens/GameScreen.java
Expand Up @@ -4,6 +4,7 @@
import net.obviam.starassault.model.World; import net.obviam.starassault.model.World;
import net.obviam.starassault.view.WorldRenderer; import net.obviam.starassault.view.WorldRenderer;


import com.badlogic.gdx.Application.ApplicationType;
import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input.Keys; import com.badlogic.gdx.Input.Keys;
import com.badlogic.gdx.InputProcessor; import com.badlogic.gdx.InputProcessor;
Expand All @@ -16,6 +17,8 @@ public class GameScreen implements Screen, InputProcessor {
private WorldRenderer renderer; private WorldRenderer renderer;
private WorldController controller; private WorldController controller;


private int width, height;

@Override @Override
public void show() { public void show() {
world = new World(); world = new World();
Expand All @@ -36,6 +39,8 @@ public void render(float delta) {
@Override @Override
public void resize(int width, int height) { public void resize(int width, int height) {
renderer.setSize(width, height); renderer.setSize(width, height);
this.width = width;
this.height = height;
} }


@Override @Override
Expand Down Expand Up @@ -94,14 +99,28 @@ public boolean keyTyped(char character) {


@Override @Override
public boolean touchDown(int x, int y, int pointer, int button) { public boolean touchDown(int x, int y, int pointer, int button) {
// TODO Auto-generated method stub if (!Gdx.app.getType().equals(ApplicationType.Android))
return false; return false;
if (x < width / 2 && y > height / 2) {
controller.leftPressed();
}
if (x > width / 2 && y > height / 2) {
controller.rightPressed();
}
return true;
} }


@Override @Override
public boolean touchUp(int x, int y, int pointer, int button) { public boolean touchUp(int x, int y, int pointer, int button) {
// TODO Auto-generated method stub if (!Gdx.app.getType().equals(ApplicationType.Android))
return false; return false;
if (x < width / 2 && y > height / 2) {
controller.leftReleased();
}
if (x > width / 2 && y > height / 2) {
controller.rightReleased();
}
return true;
} }


@Override @Override
Expand Down

0 comments on commit 0ab13e9

Please sign in to comment.