Android Open Source - CircleWorldGDX Ship View Input






From Project

Back to project page CircleWorldGDX.

License

The source code is released under:

MIT License

If you think the Android project CircleWorldGDX listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.fdangelo.circleworld.universeview.objects;
/*from w ww.j  av a2  s .  c  o m*/
import com.badlogic.gdx.Application.ApplicationType;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input;
import com.fdangelo.circleworld.GameLogic;
import com.fdangelo.circleworld.GameLogicState;
import com.fdangelo.circleworld.universeengine.objects.Ship;
import com.fdangelo.circleworld.universeengine.objects.ShipInput;
import com.fdangelo.circleworld.universeview.UniverseViewCamera;

public class ShipViewInput {
  private final ShipView shipView;

  static public ShipInputMode mode = ShipInputMode.Move;

  // private GUIStyle centeredLabelStyle;
  // private GUIStyle centeredBoxStyle;

  public ShipViewInput(final ShipView shipView) {
    this.shipView = shipView;
  }

  public final void Update(final float deltaTime) {
    if (GameLogic.getInstace().getState() != GameLogicState.PlayingShip) {
      return;
    }

    switch (mode) {
      case Move:
        updateMove();
        UniverseViewCamera.getInstance().updateZoomInput(deltaTime);
        break;
    }
  }

  private final void updateMove() {
    final ShipInput shipInput = ((Ship) shipView.getUniverseObject()).input;

    if (Gdx.app.getType() == ApplicationType.Android || Gdx.app.getType() == ApplicationType.iOS) {
      int touchCount = 0;
      int touch1x = -1, touch1y = -1;
      int touch2x = -1, touch2y = -1;

      if (Gdx.input.isTouched(0)) {
        touch1x = Gdx.input.getX(0);
        touch1y = Gdx.input.getY(0);
        touchCount++;
      }

      if (Gdx.input.isTouched(1)) {
        touch2x = Gdx.input.getX(1);
        touch2y = Gdx.input.getY(1);
        touchCount++;
      }

      final float screenWidth = Gdx.graphics.getWidth();
      final float screenHeight = Gdx.graphics.getHeight();

      if (touchCount >= 1) {
        if (touch1x > screenWidth / 2.0f && touch1y > screenHeight * 0.75f || touchCount > 1 && touch2x > screenWidth / 2.0f
            && touch2y > screenHeight * 0.75f) {
          shipInput.moveDirection = 1.0f;
        }

        if (touch1x < screenWidth / 4.0f && touch1y > screenHeight * 0.75f || touchCount > 1 && touch2x < screenWidth / 4.0f
            && touch2y > screenHeight * 0.75f) {
          shipInput.rotateDirection = -1.0f;
        } else if (touch1x < screenWidth / 2.0f && touch1y > screenHeight * 0.75f || touchCount > 1 && touch2x < screenWidth / 2.0f
            && touch2y > screenHeight * 0.75f) {
          shipInput.rotateDirection = 1.0f;
        }
      }
    } else {
      if (Gdx.input.isKeyPressed(Input.Keys.A)) {
        shipInput.rotateDirection = -1;
      } else if (Gdx.input.isKeyPressed(Input.Keys.D)) {
        shipInput.rotateDirection = 1;
      } else {
        shipInput.rotateDirection = 0;
      }

      if (Gdx.input.isKeyPressed(Input.Keys.W)) {
        shipInput.moveDirection = 1;
      } else {
        shipInput.moveDirection = 0;
      }

      // if (Gdx.input.isKeyPressed(Input.Keys.T))
      // {
      // int clickedThingIndex =
      // shipView.getUniverseView().getUniverse().FindClosestRenderedThing(shipView.getUniverseObject().getPositionX(),
      // shipView.getUniverseObject().getPositionY(), 30.0f);
      // if (clickedThingIndex >= 0)
      // GameLogic.Instace.PlayerLeaveShip(shipView.getUniverseView().getUniverse().GetPlanet((short)
      // clickedThingIndex));
      // }
    }
  }

  /*
   * #if ENABLE_ONGUI public void OnGUI() { if (GameLogic.Instace.State !=
   * GameLogicState.PlayingShip) return; if (centeredLabelStyle == null) {
   * centeredLabelStyle = new GUIStyle(GUI.skin.label);
   * centeredLabelStyle.alignment = TextAnchor.MiddleCenter; centeredBoxStyle
   * = new GUIStyle(GUI.skin.box); centeredBoxStyle.alignment =
   * TextAnchor.MiddleCenter; } InputAreas.ResetInputAreas(); switch(mode) {
   * case ShipInputMode.Move: DrawMoveGUI(); break; } } private void
   * DrawMoveGUI() { //Draw movement keys if (Application.platform ==
   * RuntimePlatform.Android || Application.platform ==
   * RuntimePlatform.IPhonePlayer) { InputAreas.AddInputArea(new Rect(0,
   * Screen.height - Screen.height * 0.25f, Screen.width, Screen.height *
   * 0.25f)); GUI.Button(new Rect(0, Screen.height - Screen.height * 0.25f,
   * Screen.width / 4, Screen.height * 0.25f), "Rotate Left"); GUI.Button(new
   * Rect(Screen.width / 4.0f, Screen.height - Screen.height * 0.25f,
   * Screen.width / 4, Screen.height * 0.25f), "Rotate Right"); GUI.Button(new
   * Rect(Screen.width / 2.0f, Screen.height - Screen.height * 0.25f,
   * Screen.width / 2, Screen.height * 0.25f), "Move Forward"); } //Draw
   * switch to avatar button InputAreas.AddInputArea(new Rect(Screen.width -
   * (Screen.width / 8) * 3.0f, 0, Screen.width / 8, Screen.height / 8)); if
   * (GUI.Button(new Rect(Screen.width - (Screen.width / 8) * 3.0f, 0,
   * Screen.width / 8, Screen.height / 8), "LEAVE SHIP")) { int
   * clickedThingIndex =
   * shipView.UniverseView.Universe.FindClosestRenderedThing
   * (shipView.UniverseObject.Position, 30.0f); if (clickedThingIndex >= 0)
   * GameLogic
   * .Instace.PlayerLeaveShip(shipView.UniverseView.Universe.GetPlanet
   * ((ushort) clickedThingIndex)); } } #endif
   */

}




Java Source Code List

.AssetsUpdater.java
com.fdangelo.circleworld.GameLogicState.java
com.fdangelo.circleworld.GameLogic.java
com.fdangelo.circleworld.MainActivity.java
com.fdangelo.circleworld.Main.java
com.fdangelo.circleworld.MyGdxGame.java
com.fdangelo.circleworld.RobovmLauncher.java
com.fdangelo.circleworld.client.GwtLauncher.java
com.fdangelo.circleworld.gui.AvatarEditControlScreen.java
com.fdangelo.circleworld.gui.AvatarMoveControlScreen.java
com.fdangelo.circleworld.gui.HudScreen.java
com.fdangelo.circleworld.gui.core.Gui.java
com.fdangelo.circleworld.gui.core.ScreenTable.java
com.fdangelo.circleworld.gui.core.Screen.java
com.fdangelo.circleworld.universeengine.IUniverseListener.java
com.fdangelo.circleworld.universeengine.ThingPosition.java
com.fdangelo.circleworld.universeengine.ThingType.java
com.fdangelo.circleworld.universeengine.Thing.java
com.fdangelo.circleworld.universeengine.UniverseFactory.java
com.fdangelo.circleworld.universeengine.UniverseGeneratorDefault.java
com.fdangelo.circleworld.universeengine.UniverseGenerator.java
com.fdangelo.circleworld.universeengine.Universe.java
com.fdangelo.circleworld.universeengine.objects.AvatarInput.java
com.fdangelo.circleworld.universeengine.objects.Avatar.java
com.fdangelo.circleworld.universeengine.objects.FollowParentParameters.java
com.fdangelo.circleworld.universeengine.objects.IUniverseObjectListener.java
com.fdangelo.circleworld.universeengine.objects.ShipInput.java
com.fdangelo.circleworld.universeengine.objects.Ship.java
com.fdangelo.circleworld.universeengine.objects.UniverseObject.java
com.fdangelo.circleworld.universeengine.tilemap.ITilemapCircleListener.java
com.fdangelo.circleworld.universeengine.tilemap.PlanetType.java
com.fdangelo.circleworld.universeengine.tilemap.PlanetTypes.java
com.fdangelo.circleworld.universeengine.tilemap.Planet.java
com.fdangelo.circleworld.universeengine.tilemap.TileDirection.java
com.fdangelo.circleworld.universeengine.tilemap.TileHitFlags.java
com.fdangelo.circleworld.universeengine.tilemap.TileHitInfo.java
com.fdangelo.circleworld.universeengine.tilemap.TileSubtype.java
com.fdangelo.circleworld.universeengine.tilemap.TileType.java
com.fdangelo.circleworld.universeengine.tilemap.TileTypes.java
com.fdangelo.circleworld.universeengine.tilemap.TilemapCircle.java
com.fdangelo.circleworld.universeengine.utils.DataPools.java
com.fdangelo.circleworld.universeengine.utils.PoolByte.java
com.fdangelo.circleworld.universeengine.utils.PoolColor.java
com.fdangelo.circleworld.universeengine.utils.PoolFloat.java
com.fdangelo.circleworld.universeengine.utils.PoolInt.java
com.fdangelo.circleworld.universeengine.utils.PoolVector2.java
com.fdangelo.circleworld.universeengine.utils.PoolVector3.java
com.fdangelo.circleworld.universeengine.utils.UEProfilerSample.java
com.fdangelo.circleworld.universeengine.utils.UEProfiler.java
com.fdangelo.circleworld.universeview.FollowCameraParameters.java
com.fdangelo.circleworld.universeview.UniverseViewCamera.java
com.fdangelo.circleworld.universeview.UniverseViewFactory.java
com.fdangelo.circleworld.universeview.UniverseView.java
com.fdangelo.circleworld.universeview.objects.AvatarInputEditTool.java
com.fdangelo.circleworld.universeview.objects.AvatarInputMode.java
com.fdangelo.circleworld.universeview.objects.AvatarViewInput.java
com.fdangelo.circleworld.universeview.objects.AvatarView.java
com.fdangelo.circleworld.universeview.objects.InputAreas.java
com.fdangelo.circleworld.universeview.objects.ShipInputMode.java
com.fdangelo.circleworld.universeview.objects.ShipViewInput.java
com.fdangelo.circleworld.universeview.objects.ShipView.java
com.fdangelo.circleworld.universeview.objects.UniverseObjectView.java
com.fdangelo.circleworld.universeview.tilemap.PlanetView.java
com.fdangelo.circleworld.universeview.tilemap.TilemapCircleViewBackgroundRenderer.java
com.fdangelo.circleworld.universeview.tilemap.TilemapCircleViewRenderer.java
com.fdangelo.circleworld.universeview.tilemap.TilemapCircleView.java
com.fdangelo.circleworld.utils.Mathf.java
com.fdangelo.circleworld.utils.Vector2I.java