Android Open Source - CircleWorldGDX Planet






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.universeengine.tilemap;
/*  www .  j a  va  2s  .c o m*/
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.math.MathUtils;
import com.fdangelo.circleworld.universeengine.Thing;
import com.fdangelo.circleworld.universeengine.ThingPosition;
import com.fdangelo.circleworld.universeengine.ThingType;
import com.fdangelo.circleworld.universeengine.Universe;

public class Planet extends TilemapCircle {
  private float gravity = 10.0f;

  private Universe universe;
  private short thingIndex;

  public final short getThingIndex() {
    return thingIndex;
  }

  public final float getGravity() {
    return gravity;
  }

  public final void setGravity(final float value) {
    gravity = value;
  }

  public PlanetType getPlanetType() {
    if (universe.getThing(thingIndex).type == ThingType.Sun) {
      return PlanetTypes.getPlanetType((byte) (Math.abs(getSeed() % 2) + 4)); // suns!
    } else {
      return PlanetTypes.getPlanetType((byte) (Math.abs(getSeed() % 4))); // planets!
    }
  }

  @Override
  protected void updateTiles() {
    // System.Random random = new System.Random(Seed);

    final byte tileId = getPlanetType().mainTileId;

    for (int i = 0; i < tiles.length; i++) {
      // if (random.NextDouble() > 0.95f)
      // tiles[i] = 0;
      // else
      tiles[i] = tileId;
    }
  }

  public final void initPlanet(final Universe universe, final short thingIndex) {
    this.universe = universe;
    this.thingIndex = thingIndex;

    final Thing thing = universe.getThing(thingIndex);

    init(thing.seed, getPlanetHeightWithRadius(thing.radius));

    updatePlanetPosition();
  }

  @Override
  public void recycle() {
    super.recycle();

    universe = null;
    thingIndex = 0;
  }

  public void update(final float deltaTime) {

    updatePlanetPosition();

    if (listener != null) {
      listener.onTilemapParentChanged(deltaTime);
    }
  }

  private void updatePlanetPosition() {
    final ThingPosition thing = universe.getThingPosition(thingIndex);

    positionX = thing.x;
    positionY = thing.y;
    rotation = thing.rotation;
  }

  static private short[] validHeights = new short[] { 8, 16, 32, 64, 128 };
  static private short[] validRadius;

  static public short getClosestValidRadius(final short radius) {
    initValidRadius();

    for (int i = 0; i < validRadius.length; i++) {
      if (validRadius[i] > radius) {
        if (i == 0) {
          return validRadius[0];
        } else {
          return validRadius[i - 1];
        }
      }
    }

    return 0;
  }

  @SuppressWarnings("boxing")
  static private void initValidRadius() {
    if (validRadius == null) {
      validRadius = new short[validHeights.length];
      for (int i = 0; i < validHeights.length; i++) {
        validRadius[i] = getRadiusFromPlanetHeight(validHeights[i]);
      }

      for (int i = 0; i < validHeights.length; i++) {
        if (getPlanetHeightWithRadius(validRadius[i]) != validHeights[i]) {
          Gdx.app.error("Error", String.format("Invalid validRadius[] initialization, expected %d, got %d", validHeights[i],
              getPlanetHeightWithRadius(validRadius[i])));
        }
      }
    }
  }

  static public short getPlanetHeightWithRadius(final short radius) {
    initValidRadius();

    for (int i = 0; i < validRadius.length; i++) {
      if (radius == validRadius[i]) {
        return validHeights[i];
      }
    }

    return 0;
  }

  static private short getRadiusFromPlanetHeight(final short height) {
    final int width = (((int) (height * MathUtils.PI * 2.0f)) / 4) * 4;

    final float height0 = (height - 1) * TILE_SIZE;
    final float k = -((width / (MathUtils.PI * 2.0f))) / (1 - (width / (MathUtils.PI * 2.0f)));

    final float r = (float) (height0 * Math.pow(k, height));

    return (short) r;
  }
}




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