Android Open Source - LucyTheMoocher Player Character






From Project

Back to project page LucyTheMoocher.

License

The source code is released under:

MIT License

If you think the Android project LucyTheMoocher 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.lucythemoocher.actors;
/* ww w. j  a v a  2s  . c o  m*/
import java.util.Iterator;

import com.lucythemoocher.Globals.Globals;
import com.lucythemoocher.actors.maincharacter.state.*;

import com.lucythemoocher.controls.Controllable;
import com.lucythemoocher.controls.ActionController;
import com.lucythemoocher.util.Direction;
import com.lucythemoocher.R;

public class PlayerCharacter extends Actor implements Controllable {
  private State state_;
  private ActionController controller_;
  
  /**
   * Constructor. The controller will be attached with 
   * the character in the constructor, you don't have
   * to do it outside
   * @param controller Player's controller
   * @param x
   * @param y
   */
  public PlayerCharacter(ActionController controller, float x, float y) {
    super();
    getDrawer().initializeAnimation(R.drawable.lucy_states);
    getCinematic().addBox(x, y, getH(), getW());
    state_ = new StateNone(this, pos_, getDrawer().getAnim(), Direction.LEFT);
    controller_ = controller;
    controller_.setControllable(this);
  }
  
  /**
   * Update the character
   */
  public void update() {
    super.update();
    controller_.update();
    state_.update();
    checkCollisions();
  }
  
  /**
   * State pattern
   * @param newState
   */
  public void changeState(State newState) {
    state_ = newState;
  }
  
  /**
   * Called when the character stops moving
   */
  public void moveStop() {
    state_.moveStop();
  }

  /**
   * Try to go to the left
   */
  public void moveLeft() {
    state_.moveLeft();
  }

  /**
   * Try to go to the right
   */
  public void moveRight() {
    state_.moveRight();
  }

  /**
   * Try to go up
   */
  public void moveUp() {
    state_.moveUp();
  }

  /**
   * Try to go down
   */
  public void moveDown() {
    state_.moveDown();
  }

  /**
   * Try to move fast to the right
   */
  public void moveFastRight() {
    state_.moveFastRight();
  }
  
  /**
   * Try to move fast to the left
   */
  public void moveFastLeft() {
    state_.moveFastLeft();
  }
  
  // temporary
  private void checkMonstersCollisions() {
    Iterator<Monster> it = Globals.getInstance().getGame().getMonstersManager().getIterator();
    while (it.hasNext()) {
      Monster monster = it.next();
      if (collidesWith(monster, 1)) {
        if (state_.isAttacking()) {
          monster.setToRemove();
        } else if (collidesWith(monster, 0.75f)) {
          Globals.getInstance().lose();
        }
      }
    }
  }
  
  // temporary
  private void checkProjectilesCollisions() {
    Iterator<Projectile> it = Globals.getInstance().getGame().getProjectilesManager().getIterator();
    while (it.hasNext()) {
      Projectile proj = it.next();
      if (collidesWith(proj, 1.25f)) {
        if (state_.isAttacking()) {
          proj.setToRemove();
        } else if (collidesWith(proj, 1)) {
          Globals.getInstance().lose();
        }
      }
    }
  }
  
  // temporary
  private void checkTargetCollision() {
    TargetCharacter target = Globals.getInstance().getGame().getTarget();
    if (collidesWith(target, 1f)) {
      Globals.getInstance().win();
    }
  }
  
  // TODO temporary, all should be moved in game
  public void checkCollisions() {
    checkMonstersCollisions();
    checkProjectilesCollisions();
    checkTargetCollision();
  }
  
  public int getDir() {
    return state_.getDir();
  }
  
}




Java Source Code List

com.lucythemoocher.LucyTheMoocherActivity.java
com.lucythemoocher.FX.FXManager.java
com.lucythemoocher.FX.FX.java
com.lucythemoocher.Globals.Globals.java
com.lucythemoocher.actors.Actor.java
com.lucythemoocher.actors.ActorsManager.java
com.lucythemoocher.actors.Monster.java
com.lucythemoocher.actors.MonstersManager.java
com.lucythemoocher.actors.PlayerCharacter.java
com.lucythemoocher.actors.Projectile.java
com.lucythemoocher.actors.ProjectilesManager.java
com.lucythemoocher.actors.Tank.java
com.lucythemoocher.actors.TargetCharacter.java
com.lucythemoocher.actors.maincharacter.state.StateAttack.java
com.lucythemoocher.actors.maincharacter.state.StateFalling.java
com.lucythemoocher.actors.maincharacter.state.StateJumping.java
com.lucythemoocher.actors.maincharacter.state.StateNone.java
com.lucythemoocher.actors.maincharacter.state.StateRunning.java
com.lucythemoocher.actors.maincharacter.state.StateWallSliding.java
com.lucythemoocher.actors.maincharacter.state.StateWallWalking.java
com.lucythemoocher.actors.maincharacter.state.State.java
com.lucythemoocher.controls.AIController.java
com.lucythemoocher.controls.ActionController.java
com.lucythemoocher.controls.ButtonListener.java
com.lucythemoocher.controls.Controllable.java
com.lucythemoocher.controls.Controller.java
com.lucythemoocher.controls.GlobalController.java
com.lucythemoocher.controls.KeysListener.java
com.lucythemoocher.controls.TouchListener.java
com.lucythemoocher.events.EventNormal.java
com.lucythemoocher.events.EventSlow.java
com.lucythemoocher.events.Event.java
com.lucythemoocher.game.GameThread.java
com.lucythemoocher.game.Game.java
com.lucythemoocher.game.LevelLoader.java
com.lucythemoocher.graphics.ActorDrawer.java
com.lucythemoocher.graphics.Animation.java
com.lucythemoocher.graphics.Background.java
com.lucythemoocher.graphics.Camera.java
com.lucythemoocher.graphics.Drawable.java
com.lucythemoocher.graphics.Grid.java
com.lucythemoocher.graphics.HUD.java
com.lucythemoocher.graphics.Image.java
com.lucythemoocher.graphics.PersistentEffect.java
com.lucythemoocher.graphics.PersistentPic.java
com.lucythemoocher.graphics.PictureContainer.java
com.lucythemoocher.gui.MenuButtonListener.java
com.lucythemoocher.gui.MenuButtonTouchListener.java
com.lucythemoocher.gui.MenuButton.java
com.lucythemoocher.loops.CreditsLoop.java
com.lucythemoocher.loops.GameOverLoop.java
com.lucythemoocher.loops.InitMenuLoop.java
com.lucythemoocher.loops.LivesMenuLoop.java
com.lucythemoocher.loops.LoopGame.java
com.lucythemoocher.loops.LoopPause.java
com.lucythemoocher.loops.Loop.java
com.lucythemoocher.loops.MasterLoop.java
com.lucythemoocher.physics.Box.java
com.lucythemoocher.physics.Cinematic.java
com.lucythemoocher.physics.Map.java
com.lucythemoocher.sounds.SoundManager.java
com.lucythemoocher.sounds.SoundsState.java
com.lucythemoocher.sounds.StateLevel1.java
com.lucythemoocher.sounds.StateLevel2.java
com.lucythemoocher.sounds.StateLevel3.java
com.lucythemoocher.sounds.StateNormal.java
com.lucythemoocher.util.Direction.java
com.lucythemoocher.util.MathUtil.java
com.lucythemoocher.util.Resources.java
com.lucythemoocher.util.Timer.java