Android Open Source - mobius Moving Layer






From Project

Back to project page mobius.

License

The source code is released under:

MIT License

If you think the Android project mobius 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.sgtcodfish.mobiusListing.components;
/*  ww  w .  j a  va2 s . com*/
import com.badlogic.gdx.maps.MapProperties;

/**
 * <p>
 * Holds a movable layer. Override and implement interact for specific
 * directions.
 * </p>
 * 
 * @author Ashley Davis (SgtCoDFish)
 */
public abstract class MovingLayer extends InteractableLayer<Position> {
  public int  deltaPos    = 0;
  public int  maxDiff      = 0;

  // the actual direction the layer will move when going from deltaPos 0 ->
  // maxDiff
  // 1 = right/up
  // -1 = left/down
  public int  direction    = 1;

  // the direction we're currently moving in
  public int  tempDirection  = 1;

  @Override
  public void interact(Position p, int degree) {
    deltaPos += tempDirection * degree;

    move(p, degree * tempDirection);

    if (deltaPos >= maxDiff) {
      deltaPos = maxDiff;
      tempDirection = -1;
    } else if (deltaPos <= 0) {
      deltaPos = 0;
      tempDirection = 1;
    }
  }

  protected abstract void move(Position p, int degree);

  protected void tiledPropertiesHelper(MapProperties properties, String propertyString, boolean flipMax) {
    String prop = (String) properties.get(propertyString, null, String.class);

    if (prop != null) {
      int max = 0;

      try {
        max = Integer.parseInt(prop);
      } catch (NumberFormatException nfe) {
        throw new IllegalArgumentException("Parsing error when loading MovingLayer (" + propertyString
            + "); no max found.");
      }

      direction = (flipMax ? -1 : 1) * Integer.signum(max);

      if (direction == 0) {
        throw new IllegalArgumentException("MovingLayer (" + propertyString
            + "): No valid value for property found.");
      }

      maxDiff = Math.abs(max);
    } else {
      throw new IllegalArgumentException("Attempting to load MovingLayer (" + propertyString
          + ") from a layer with no valid property.");
    }
  }

  @Override
  public void reset() {
    super.reset();
    deltaPos = 0;
    maxDiff = 0;
    direction = 1;
    tempDirection = 1;
  }
}




Java Source Code List

com.sgtcodfish.mobiusListing.Item.java
com.sgtcodfish.mobiusListing.MobiusListingGame.java
com.sgtcodfish.mobiusListing.TerrainCollisionMap.java
com.sgtcodfish.mobiusListing.WorldConstants.java
com.sgtcodfish.mobiusListing.android.AndroidLauncher.java
com.sgtcodfish.mobiusListing.components.ChildLinked.java
com.sgtcodfish.mobiusListing.components.Collectable.java
com.sgtcodfish.mobiusListing.components.DxLayer.java
com.sgtcodfish.mobiusListing.components.DyLayer.java
com.sgtcodfish.mobiusListing.components.FadableLayer.java
com.sgtcodfish.mobiusListing.components.FocusTaker.java
com.sgtcodfish.mobiusListing.components.InteractableLayer.java
com.sgtcodfish.mobiusListing.components.Interactable.java
com.sgtcodfish.mobiusListing.components.Inventory.java
com.sgtcodfish.mobiusListing.components.Linked.java
com.sgtcodfish.mobiusListing.components.MobiusSprite.java
com.sgtcodfish.mobiusListing.components.MovingLayer.java
com.sgtcodfish.mobiusListing.components.Opacity.java
com.sgtcodfish.mobiusListing.components.PlatformInputListener.java
com.sgtcodfish.mobiusListing.components.PlatformSprite.java
com.sgtcodfish.mobiusListing.components.PlayerInputListener.java
com.sgtcodfish.mobiusListing.components.PlayerSprite.java
com.sgtcodfish.mobiusListing.components.PlayerState.java
com.sgtcodfish.mobiusListing.components.Position.java
com.sgtcodfish.mobiusListing.components.Solid.java
com.sgtcodfish.mobiusListing.components.StaticSprite.java
com.sgtcodfish.mobiusListing.components.TiledRenderable.java
com.sgtcodfish.mobiusListing.components.Velocity.java
com.sgtcodfish.mobiusListing.desktop.DesktopLauncher.java
com.sgtcodfish.mobiusListing.levels.LevelEntityFactory.java
com.sgtcodfish.mobiusListing.player.HumanoidAnimationState.java
com.sgtcodfish.mobiusListing.player.PlayerConstants.java
com.sgtcodfish.mobiusListing.player.PlayerEntityFactory.java
com.sgtcodfish.mobiusListing.systems.AudioSystem.java
com.sgtcodfish.mobiusListing.systems.CollisionBoxRenderingDebugSystem.java
com.sgtcodfish.mobiusListing.systems.FocusTakerSystem.java
com.sgtcodfish.mobiusListing.systems.LevelAdvanceSystem.java
com.sgtcodfish.mobiusListing.systems.LinkingSystem.java
com.sgtcodfish.mobiusListing.systems.MovementSystem.java
com.sgtcodfish.mobiusListing.systems.PlatformInputSystem.java
com.sgtcodfish.mobiusListing.systems.PlayerInputSystem.java
com.sgtcodfish.mobiusListing.systems.SolidProcessingSystem.java
com.sgtcodfish.mobiusListing.systems.SpriteRenderingSystem.java
com.sgtcodfish.mobiusListing.systems.TerrainCollisionBoxRenderingDebugSystem.java
com.sgtcodfish.mobiusListing.systems.TerrainCollisionSystem.java
com.sgtcodfish.mobiusListing.systems.TiledRenderingSystem.java