Android Open Source - LucyTheMoocher Actor






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;
//from w  ww. j  ava 2 s .  c  o m
import java.util.ArrayList;

import com.lucythemoocher.controls.Controllable;
import com.lucythemoocher.graphics.Drawable;
import com.lucythemoocher.graphics.ActorDrawer;

import com.lucythemoocher.physics.Box;
import com.lucythemoocher.physics.Cinematic;

/**
 * A Drawable and physical entity interacting with the other
 * in a game
 */
public abstract class Actor implements Drawable, Controllable {
  protected Cinematic pos_;
  private boolean isToRemove_ = false;
  private int id_ = -1;
  private ActorDrawer drawer_;
  
  /**
   * Public constructor
   */
  public Actor() {
    drawer_ = new ActorDrawer();
    setCinematic(new Cinematic());
  }
  
  /**
   * Updates the Actor, should be called at every game's update
   */
  public void update() {
    pos_.update();
    getDrawer().update();
  }

  /**
   * Getter
   * @return True if the Actor should be removed from the game
   */
  public boolean isToRemove() {
    return isToRemove_;
  }

  /**
   * Notify that the actor should be removed from the game
   */
  public void setToRemove() {
    isToRemove_ = true;
  }

  /**
   * Mutator
   * @param id
   */
  public void setId(int id) {
    if ( id_ == -1 ) {
      id_ = id;
    }
  }
  
  /**
   * Getter
   * @return Actor's id
   */
  public int id() {
    return id_;
  }

  /**
   * Override Drawable.draw
   */
  public void draw() {
    getDrawer().draw((int)getX(), (int)getY());
  }
  
  /**
   * Called when the actor should stop 
   * (can be overrode)
   */
  public void moveStop() {
    pos_.moveStop();
  }

  /**
   * Called when the actor should go to left 
   * (can be overrode)
   */
  public void moveLeft() {
    pos_.moveLeft();
  }
  
  /**
   * Called when the actor should go to right 
   * (can be overrode)
   */
  public void moveRight() {
    pos_.moveRight();
  }

  /**
   * Called when the actor should go up 
   * (can be overrode)
   */
  public void moveUp() {
    pos_.moveUp();
  }
  
  public void moveFastLeft() {}

  public void moveFastRight() {}

  public void moveDown() {}
  
  /**
   * Called when the actor should attack 
   * (can be overrode)
   */
  public void attack() {
    
  }
  
  /**
   * Getter
   * @return Actor's bounding boxes
   */
  public ArrayList<Box> getBoundingBoxes() {
    return pos_.boundingBoxes();
  }
  
  /**
   * Getter
   * @return Actor's position x
   */
  public float getX() {
    return pos_.x();
  }

  /**
   * Getter
   * @return Actor's position y
   */
  public float getY() {
    return pos_.y();
  }
  
  /**
   * Getter (valid only once animation has been initialized)
   * @return Actor's width
   */
  public float getW() {
    return getDrawer().getAnim().getW();
  }
  
  /**
   * Getter (valid only once animation has been initialized)
   * @return Actor's height
   */  
  public float getH() {
    return getDrawer().getAnim().getH();
  }
  
  /**
   * Getter
   * @return Actor's drawer
   */
  public ActorDrawer getDrawer() {
    return drawer_;
  }
  
  /**
   * Getter
   * @return Actor's cinematic
   */
  public Cinematic getCinematic() {
    return pos_;
  }
  
  /**
   * Mutator
   * @param cinematic 
   */
  public void setCinematic(Cinematic cinematic) {
    pos_ = cinematic;
  }
  
  /**
   * Checks interaction between actors (if one is dead, returns false)
   * @param actor
   * @return True if actors are alive and if their bounding boxes collide
   */
  public boolean collidesWith(Actor actor, float ratio) {
    return !isToRemove() && !actor.isToRemove() && getCinematic().collidesWith(actor.getCinematic(), ratio);
  }
  
  // temporary
  public void checkCollision() {}
}




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