Android Open Source - CircleWorldGDX Game Logic






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;
/*from   w  ww  . ja v a2s  .co m*/
import com.badlogic.gdx.assets.AssetManager;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.badlogic.gdx.utils.Disposable;
import com.fdangelo.circleworld.universeengine.objects.Avatar;
import com.fdangelo.circleworld.universeengine.tilemap.Planet;
import com.fdangelo.circleworld.universeview.FollowCameraParameters;
import com.fdangelo.circleworld.universeview.UniverseView;
import com.fdangelo.circleworld.universeview.UniverseViewCamera;
import com.fdangelo.circleworld.universeview.tilemap.PlanetView;
import com.fdangelo.circleworld.utils.Mathf;

public class GameLogic implements Disposable {
  
  private static GameLogic instace;

  public AssetManager assetManager;

  private UniverseViewCamera universeCamera;
  private UniverseView universeView;

  private int universeSeed;

  private GameLogicState state = GameLogicState.PlayingAvatar;
  private float stateTime;

  private float universeTimeMultiplier = 1.0f;

  public static GameLogic getInstace() {
    return instace;
  }

  public UniverseView getUniverseView() {
    return universeView;
  }

  public GameLogicState getState() {
    return state;
  }

  public GameLogic() {
    instace = this;

    assetManager = new AssetManager();

    assetManager.load("atlas/gui.atlas", TextureAtlas.class);
    assetManager.load("atlas/planets.atlas", TextureAtlas.class);
    assetManager.load("atlas/player1.atlas", TextureAtlas.class);
    assetManager.load("atlas/ships.atlas", TextureAtlas.class);
    assetManager.load("atlas/tilemap.atlas", TextureAtlas.class);

    switchState(GameLogicState.Loading);
  }

  public void switchState(final GameLogicState toState) {
    state = toState;
    stateTime = 0.0f;

    switch (toState) {
      case Loading:
        // Do nothing
        break;

      case PlayingAvatar:
        universeCamera.followObject(getUniverseView().getAvatarView(), FollowCameraParameters.FollowRotation | FollowCameraParameters.FollowScale, true);
        break;

      case PlayingShip:
        universeCamera.followObject(getUniverseView().getShipView(), FollowCameraParameters.None, true);
        break;

      case Travelling:
        // Do nothing
        break;
    }
  }

  public void updateAndRender(float deltaTime) {
    if (deltaTime > 0.1f) {
      deltaTime = 0.1f;
    }

    stateTime += deltaTime;

    switch (state) {
      case Loading:
        if (assetManager.update()) {
          // Loading complete!

          // Create layers
          universeView = new UniverseView();
          universeView.init(universeSeed);

          universeCamera = new UniverseViewCamera(getUniverseView().getCamera());

          switchState(GameLogicState.PlayingAvatar);
        }
        break;

      case PlayingAvatar:
        universeTimeMultiplier = Mathf.lerp(universeTimeMultiplier, 1.0f, 0.25f);
        getUniverseView().updateUniverse(deltaTime * universeTimeMultiplier);
        universeCamera.update(deltaTime);
        break;

      case PlayingShip:
        universeTimeMultiplier = Mathf.lerp(universeTimeMultiplier, 1.0f, 0.25f);
        getUniverseView().updateUniverse(deltaTime * universeTimeMultiplier);
        universeCamera.update(deltaTime);
        break;

      case Travelling:
        universeTimeMultiplier = Mathf.lerp(universeTimeMultiplier, 0.1f, 0.25f);
        if (stateTime > 1.25f) {
          switchState(GameLogicState.PlayingAvatar);
        }
        getUniverseView().updateUniverse(deltaTime * universeTimeMultiplier);
        universeCamera.update(deltaTime);
        break;
    }

    if (getUniverseView() != null) {
      getUniverseView().updateLayers(deltaTime);
    }
  }

  public void travelToPlanet(final PlanetView targetPlanetView) {
    ((Avatar) getUniverseView().getAvatarView().getUniverseObject()).travelToPlanet((Planet) targetPlanetView.getTilemapCircle());

    // Force update to update AvatarView position
    getUniverseView().updateUniverse(0);

    switchState(GameLogicState.Travelling);
  }

  public void playerBoardShip() {
    getUniverseView().getUniverse().getShip().beamUpAvatar(getUniverseView().getUniverse().getAvatar());

    switchState(GameLogicState.PlayingShip);
  }

  public void playerLeaveShip(final Planet planet) {
    getUniverseView().getUniverse().getShip().beamDownAvatar(getUniverseView().getUniverse().getAvatar(), planet);

    switchState(GameLogicState.PlayingAvatar);
  }

  @Override
  public void dispose() {
    if (getUniverseView() != null) {
      getUniverseView().dispose();
    }

    assetManager.dispose();
  }

  public void resize(final int width, final int height) {

    if (getUniverseView() != null) {
      getUniverseView().resize(width, height);
    }

  }
}




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