Android Open Source - mobius Player Input System






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.systems;
/* w ww.  j  a va2 s.  c o m*/
import com.artemis.ComponentMapper;
import com.artemis.Entity;
import com.artemis.Filter;
import com.artemis.systems.EntityProcessingSystem;
import com.badlogic.gdx.Application;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input.Keys;
import com.sgtcodfish.mobiusListing.MobiusListingGame;
import com.sgtcodfish.mobiusListing.components.PlayerInputListener;
import com.sgtcodfish.mobiusListing.components.PlayerState;
import com.sgtcodfish.mobiusListing.components.Position;
import com.sgtcodfish.mobiusListing.components.Velocity;
import com.sgtcodfish.mobiusListing.player.HumanoidAnimationState;
import com.sgtcodfish.mobiusListing.player.PlayerConstants;

/**
 * @author Ashley Davis (SgtCoDFish)
 */
public class PlayerInputSystem extends EntityProcessingSystem {
  private ComponentMapper<PlayerState>  animationStateMapper  = null;
  private ComponentMapper<Velocity>    velocityMapper      = null;

  private MobiusListingGame        instance        = null;

  private boolean              hasReleasedSpace    = false;

  @SuppressWarnings("unchecked")
  public PlayerInputSystem(MobiusListingGame instance) {
    this(Filter.allComponents(PlayerInputListener.class, Position.class, PlayerState.class, Velocity.class),
        instance);
  }

  protected PlayerInputSystem(Filter filter, MobiusListingGame instance) {
    super(filter);
    this.instance = instance;
  }

  @Override
  public void initialize() {
    velocityMapper = world.getMapper(Velocity.class);
    animationStateMapper = world.getMapper(PlayerState.class);
  }

  @Override
  protected void process(Entity e) {
    // TODO: More portable implementation - keys in PlayerInputListener?

    PlayerState ps = animationStateMapper.get(e);

    // TODO: remove movement intended for debug
    if (Gdx.input.isKeyPressed(Keys.S)) {
      velocityMapper.get(e).velocity.x = 0;
      ps.state = HumanoidAnimationState.STANDING;
    } else if (Gdx.input.isKeyPressed(Keys.A)) {
      velocityMapper.get(e).velocity.x = -PlayerConstants.RUN_VELOCITY;
      if (ps.state != HumanoidAnimationState.JUMPING)
        ps.state = HumanoidAnimationState.RUNNING;
    }

    if (Gdx.input.isKeyPressed(Keys.D)) {
      velocityMapper.get(e).velocity.x = +PlayerConstants.RUN_VELOCITY;
      if (ps.state != HumanoidAnimationState.JUMPING)
        ps.state = HumanoidAnimationState.RUNNING;
    }

    if (Gdx.input.isKeyPressed(Keys.SPACE)) {
      if (hasReleasedSpace && ps.state != HumanoidAnimationState.JUMPING) {
        velocityMapper.get(e).velocity.y = PlayerConstants.JUMP_VELOCITY;
        ps.state = HumanoidAnimationState.JUMPING;
        hasReleasedSpace = false;
      }
    } else {
      hasReleasedSpace = true;
    }

    if (Gdx.input.isKeyPressed(Keys.P)) {
      instance.resetPlayer();
    }

    if (Gdx.app.getLogLevel() == Application.LOG_DEBUG) {
      if (Gdx.input.isKeyPressed(Keys.NUMPAD_6)) {
        world.getMapper(Position.class).get(e).position.x += 2.0f;
      }
    }
  }
}




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