List of usage examples for com.badlogic.gdx.math Vector3 Vector3
public Vector3(float x, float y, float z)
From source file:airfoil.etc.Controller.java
License:Open Source License
@Override public boolean touchDragged(int x, int y, int pointer) { final Vector3 delta; if (this.button) { delta = new Vector3(x, y, 0).sub(this.last).mul(0.5f); this.last.set(x, y, 0); } else {/*from w w w . ja v a 2 s . co m*/ delta = new Vector3(0, x, y).sub(this.last).mul(0.5f); this.last.set(0, x, y); } final Quaternion rotation; if (this.button) { rotation = new Quaternion(YA, -delta.x).mul(new Quaternion(YA, delta.y)); } else { rotation = new Quaternion(ZA, delta.z).mul(new Quaternion(ZA, -delta.y)); } this.rotation.mul(new Matrix4(rotation)); this.reinit(); return true; }
From source file:at.juggle.games.counting.screens.CountingGameScreen.java
License:Apache License
private void handleInput() { if (Gdx.input.isKeyJustPressed(Input.Keys.BACK) || Gdx.input.isKeyJustPressed(Input.Keys.ESCAPE)) { parentGame.getScreenManager().setCurrentState(ScreenManager.ScreenState.Menu); } else if (Gdx.input.isKeyJustPressed(Input.Keys.ANY_KEY)) { // model.resetGameState(); }/* w w w . j ava 2s.c o m*/ if (Gdx.input.justTouched()) { Vector3 touchWorldCoords = cam.unproject(new Vector3(Gdx.input.getX(), Gdx.input.getY(), 1)); CountingGameModel.InputResult inputResult = model.handleTouch(touchWorldCoords); if (inputResult == CountingGameModel.InputResult.Change) { model.resetGameState(); } else if (inputResult == CountingGameModel.InputResult.Button) { // Todo .. play sound parentGame.speakOut(model.getNumberOfSprites() + ""); // parentGame.getSoundManager().playEvent(model.getNumberOfSprites()+""); } else if (inputResult == CountingGameModel.InputResult.Pop) { xplode.setPosition(touchWorldCoords.x, touchWorldCoords.y); xplode.reset(); String event = "blob0" + ((int) (Math.random() * 4) + 1); parentGame.getSoundManager().playEvent(event); } } }
From source file:at.juggle.games.counting.screens.MenuScreen.java
License:Apache License
private void handleInput() { // touch// w w w . ja v a 2 s .co m if (Gdx.input.justTouched()) { CountingGame.numberOfBalloons = getNumberOfBallons(); Vector3 touchWorldCoords = cam.unproject(new Vector3(Gdx.input.getX(), Gdx.input.getY(), 1)); // find the menu item .. if (startMengen.getBoundingRectangle().contains(touchWorldCoords.x, touchWorldCoords.y)) { parentGame.getScreenManager().setCurrentState(ScreenManager.ScreenState.CountingGame); } else if (startZaehlen.getBoundingRectangle().contains(touchWorldCoords.x, touchWorldCoords.y)) { parentGame.getScreenManager().setCurrentState(ScreenManager.ScreenState.SortingGame); } for (int i = 2; i < menuStrings.length; i++) { if (touchWorldCoords.x > offsetLeft) { float pos = CountingGame.GAME_HEIGHT - offsetTop - i * offsetY; if (touchWorldCoords.y < pos && touchWorldCoords.y > pos - menuFont.getLineHeight()) { // it's there if (menuStrings[i].equals(ende)) { Gdx.app.exit(); } else if (menuStrings[i].equals(difficulty)) { CountingGame.difficulty++; CountingGame.difficulty %= 3; } else if (menuStrings[i].equals(zahlen)) { // parentGame.getScreenManager().setCurrentState(ScreenManager.ScreenState.CountingGame); } else if (menuStrings[i].equals(reihen)) { // parentGame.getScreenManager().setCurrentState(ScreenManager.ScreenState.SortingGame); } else if (menuStrings[i].equals(ballons)) { numberOfBallonsIndex++; numberOfBallonsIndex = numberOfBallonsIndex % numberOfBallonsValues.length; CountingGame.numberOfBalloons = getNumberOfBallons(); } } } } } }
From source file:at.juggle.games.counting.screens.SortingGameScreen.java
License:Apache License
private void handleInput() { if (Gdx.input.isKeyJustPressed(Input.Keys.BACK) || Gdx.input.isKeyJustPressed(Input.Keys.ESCAPE)) { parentGame.getScreenManager().setCurrentState(ScreenManager.ScreenState.Menu); } else if (Gdx.input.isKeyJustPressed(Input.Keys.ANY_KEY)) { // model.resetGameState(); }// w ww . java 2s. co m if (Gdx.input.justTouched()) { Vector3 touchWorldCoords = cam.unproject(new Vector3(Gdx.input.getX(), Gdx.input.getY(), 1)); SortingGameModel.InputResult inputResult = model.handleTouch(touchWorldCoords); if (inputResult == SortingGameModel.InputResult.Change) { model.resetGameState(); } else if (inputResult == SortingGameModel.InputResult.Pop) { xplode.setPosition(touchWorldCoords.x, touchWorldCoords.y); xplode.reset(); String event = "blob0" + ((int) (Math.random() * 4) + 1); parentGame.getSoundManager().playEvent(event); } } }
From source file:at.juggle.games.counting.screens.TextMenuScreen.java
License:Apache License
private void handleInput() { // keys .../* www .j a va2 s. c o m*/ if (Gdx.input.isKeyJustPressed(Input.Keys.DOWN)) { currentMenuItem = (currentMenuItem + 1) % menuStrings.length; parentGame.getSoundManager().playEvent("blip"); } else if (Gdx.input.isKeyJustPressed(Input.Keys.UP)) { if (currentMenuItem > 0) currentMenuItem = (currentMenuItem - 1); else currentMenuItem = menuStrings.length - 1; parentGame.getSoundManager().playEvent("blip"); } else if (Gdx.input.isKeyJustPressed(Input.Keys.N)) { System.out.println("Next level in music ..."); parentGame.getSoundManager().addLevel(1); } else if (Gdx.input.isKeyJustPressed(Input.Keys.P)) { System.out.println("Previous level in music ..."); parentGame.getSoundManager().addLevel(-1); } else if (Gdx.input.isKeyJustPressed(Input.Keys.ENTER)) { if (menuStrings[currentMenuItem].equals(ende)) { Gdx.app.exit(); parentGame.getSoundManager().playEvent("explode"); } else if (menuStrings[currentMenuItem].equals(difficulty)) { CountingGame.difficulty++; CountingGame.difficulty %= 3; } else if (menuStrings[currentMenuItem].equals(zahlen)) { parentGame.getScreenManager().setCurrentState(ScreenManager.ScreenState.CountingGame); } else if (menuStrings[currentMenuItem].equals(reihen)) { parentGame.getScreenManager().setCurrentState(ScreenManager.ScreenState.SortingGame); } else if (menuStrings[currentMenuItem].equals(ballons)) { numberOfBallonsIndex++; numberOfBallonsIndex = numberOfBallonsIndex % numberOfBallonsValues.length; CountingGame.numberOfBalloons = getNumberOfBallons(); } } // touch if (Gdx.input.justTouched()) { Vector3 touchWorldCoords = cam.unproject(new Vector3(Gdx.input.getX(), Gdx.input.getY(), 1)); // find the menu item .. for (int i = 0; i < menuStrings.length; i++) { if (touchWorldCoords.x > offsetLeft) { float pos = CountingGame.GAME_HEIGHT - offsetTop - i * offsetY; if (touchWorldCoords.y < pos && touchWorldCoords.y > pos - menuFont.getLineHeight()) { // it's there if (menuStrings[i].equals(ende)) { Gdx.app.exit(); } else if (menuStrings[i].equals(difficulty)) { CountingGame.difficulty++; CountingGame.difficulty %= 3; } else if (menuStrings[i].equals(zahlen)) { parentGame.getScreenManager().setCurrentState(ScreenManager.ScreenState.CountingGame); } else if (menuStrings[i].equals(reihen)) { parentGame.getScreenManager().setCurrentState(ScreenManager.ScreenState.SortingGame); } else if (menuStrings[i].equals(ballons)) { numberOfBallonsIndex++; numberOfBallonsIndex = numberOfBallonsIndex % numberOfBallonsValues.length; CountingGame.numberOfBalloons = getNumberOfBallons(); } } } } } }
From source file:at.therefactory.jewelthief.input.GameScreenInputAdapter.java
License:Open Source License
@Override public boolean touchDown(int screenX, int screenY, int pointer, int button) { boolean returnValue = super.touchDown(screenX, screenY, pointer, button); numTouches++;/* w w w.j a v a 2 s. c o m*/ if (!(JewelThief.getInstance().getScreen() instanceof GameScreen)) { return true; } pressOrReleaseButtonAt(viewport.unproject(new Vector3(screenX, screenY, 0))); return returnValue; }
From source file:at.therefactory.jewelthief.input.GameScreenInputAdapter.java
License:Open Source License
@Override public boolean touchUp(int screenX, int screenY, int pointer, int button) { super.touchUp(screenX, screenY, pointer, button); numTouches = (short) Math.max(0, numTouches - 1); playerDragging = false;//from w ww. ja v a 2 s .c om releaseAllButtons(); // check if button has been clicked Vector3 touchCoordinates = viewport.unproject(new Vector3(screenX, screenY, 0)); if (!game.isMenuShown() && game.getPlayer().getNumMen() > 0 && Utils.within(touchCoordinates, hud.getButtonShowMenu())) { game.showMenu(); } else if (game.getPlayer().getNumMen() <= 0) { if (allowButtonClick) { allowButtonClick = false; // play again? yes if (Utils.within(touchCoordinates, game.getButtonPlayAgain())) { game.resetGame(); } // play again? no else if (Utils.within(touchCoordinates, game.getButtonExit())) { JewelThief.getInstance().switchToMainMenu(); } } else { allowButtonClick = true; } } else if (game.isMenuShown()) { // yes if (Utils.within(touchCoordinates, game.getButtonYes())) { JewelThief.getInstance().switchToMainMenu(); } // no else if (Utils.within(touchCoordinates, game.getButtonNo())) { game.hideMenu(); } // restart else if (Utils.within(touchCoordinates, game.getButtonRestart())) { game.resetGame(); } } return true; }
From source file:at.therefactory.jewelthief.input.GameScreenInputAdapter.java
License:Open Source License
@Override public boolean touchDragged(int screenX, int screenY, int pointer) { super.touchDragged(screenX, screenY, pointer); Vector3 touchCoordinates = viewport.unproject(new Vector3(screenX, screenY, 0)); if (game.isPaused()) { pressOrReleaseButtonAt(touchCoordinates); } else {/*w ww . ja v a2 s.c om*/ if (playerDragging && numTouches == 1) { // do not exceed right border float newX = Math.min(touchCoordinates.x - deltaX, game.getSpriteBackground().getX() + game.getSpriteBackground().getWidth() - game.getPlayer().getSprite().getWidth() / 2 - 1); // do not exceed left border newX = Math.max(game.getSpriteBackground().getX() + game.getPlayer().getSprite().getWidth() / 2, newX); // do not exceed lower border float newY = Math.max(touchCoordinates.y - deltaY, game.getSpriteBackground().getY() + game.getPlayer().getSprite().getHeight() / 2); // do not exceed upper border newY = Math.min(game.getSpriteBackground().getY() + game.getSpriteBackground().getHeight() - game.getPlayer().getSprite().getHeight() / 2 - 1, newY); game.getPlayer().setPosition(newX, newY); } else { playerDragging = true; } // delta between touch point and player position deltaX = (touchCoordinates.x - game.getPlayer().getPosition().x); deltaY = (touchCoordinates.y - game.getPlayer().getPosition().y); } return true; }
From source file:at.therefactory.jewelthief.input.MenuScreenInputAdapter.java
License:Open Source License
@Override public boolean touchDown(int screenX, int screenY, int pointer, int button) { super.touchDown(screenX, screenY, pointer, button); numTouches++;/* ww w. ja v a2 s . c om*/ Vector3 touchCoordinates = viewport.unproject(new Vector3(screenX, screenY, 0)); pressOrReleaseButtons(touchCoordinates); handleTouchOnStars(touchCoordinates); touchStartY = touchCoordinates.y; // if (DEBUG_MODE && Utils.within(touchCoordinates, menuScreen.getSpriteTitle())) { // menuScreen.setState(MenuScreen.MenuState.ShowPromo); // } else if (menuScreen.getState().equals(MenuScreen.MenuState.ShowPromo)) { // menuScreen.setState(MenuScreen.MenuState.ShowMenu); // } return true; }
From source file:at.therefactory.jewelthief.input.MenuScreenInputAdapter.java
License:Open Source License
@Override public boolean touchDragged(int screenX, int screenY, int pointer) { super.touchDragged(screenX, screenY, pointer); Vector3 touchCoordinates = viewport.unproject(new Vector3(screenX, screenY, 0)); pressOrReleaseButtons(touchCoordinates); handleTouchOnStars(touchCoordinates); if (numTouches == 1 && !menuScreen.buttonUpdateHighscores.isPressed() && !menuScreen.buttonExitToMainMenu.isPressed()) { deltaY = lastDeltaY + (touchStartY - touchCoordinates.y); deltaY = Math.max(deltaY, menuScreen.getHighscores() == null ? 0 : -HIGHSCORES_LINE_HEIGHT * (menuScreen.getHighscores().length - 1)); // stop scrolling if only last line is visible deltaY = -deltaY; // invert vertical scrolling direction menuScreen.setScrollbarPositionY( (22f - 200f) / (HIGHSCORES_LINE_HEIGHT * (menuScreen.getHighscores().length - 1)) * deltaY + 200);//from w w w . j a va 2 s . c o m } touchDragging = true; return true; }