List of usage examples for com.badlogic.gdx Input isKeyPressed
public boolean isKeyPressed(int key);
From source file:com.davidykay.shootout.screens.GameLoop.java
License:Apache License
@Override public void update(Application app) { simulation.update(app.getGraphics().getDeltaTime()); Input input = app.getInput(); final boolean ACCELEROMETER_STEERING = false; if (ACCELEROMETER_STEERING) { if (input.getAccelerometerY() < 0) simulation.moveShipLeft(app.getGraphics().getDeltaTime(), Math.abs(input.getAccelerometerY()) / 10); else/*from w ww . j a va2s.c o m*/ simulation.moveShipRight(app.getGraphics().getDeltaTime(), Math.abs(input.getAccelerometerY()) / 10); } if (input.isKeyPressed(Keys.DPAD_LEFT)) simulation.moveShipLeft(app.getGraphics().getDeltaTime(), 0.5f); if (input.isKeyPressed(Keys.DPAD_RIGHT)) simulation.moveShipRight(app.getGraphics().getDeltaTime(), 0.5f); if (input.justTouched()) { final float x = input.getX(); final float y = input.getY(); Vector3 nearVector = new Vector3(x, y, 0); Vector3 farVector = new Vector3(x, y, 1); renderer.unproject(nearVector); renderer.unproject(farVector); /** Vector tracing between the near plane and the far plane **/ Vector3 inVector = new Vector3(nearVector); final Plane gamePlane = new Plane(new Vector3(0, 0, 0), new Vector3(1, 0, 0), new Vector3(0, 0, 1)); Ray pickRay = renderer.getCamera().getPickRay(x, y); Vector3 intersection = new Vector3(); Vector3 finalVector; if (FLAT_MODE) { // Flat Mode if (Intersector.intersectRayPlane(pickRay, gamePlane, intersection)) { finalVector = new Vector3(intersection); if (finalVector.equals(nearVector)) { Gdx.app.log(TAG, String.format("Near Vector! finalVector:(%s)", finalVector.toString())); } else { Gdx.app.log(TAG, String.format("INTERSECTION! finalVector:(%s)", finalVector.toString())); } } else { Gdx.app.log(TAG, String.format("NO INTERSECTION. nearVector:(%s)", nearVector.toString())); finalVector = new Vector3(nearVector); } } else { // 3D Mode finalVector = new Vector3(nearVector); //for (Alien alien : aliens) { // if ( // Intersector.intersectRayPlane( // pickRay, // gamePlane, // intersection // ) // ) { // } //} } //simulation.tapShot(nearVector); //simulation.tapShot(finalVector); simulation.tapRay(pickRay); } else { // If we haven't been touched, let's look at the orientation. This in an attempt to lower // impulse from user's finger. float azimuth = input.getAzimuth(); float pitch = input.getPitch(); float roll = input.getRoll(); simulation.updateOrientation(azimuth, pitch, roll); } }
From source file:com.digitale.screens.GameLoop.java
License:Open Source License
/** * @param input//from ww w .j av a 2 s . c o m * @param turnSpeed */ private void checkShipContols(Input input, float turnSpeed, float delta) { /* * A minimum of dataset B maximum of dataset a is from where you would * like normalised data set to start b is where you would like * normalised data set to end x is the value you are trying to normalise * a + (x-A)*(b-a)/(B-A) */ float pitch = 0.5f + (Ship.SHIP_VELOCITY - 0) * (2.0f - 0.5f) / (Ship.SHIP_MAXVELOCITY - 0); if (Stardust3d.DEEPDEBUG) System.out.println("enginepitch " + pitch); SoundManager.changeEnginePitch(pitch); if (input.isKeyPressed(Keys.DPAD_LEFT) || input.isKeyPressed(Keys.A)) Ship.yawAngle += turnSpeed; if (input.isKeyPressed(Keys.DPAD_RIGHT) || input.isKeyPressed(Keys.D)) Ship.yawAngle -= turnSpeed; if (input.isKeyPressed(Keys.DPAD_UP) || input.isKeyPressed(Keys.W)) Ship.pitchAngle += turnSpeed; if (input.isKeyPressed(Keys.DPAD_DOWN) || input.isKeyPressed(Keys.S)) Ship.pitchAngle -= turnSpeed; if (input.isKeyPressed(Keys.SPACE)) simulation.shot(); if (input.isKeyPressed(Keys.Q)) simulation.missile(); if (input.isKeyPressed(Keys.E)) simulation.repair(); /* * if (input.isKeyPressed(Keys.A)) Ship.SHIP_VELOCITY += * Ship.SHIP_ACCELERATION; if (Ship.SHIP_VELOCITY > * Ship.SHIP_MAXVELOCITY) Ship.SHIP_VELOCITY = Ship.SHIP_MAXVELOCITY; if * (input.isKeyPressed(Keys.Z)) Ship.SHIP_VELOCITY -= * Ship.SHIP_ACCELERATION; if (Ship.SHIP_VELOCITY < 0) * Ship.SHIP_VELOCITY = 0; if (input.isKeyPressed(Keys.S)) * Ship.SHIP_VELOCITY = 0; */ if (input.isKeyPressed(Keys.R)) { Ship.SHIP_POWER = 1f * delta; } else if (input.isKeyPressed(Keys.F)) { Ship.SHIP_POWER = -1f * delta; } else { Ship.SHIP_POWER = 0; Ship.SHIP_ACCELERATION = 0; } Ship.SHIP_ACCELERATION += Ship.SHIP_POWER; if (Ship.SHIP_ACCELERATION > Ship.SHIP_MAXACCELERATION) Ship.SHIP_ACCELERATION = Ship.SHIP_MAXACCELERATION; if (Ship.SHIP_VELOCITY < 0) Ship.SHIP_VELOCITY = 0; if (Ship.SHIP_VELOCITY > Ship.SHIP_MAXVELOCITY) Ship.SHIP_VELOCITY = Ship.SHIP_MAXVELOCITY; }
From source file:de.cubicvoxel.openspacebox.input.KeyboardInputHandler.java
License:Open Source License
@Override void handleInput(float deltaTime) { Input input = Gdx.input; float x = 0, y = 0; if (input.isKeyPressed(Input.Keys.A)) x -= 1.0f;/*from w w w .j av a 2 s.com*/ if (input.isKeyPressed(Input.Keys.D)) x += 1.0f; if (input.isKeyPressed(Input.Keys.W)) y += 1.0f; if (input.isKeyPressed(Input.Keys.S)) y -= 1.0f; if (x != 0 || y != 0) postMoveInputEventWithClampedInput(x, y, deltaTime); if (input.isKeyJustPressed(Input.Keys.BACKSPACE)) inputEventBus.post(new BackInputEvent(deltaTime)); }