Package com.pointcliki.dizgruntled.task

Source Code of com.pointcliki.dizgruntled.task.WalkTask

package com.pointcliki.dizgruntled.task;

import java.util.List;

import com.pointcliki.dizgruntled.grunt.GruntState;
import com.pointcliki.dizgruntled.grunt.Task;
import com.pointcliki.dizgruntled.logic.Grunt;
import com.pointcliki.dizgruntled.utils.PathFinder;
import com.pointcliki.grid.GridCoordinate;

public class WalkTask extends Task {
 
  /**
   * Serial key
   */
  private static final long serialVersionUID = -8452967463204168341L;
 
  GridCoordinate fTarget;
  protected List<GridCoordinate> fPath;
  protected int fPathIndex;

  public WalkTask(Grunt g, GridCoordinate xy) {
    super(g);
    fTarget = xy;
  }
 
  @Override
  public boolean next() {
    if (fPath.size() > fPathIndex) followPath();
    else {
      return false;
    }
    return true;
  }

  protected void followPath() {
    GridCoordinate xy = fPath.get(fPathIndex);
    fPathIndex++;
   
    xy = xy.subtract(fGrunt.getTile());
    fGrunt.animate("WALK", "WALK", xy);
    fGrunt.movement().move(xy);
    fGrunt.state(GruntState.MOVING);
  }

  public boolean start() {
    PathFinder finder = new PathFinder(fGrunt.levelScene());
    fPath = finder.calculate(fGrunt.getTile(), fTarget, 1000);
    fPathIndex = 1;
    return fPath != null;
  }
}
TOP

Related Classes of com.pointcliki.dizgruntled.task.WalkTask

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.