Java Code Examples for com.badlogic.gdx.Input

The following are top voted examples for showing how to use com.badlogic.gdx.Input. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: ggvm   File: PCMenu.java   Source Code and License 6 votes vote down vote up
@Override
public boolean keyDown(int keycode) {
    if (currentMenuOption != null) {
        switch(keycode) {
            case Input.Keys.DOWN:
                cursorDown();
                return true;
            case Input.Keys.UP:
                cursorUp();
                return true;
            case Input.Keys.ENTER:
                menuAction();
                return true;
            case Input.Keys.ESCAPE:
                dismissMenu();
                return true;
            default:
                returnToTitleOption.resetVisited();
                break;
        }
    }
    return false;
}
 
Example 2
Project: odb-artax   File: CameraFollowSystem.java   Source Code and License 6 votes vote down vote up
@Override
protected void process(E e) {
    if ( Gdx.input.isKeyJustPressed(Input.Keys.F9) ) lockCamera = !lockCamera;

    if ( lockCamera) return;
    if (e.wallSensorOnFloor() || e.wallSensorOnPlatform()) {
        float newTargetY = myAnimRenderSystem.roundToPixels(e.posY());
        if (targetY != newTargetY) {
            sourceY = (int) cameraSystem.camera.position.y;
            targetY = (int) newTargetY;
            cooldown = 0f;
        }
    }
    if (cooldown <= 1F) {
        cooldown += world.delta*2f;
        if (cooldown > 1f) cooldown = 1f;
        cameraSystem.camera.position.y = myAnimRenderSystem.roundToPixels(Interpolation.pow2Out.apply(sourceY,targetY, cooldown));        }
    cameraSystem.camera.position.x = myAnimRenderSystem.roundToPixels(e.posX());
    cameraSystem.camera.update();

    float maxDistance = (Gdx.graphics.getHeight() / G.CAMERA_ZOOM) * 0.5F * 0.6f;
    if (  e.posY() < cameraSystem.camera.position.y - maxDistance) {
        cameraSystem.camera.position.y = e.posY() + maxDistance;
        cameraSystem.camera.update();
    }
}
 
Example 3
Project: PixelDungeonTC   File: Window.java   Source Code and License 6 votes vote down vote up
@Override
public void onSignal( NoosaInputProcessor.Key<GameAction> key ) {
	if (key.pressed) {
		switch (key.code) {
		case Input.Keys.BACK:
			onBackPressed();			
			break;
		case Input.Keys.MENU:
			onMenuPressed();			
			break;
		}
	}


	Game.instance.getInputProcessor().cancelKeyEvent();
}
 
Example 4
Project: drc-sim-client   File: StageConfigInput.java   Source Code and License 6 votes vote down vote up
public static String getInputDisplayName(int type, ConfigKeymap config, String key) {
    ConfigKeymap.Input input = config.getInput(key, -1, -1, -1);
    if (input.getInput() < 0)
        return "NONE";
    if (type == KEYBOARD && input.getInput() <= 255)
        return Input.Keys.toString(input.getInput());
    else if (type == CONTROLLER) {
        if (input.getType() == ConfigKeymap.Input.TYPE_AXIS)
            return String.format(Locale.US, "Axis %d %s", input.getInput(),
                    input.getExtra() == 0 ? "negative" : "positive");
        else if (input.getType() == ConfigKeymap.Input.TYPE_POV) {
            String pov = String.valueOf(input.getExtra());
            for (PovDirection dir : PovDirection.values())
                if (dir.ordinal() == input.getExtra())
                    pov = dir.name();
            return String.format(Locale.US, "D-pad %d %s", input.getInput(), pov);
        }
        else if (input.getType() == ConfigKeymap.Input.TYPE_BUTTON)
            return String.format(Locale.US, "Button %d", input.getInput());
    }
    return String.format(Locale.US, "%d", input.getInput());
}
 
Example 5
Project: conquest   File: ConquestCamera.java   Source Code and License 6 votes vote down vote up
public void handle() {
    if (Gdx.input.isKeyPressed(Input.Keys.W) || Gdx.input.isKeyPressed(Input.Keys.UP)) {
        translate(0, 10);
    }
    if (Gdx.input.isKeyPressed(Input.Keys.A) || Gdx.input.isKeyPressed(Input.Keys.LEFT)) {
        translate(-10, 0);
    }
    if (Gdx.input.isKeyPressed(Input.Keys.S) || Gdx.input.isKeyPressed(Input.Keys.DOWN)) {
        translate(0, -10);
    }
    if (Gdx.input.isKeyPressed(Input.Keys.D) || Gdx.input.isKeyPressed(Input.Keys.RIGHT)) {
        translate(10, 0);
    }
    if (Gdx.input.isKeyPressed(Input.Keys.I)) {
        zoom -= 0.05;
    }
    if (Gdx.input.isKeyPressed(Input.Keys.O)) {
        zoom += 0.05;
    }

    zoom = MathUtils.clamp(zoom, 0.5f, 2);
    position.x = MathUtils.clamp(position.x, left, right);
    position.y = MathUtils.clamp(position.y, bottom, top);
}
 
Example 6
Project: PixelDungeonTC   File: Scene.java   Source Code and License 6 votes vote down vote up
public void create() {
	Gdx.input.setCatchBackKey(true);
	Game.instance.getInputProcessor().addKeyListener(keyListener = new Signal.Listener<NoosaInputProcessor.Key>() {
		@Override
		public void onSignal(NoosaInputProcessor.Key key) {
			if (Game.instance != null && key.pressed) {
				switch (key.code) {
					case Input.Keys.BACK:
					case Input.Keys.ESCAPE:
						onBackPressed();
						break;
					case Input.Keys.MENU:
					case Input.Keys.F5:
						onMenuPressed();
						break;
				}
			}
		}
	});
}
 
Example 7
Project: SpaceChaos   File: InputManager.java   Source Code and License 6 votes vote down vote up
@Override
public boolean keyDown(int keycode) {
    if (keycode == Input.Keys.A || keycode == Input.Keys.LEFT) {
        left = true;
    } else if (keycode == Input.Keys.D || keycode == Input.Keys.RIGHT) {
        right = true;
    } else if (keycode == Input.Keys.W || keycode == Input.Keys.UP) {
        up = true;
    } else if (keycode == Input.Keys.S || keycode == Input.Keys.DOWN) {
        down = true;
    } else if (keycode == Input.Keys.ESCAPE) {
        escape = true;
    } else if (keycode == Input.Keys.SPACE) {
        space = true;
    }
    return true;
}
 
Example 8
Project: SpaceChaos   File: InputManager.java   Source Code and License 6 votes vote down vote up
@Override
public boolean keyUp(int keycode) {
    if (keycode == Input.Keys.A || keycode == Input.Keys.LEFT) {
        left = false;
    } else if (keycode == Input.Keys.D || keycode == Input.Keys.RIGHT) {
        right = false;
    } else if (keycode == Input.Keys.W || keycode == Input.Keys.UP) {
        up = false;
    } else if (keycode == Input.Keys.S || keycode == Input.Keys.DOWN) {
        down = false;
    } else if (keycode == Input.Keys.ESCAPE) {
        escape = false;
    } else if (keycode == Input.Keys.SPACE) {
        space = false;
    }

    return true;
}
 
Example 9
Project: EarthInvadersGDX   File: MenuScreen.java   Source Code and License 6 votes vote down vote up
@Override
public void tick() {
    if (play.clicked) {
        GameScreen gs = new GameScreen();
        Game.setCurrentScreen(gs);
        play.clicked = false;
    }
    if (music.released) {
        music.setSprite(Game.musicMuted() ? musicUnmuted : musicMuted);
        music.setScale(4f);
        Game.setMuted(!Game.musicMuted());
        Game.save();
        music.released = false;
    }
    play.tick();
    music.tick();

    if (Gdx.input.isKeyJustPressed(Input.Keys.BACK)) {
        Gdx.app.exit();
    }
}
 
Example 10
Project: summer17-android   File: PlayScreen.java   Source Code and License 6 votes vote down vote up
public void handleInput(float dt) {
    //if our user is holding down mouse move our camer
    if (((Gdx.input.isKeyJustPressed(Input.Keys.UP) || controller.isUpPressed()) && hero.b2body.getLinearVelocity().y == 0)) {
        hero.b2body.applyLinearImpulse(new Vector2(0, 3f), hero.b2body.getWorldCenter(),
                true);
    }

    isObjectHit = worldContactListener.getIsObjectTouched();
    if(isObjectHit == NoObjectionGame.MUSHROOM){
        gameWin = true;
    }

    //temp climbing
    if (((Gdx.input.isKeyJustPressed(Input.Keys.DOWN) || controller.isDownPressed() && hero.b2body.getLinearVelocity().y < 1) && isObjectHit == 1000)) {
        hero.b2body.applyLinearImpulse(new Vector2(0, 2f), hero.b2body.getWorldCenter(),
                true);
    }
    if ((Gdx.input.isKeyPressed(Input.Keys.RIGHT) || controller.isRightPressed())
            && hero.b2body.getLinearVelocity().x <= 2) {
        hero.b2body.applyLinearImpulse(new Vector2(0.1f, 0), hero.b2body.getWorldCenter(), true);
    }
    if ((Gdx.input.isKeyPressed(Input.Keys.LEFT) || controller.isLeftPressed())
            && hero.b2body.getLinearVelocity().x >= -2) {
        hero.b2body.applyLinearImpulse(new Vector2(-0.1f, 0), hero.b2body.getWorldCenter(), true);
    }
}
 
Example 11
Project: Polymorph   File: GameScreen.java   Source Code and License 6 votes vote down vote up
@Override
public boolean keyDown(int keycode) {
    switch (keycode) {
    case Input.Keys.NUMPAD_4:
        shapeHeld = Shape.TRIANGLE;
        break;
    case Input.Keys.NUMPAD_5:
        shapeHeld = Shape.CIRCLE;
        break;
    case Input.Keys.NUMPAD_6:
        shapeHeld = Shape.SQUARE;
        break;
    default:
        return false;
    }
    return true;
}
 
Example 12
Project: Polymorph   File: GameScreen.java   Source Code and License 6 votes vote down vote up
@Override
public boolean keyUp(int keycode) {
    if (shapeHeld == null) {
        return false;
    }

    switch (keycode) {
    case Input.Keys.NUMPAD_7:
        polyGame.getPlayer().morph(shapeHeld, ShapeColor.values()[0].color);
        break;
    case Input.Keys.NUMPAD_8:
        polyGame.getPlayer().morph(shapeHeld, ShapeColor.values()[1].color);
        break;
    case Input.Keys.NUMPAD_9:
        polyGame.getPlayer().morph(shapeHeld, ShapeColor.values()[2].color);
        break;
    }
    return true;
}
 
Example 13
Project: gdx-cclibs   File: LiveWallpaperWrapper.java   Source Code and License 6 votes vote down vote up
private void handleTouch() {
    Input input = Gdx.input;

    if (input.justTouched()) {
        swipeXStart = input.getX(0);
    }

    if (input.isTouched(0) && !input.isTouched(1)) { //only one finger down and swiping
        //Measure swipe distance since last frame and apply. Then reset for next frame.
        float swipeDelta = swipeXStart - input.getX();
        xOffsetFakeTarget += (swipeDelta / density) / DIP_TO_XOFFSET_FAKE_RATIO;
        if (xOffsetFakeTarget < 0)
            xOffsetFakeTarget = 0;
        else if (xOffsetFakeTarget > 1)
            xOffsetFakeTarget = 1;
        swipeXStart = input.getX();
    }
}
 
Example 14
Project: ExamensArbeteTD   File: InputHandler.java   Source Code and License 6 votes vote down vote up
public void setCameraDirection() {
	if (Gdx.input.isKeyPressed(Input.Keys.W)) {
		yAxis = 1;
	} else if (Gdx.input.isKeyPressed(Input.Keys.S)) {
		yAxis = -1;
	} else {
		yAxis = 0;
	}

	if (Gdx.input.isKeyPressed(Input.Keys.D)) {
		xAxis = 1;
	} else if (Gdx.input.isKeyPressed(Input.Keys.A)) {
		xAxis = -1;
	} else {
		xAxis = 0;
	}
	_inputHandler.setCamDir(xAxis, yAxis);
}
 
Example 15
Project: school-game   File: InputManager.java   Source Code and License 6 votes vote down vote up
/**
 * Sollte nur von Menüs aufgerufen werden.
 * Gibt die der Taste entsprechende Aktion zurück.
 *
 * @param keycode der Tastencode der Taste
 * @return die Aktion, die mit dieser Taste verknüpft ist
 */
public static Action checkMenuAction(int keycode)
{
    if (keycode == Input.Keys.UP || keycode == Input.Keys.W)
    {
        return Action.MOVE_UP;
    }

    if (keycode == Input.Keys.DOWN || keycode == Input.Keys.S)
    {
        return Action.MOVE_DOWN;
    }

    if (keycode == Input.Keys.ENTER || keycode == Input.Keys.SPACE)
    {
        return Action.MENU_SELECT;
    }

    return Action.UNKNOWN;
}
 
Example 16
Project: school-game   File: InputManager.java   Source Code and License 6 votes vote down vote up
/**
 * Wird für Polling benutzt.
 * Fragt in jedem Frame ab, ob eine Taste im Moment gedrückt ist.
 *
 * @param action die Aktion, die abgefragt werden soll
 * @return true wenn diese Aktion im Moment aktiv ist
 */
public static boolean checkActionActive(Action action)
{
    switch (action)
    {
        case MOVE_UP:
            return Gdx.input.isKeyPressed(Input.Keys.UP) || Gdx.input.isKeyPressed(Input.Keys.W) || checkController(action);

        case MOVE_DOWN:
            return Gdx.input.isKeyPressed(Input.Keys.DOWN) || Gdx.input.isKeyPressed(Input.Keys.S) || checkController(action);

        case MOVE_LEFT:
            return Gdx.input.isKeyPressed(Input.Keys.LEFT) || Gdx.input.isKeyPressed(Input.Keys.A) || checkController(action);

        case MOVE_RIGHT:
            return Gdx.input.isKeyPressed(Input.Keys.RIGHT) || Gdx.input.isKeyPressed(Input.Keys.D) || checkController(action);

        case RUN:
            return Gdx.input.isKeyPressed(Input.Keys.SHIFT_LEFT) || Gdx.input.isKeyPressed(Input.Keys.SHIFT_RIGHT) || checkController(action);

        default:
            break;
    }

    return false;
}
 
Example 17
Project: skycity   File: StartScreen.java   Source Code and License 6 votes vote down vote up
@Override
public void render(float delta) {
    cleanScreen();
    skyCity.batch.begin();
    skyCity.batch.setColor(1, 1, 1, alpha);
    skyCity.batch.draw(logoTexture, Config.SCREEN_WIDTH / 2 - logoTexture.getWidth() / 2, Config.SCREEN_HEIGHT / 2 - logoTexture.getHeight() / 2);
    skyCity.batch.end();

    deltaSum += delta;
    if (deltaSum > REMAIN) {
        skyCity.setScreen(new GameScreen(skyCity));
    } else {
        alpha = gradientAlpha(deltaSum);
    }

    if (Gdx.input.isKeyPressed(Input.Keys.ANY_KEY) && deltaSum >1) {
        skyCity.setScreen(new GameScreen(skyCity));
    }

}
 
Example 18
Project: savethebunny   File: StoryScreenController.java   Source Code and License 5 votes vote down vote up
@Override
public boolean keyUp(int keycode) {
    if (keycode == Input.Keys.BACK) {
        if (mode == MODE_PHASE) {
            ((MerlinGame) game).loadMenuScreen();
        } else {
            showSelectPhase();
        }
    }
    return false;
}
 
Example 19
Project: ShootMe   File: TestScreen.java   Source Code and License 5 votes vote down vote up
@Override
public boolean keyUp(int keycode) {

    switch (keycode) {
        case Input.Keys.LEFT:
        case Input.Keys.RIGHT:
        case Input.Keys.A:
        case Input.Keys.D:

            imagePosMovement.set(0, imagePosMovement.y);

            if(SM.input.isKeyPressed(Input.Keys.RIGHT) ||SM.input.isKeyPressed(Input.Keys.D))
                imagePosMovement.set(+7, imagePosMovement.y);

            if(SM.input.isKeyPressed(Input.Keys.LEFT) ||SM.input.isKeyPressed(Input.Keys.A))
                imagePosMovement.set(-7, imagePosMovement.y);

            break;
        case Input.Keys.DOWN:
        case Input.Keys.UP:
        case Input.Keys.W:
        case Input.Keys.S:

            imagePosMovement.set(imagePosMovement.x, 0);

            if(SM.input.isKeyPressed(Input.Keys.DOWN) ||SM.input.isKeyPressed(Input.Keys.S))
                imagePosMovement.set(-7, imagePosMovement.y);

            if(SM.input.isKeyPressed(Input.Keys.UP) ||SM.input.isKeyPressed(Input.Keys.W))
                imagePosMovement.set(+7, imagePosMovement.y);
            break;
    }

    return false;
}
 
Example 20
Project: ggvm   File: PCMenu.java   Source Code and License 5 votes vote down vote up
@Override
public boolean keyDown(int keycode) {
    Gdx.app.log(getClass().getSimpleName(), "keyDown(" + keycode + ")");
    if (keycode != Input.Keys.ESCAPE) {
        inputProcessor.getButtonIndexToKeyCode().inverse().forcePut(keycode, currentMenuOption.buttonIndex);
        menu = topLevelMenu;
        menu.activate();
    }
    return false;
}
 
Example 21
Project: ggvm   File: KeyboardInputProcessor.java   Source Code and License 5 votes vote down vote up
public void autoConfigure() {
    Array<Controller> controllers = Controllers.getControllers();
    if (controllers.size > 0) {
        Controller controller = controllers.get(0);
        if (isXbox360Controller(controller.getName())) {
            buttonIndexToButton.put(com.gradualgames.ggvm.Controller.Buttons.A, XBOX_360_A);
            buttonIndexToButton.put(com.gradualgames.ggvm.Controller.Buttons.B, XBOX_360_X);
            buttonIndexToButton.put(com.gradualgames.ggvm.Controller.Buttons.SELECT, XBOX_360_LEFT_SHOULDER);
            buttonIndexToButton.put(com.gradualgames.ggvm.Controller.Buttons.START, XBOX_360_START);
        } else if (controller.getName().equals(RETRO_USB_NAME)) {
            buttonIndexToButton.put(com.gradualgames.ggvm.Controller.Buttons.A, RETRO_USB_A);
            buttonIndexToButton.put(com.gradualgames.ggvm.Controller.Buttons.B, RETRO_USB_B);
            buttonIndexToButton.put(com.gradualgames.ggvm.Controller.Buttons.SELECT, RETRO_USB_SELECT);
            buttonIndexToButton.put(com.gradualgames.ggvm.Controller.Buttons.START, RETRO_USB_START);
            actualAxisToAxisCode.put(Axis.X, 1);
            actualAxisToAxisCode.put(Axis.Y, 0);
        }
    }
    buttonIndexToKeyCode.put(com.gradualgames.ggvm.Controller.Buttons.A, Input.Keys.F);
    buttonIndexToKeyCode.put(com.gradualgames.ggvm.Controller.Buttons.B, Input.Keys.D);
    buttonIndexToKeyCode.put(com.gradualgames.ggvm.Controller.Buttons.SELECT, Input.Keys.A);
    buttonIndexToKeyCode.put(com.gradualgames.ggvm.Controller.Buttons.START, Input.Keys.S);
    buttonIndexToKeyCode.put(com.gradualgames.ggvm.Controller.Buttons.UP, Input.Keys.UP);
    buttonIndexToKeyCode.put(com.gradualgames.ggvm.Controller.Buttons.RIGHT, Input.Keys.RIGHT);
    buttonIndexToKeyCode.put(com.gradualgames.ggvm.Controller.Buttons.DOWN, Input.Keys.DOWN);
    buttonIndexToKeyCode.put(com.gradualgames.ggvm.Controller.Buttons.LEFT, Input.Keys.LEFT);
}
 
Example 22
Project: ggvm   File: KeyboardInputProcessor.java   Source Code and License 5 votes vote down vote up
@Override
public boolean keyDown(int keycode) {
    if (buttonIndexToKeyCode.containsValue(keycode)) {
        int buttonIndex = buttonIndexToKeyCode.inverse().get(keycode).ordinal();
        ggvm.setButtonState(buttonIndex, true);
        if (buttonToButtonUpIndex.containsKey(buttonIndex)) {
            ggvm.setButtonState(buttonToButtonUpIndex.get(buttonIndex), false);
        }
    }
    if (keycode == Input.Keys.ESCAPE) {
        stopGGVmAndActivateMenu();
    }
    return false;
}
 
Example 23
Project: libgdx_ui_editor   File: MainWindow.java   Source Code and License 5 votes vote down vote up
@Override
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
    if (button == Input.Buttons.RIGHT) {
        startX = x;
        startY = y;
        selectedGroup.clearAllActor();
        selectedGroup.setVisible(true);
        return true;
    }
    return super.touchDown(event, x, y, pointer, button);
}
 
Example 24
Project: Planet-Generator   File: Scene.java   Source Code and License 5 votes vote down vote up
@Override
public boolean keyDown(int keycode) {
    switch(keycode) {
        case Input.Keys.ESCAPE:
            Gdx.app.exit();
            return true;

        case Input.Keys.F12:
            takeScreenshot();
            return true;
    }

    return false;
}
 
Example 25
Project: feup-lpoo-armadillo   File: GameInputPoller.java   Source Code and License 5 votes vote down vote up
/**
 * Game Controller's constructor.
 *
 * @param model The current game being played by the USer.
 */
public GameInputPoller(GameModel model) {
    this.model = model;

    if (!(accelerometerAvailable = Gdx.input.isPeripheralAvailable(Input.Peripheral.Accelerometer)))
        System.err.println("Accelerometer unavailable");
}
 
Example 26
Project: feup-lpoo-armadillo   File: GameInputPoller.java   Source Code and License 5 votes vote down vote up
/**
 * Decide what to do when the keys are pressed.
 *
 * @param delta The time elapsed since the last update
 */
private void pollKeys(float delta) {
    if (Gdx.input.isKeyPressed(Input.Keys.LEFT)) {
        model.getBallModel().rotate(delta);
    } else if (Gdx.input.isKeyPressed(Input.Keys.RIGHT)) {
        model.getBallModel().rotate(delta * -1);
    }

    if (Gdx.input.isKeyJustPressed(Input.Keys.SPACE)) {
        model.getBallModel().jump();
    } else if (Gdx.input.isKeyJustPressed(Input.Keys.P)) {
        model.togglePause();
    }
}
 
Example 27
Project: libgdx-learnlib   File: WorldController.java   Source Code and License 5 votes vote down vote up
private void handleDebugInput(float deltaTime) {
    if (Gdx.app.getType() != Application.ApplicationType.Desktop) {
        return;
    }

    // Camera controls (move)
    if (!cameraHelper.hasTarget(level.bunnyHead)) {
        float camMoveSpeed = 5 * deltaTime;
        float camMoveSpeedAccelerationFactor = 5;
        if (Gdx.input.isKeyPressed(Input.Keys.SHIFT_LEFT))
            camMoveSpeed *= camMoveSpeedAccelerationFactor;
        if (Gdx.input.isKeyPressed(Input.Keys.LEFT))
            moveCamera(-camMoveSpeed, 0);
        if (Gdx.input.isKeyPressed(Keys.RIGHT))
            moveCamera(camMoveSpeed, 0);
        if (Gdx.input.isKeyPressed(Keys.UP))
            moveCamera(0, camMoveSpeed);
        if (Gdx.input.isKeyPressed(Keys.DOWN))
            moveCamera(0, -camMoveSpeed);
        if (Gdx.input.isKeyPressed(Keys.BACKSPACE))
            cameraHelper.setPosition(0, 0);
    }

    // Camera controls (zoom)
    float camZoomSpeed = 1 * deltaTime;
    float camZoomSpeedAccelerationFactor = 5;
    if(Gdx.input.isKeyPressed(Keys.SHIFT_RIGHT))
        camZoomSpeed *= camZoomSpeedAccelerationFactor;
    if(Gdx.input.isKeyPressed(Keys.COMMA))
        cameraHelper.addZoom(camZoomSpeed);
    if(Gdx.input.isKeyPressed(Keys.PERIOD))
        cameraHelper.addZoom(-camZoomSpeed);
    if(Gdx.input.isKeyPressed(Keys.SLASH))
        cameraHelper.setZoom(1);
}
 
Example 28
Project: PixelDungeonTC   File: PDInputProcessor.java   Source Code and License 5 votes vote down vote up
@Override
protected GameAction keycodeToGameAction(int keycode) {
	switch (keycode) {
		case Input.Keys.BACK:
		case Input.Keys.ESCAPE:
			return GameAction.BACK;
		
	}
	return null;
}
 
Example 29
Project: Parasites-of-HellSpace   File: LoadingScreen.java   Source Code and License 5 votes vote down vote up
private void update()
{
    if(!loaded)
        System.out.println("Progress: " + AssetLoader.assetManager.getProgress());

    if(AssetLoader.assetManager.update())
        loaded = true;

    if(Gdx.input.isKeyPressed(Input.Keys.SPACE) && loaded)
        game.setScreen(new GameScreen());
}
 
Example 30
Project: drc-sim-client   File: StageConnect.java   Source Code and License 5 votes vote down vote up
@Override
public boolean keyDown(int keyCode) {
	if (keyCode == Input.Keys.ENTER) {
		Gdx.input.setOnscreenKeyboardVisible(false);
		connect();
	}
	return super.keyDown(keyCode);
}
 
Example 31
Project: drc-sim-client   File: Stage.java   Source Code and License 5 votes vote down vote up
@Override
public boolean keyDown(int keyCode) {
	// Back Button
	if (keyCode == Input.Keys.BACK || keyCode == Input.Keys.ESCAPE) {
		this.onBackButtonPressed();
		return true;
	}
	// Fullscreen Button
	if (Gdx.input.isKeyPressed(Input.Keys.F11)) {
		toggleFullscreen();
		return true;
	}
	return false;
}
 
Example 32
Project: conquest   File: Manager.java   Source Code and License 5 votes vote down vote up
@Override
public boolean keyUp(InputEvent event, int keycode) {
    if (!Manager.isVisible()) return false;
    if (Input.Keys.Q == keycode) {
        send();
    }
    if (Input.Keys.E == keycode || Input.Keys.ENTER == keycode) {
        sendMax();
    }

    return false;
}
 
Example 33
Project: GDX-Engine   File: TiledScene.java   Source Code and License 5 votes vote down vote up
/**
	 * Update the camera using the default setting of engine so you can control
	 * the camera by keyboard like magnification or translation
	 * 
	 * @param gameTime
	 */
	public void updateCamera(int key) {

		if (!enableDefaultCameraController)
			return;
		if (key ==(Input.Keys.Z)) {
			mainCamera.zoom += 0.02;
		}
		if (key==(Input.Keys.X)) {
			mainCamera.zoom -= 0.02;
		}
		if (key==(Input.Keys.A)) {
//			if (mainCamera.position.x > -WORLD_WIDTH / 2)
				mainCamera.translate(-10, 0, 0);
		}
		if (key==(Input.Keys.D)) {
//			if (mainCamera.position.x < WORLD_WIDTH / 2)
				mainCamera.translate(10, 0, 0);
		}
		if (key==(Input.Keys.S)) {
//			if (mainCamera.position.y > -WORLD_HEIGHT / 2)
				mainCamera.translate(0, -10, 0);
		}
		if (key==(Input.Keys.W)) {
//			if (mainCamera.position.y < WORLD_HEIGHT / 2)
				mainCamera.translate(0, 10, 0);
		}
		if (key==(Input.Keys.C)) {
			mainCamera.rotate(-rotationSpeed, 0, 0, 1);
		}
		if (key==(Input.Keys.V)) {
			mainCamera.rotate(rotationSpeed, 0, 0, 1);
		}
	}
 
Example 34
Project: GDX-Engine   File: TestCamera.java   Source Code and License 5 votes vote down vote up
private void handleInput() {
        if(Gdx.input.isKeyPressed(Input.Keys.Z)) {
                cam.zoom += 0.02;
        }
        if(Gdx.input.isKeyPressed(Input.Keys.X)) {
                cam.zoom -= 0.02;
        }
        if(Gdx.input.isKeyPressed(Input.Keys.A)) {
                if (cam.position.x > -WORLD_WIDTH/2)
                        cam.translate(-10, 0, 0);
        }
        if(Gdx.input.isKeyPressed(Input.Keys.D)) {
                if (cam.position.x < WORLD_WIDTH/2)
                        cam.translate(10, 0, 0);
        }
        if(Gdx.input.isKeyPressed(Input.Keys.S)) {
                if (cam.position.y > -WORLD_HEIGHT/2)
                        cam.translate(0, -10, 0);
        }
        if(Gdx.input.isKeyPressed(Input.Keys.W)) {
                if (cam.position.y < WORLD_HEIGHT/2)
                        cam.translate(0, 10, 0);
        }
        if(Gdx.input.isKeyPressed(Input.Keys.C)) {
                cam.rotate(-rotationSpeed, 0, 0, 1);
        }
        if(Gdx.input.isKeyPressed(Input.Keys.V)) {
                cam.rotate(rotationSpeed, 0, 0, 1);
        }
}
 
Example 35
Project: INFSEN01-2   File: GDXMouse.java   Source Code and License 5 votes vote down vote up
public IOption<Point> click() {
    if(Gdx.input.isButtonPressed(Input.Buttons.LEFT)) {
        return new Some<Point>(new Point(
            (float)Gdx.input.getX(),
            (float)Gdx.input.getY()));
    }
    else {
        return new None<Point>();
    }
}
 
Example 36
Project: INFSEN01-2   File: DefaultUpdateVisitor.java   Source Code and License 5 votes vote down vote up
@Override
public void updateButton(Button element, Float dt) {
    if (Gdx.input.isButtonPressed(Input.Buttons.LEFT)) {
        if (element.
                contains(new Point(
                        (float) Gdx.input.getX(),
                        (float) Gdx.input.getY()
                ))) {
            element.color = Color.BLUE;
            element.action.run();
        }
    } else {
        element.color = Color.WHITE;
    }
}
 
Example 37
Project: INFSEN01-2   File: DefaultUpdateVisitor.java   Source Code and License 5 votes vote down vote up
@Override
public void updateButton(Button element, Float dt) {
    if (Gdx.input.isButtonPressed(Input.Buttons.LEFT)) {
        if (element.
                contains(new Point(
                        (float) Gdx.input.getX(),
                        (float) Gdx.input.getY()
                ))) {
            element.color = Color.BLUE;
            element.action.run();
        }
    } else {
        element.color = Color.WHITE;
    }
}
 
Example 38
Project: My-game-StarComm   File: Hero.java   Source Code and License 5 votes vote down vote up
public void update() {
    if (Gdx.input.isKeyPressed(Input.Keys.UP)) {
        position.y += speed;
        if (position.y > 720) position.y = -60;
    }
    if (Gdx.input.isKeyPressed(Input.Keys.LEFT)) {
        position.x -= speed;
        if (position.x < 0) position.x = 0;
    }
    if (Gdx.input.isKeyPressed(Input.Keys.RIGHT)) {
        position.x += speed;
        if (position.x > 1200) position.x = 1200;
    }
    if (Gdx.input.isKeyPressed(Input.Keys.DOWN)) {
        position.y -= speed;
        if (position.y < -60) position.y = 720;
    }
    if(Gdx.input.isKeyPressed(Input.Keys.SPACE)) {
        fireCounter++;
        if(fireCounter > fireRate) {
            fireCounter = 0;
            for (int i = 0; i < MyGdxGame.bullets.length; i++) {
                if(!MyGdxGame.bullets[i].isActive()) {
                    MyGdxGame.bullets[i].setup(position.x, position.y);
                    break;
                }
            }
        }
    }
}
 
Example 39
Project: GangsterSquirrel   File: SplashScreen.java   Source Code and License 5 votes vote down vote up
/**
 * Handle the input
 * @param deltaTime the time between the current and the last frame
 */
private void handleInput(float deltaTime) {
    if (Gdx.input.isKeyJustPressed(Input.Keys.SPACE) || Gdx.input.isKeyJustPressed(Input.Keys.ENTER)) {
        game.setScreen(new MainMenu(game));
    }

    if (Gdx.input.isKeyJustPressed(Input.Keys.ESCAPE)) {
        game.exitApplication("User exited application from the splash screen");
    }
}
 
Example 40
Project: SpaceChaos   File: InputManager.java   Source Code and License 5 votes vote down vote up
@Override
public boolean touchDown(int x, int y, int pointer, int button) {
    if (button == Input.Buttons.LEFT) {
        leftMouse = true;
    } else if (button == Input.Buttons.RIGHT) {
        rightMouse = true;
    }
    return false;
}