예제 #1
0
  public void moveToTarget() {
    int px = target.getX();
    int py = target.getY();

    int tileSize = World.current.tileSize;

    Vector2 start = new Vector2(getX() / tileSize, getY() / tileSize);
    Vector2 goal = new Vector2(px / tileSize, py / tileSize);

    path = World.current.findPath(start, goal);

    if (path != null) {
      if (path.size() > 0) {

        Vector2 vec = path.get(path.size() - 1).tile;
        if (position.x < (vec.x * tileSize)) {
          move(1, 0);
        }

        if (position.x > (vec.x * tileSize)) {
          move(-1, 0);
        }

        if (position.y < (vec.y * tileSize)) {
          move(0, 1);
        }

        if (position.y > (vec.y * tileSize)) {
          move(0, -1);
        }
      }
    }
  }
예제 #2
0
  /**
   * Spawns a mob somewhere on the map. Ensures it doesn't intersect anything and is on a spawn tile
   *
   * @param mob
   * @return
   */
  public boolean spawnMob(Mob mob) {
    float x = mob.getX();
    float y = mob.getY();
    TextureSet textureSet = mob.getWalkingTextureSet();

    // Check mob isn't out of bounds.
    if (x < 0
        || x > getMapWidth() - textureSet.getWidth()
        || y > getMapHeight() - textureSet.getHeight()) {
      return false;
    }

    // Check mob doesn't intersect anything.
    for (Entity entity : entities) {
      if (entity instanceof Character
          && (mob.intersects(entity.getX(), entity.getY(), entity.getWidth(), entity.getHeight())
              || mob.collidesX(0)
              || mob.collidesY(0))) {
        return false;
      }
    }

    if (getSpawnLayer().getCell((int) x / getTileWidth(), (int) y / getTileHeight()) == null) {
      return false;
    }

    entities.add(mob);
    return true;
  }
예제 #3
0
  public void setMobs(ArrayList<Mob> realMobs) {

    for (Mob m : realMobs) {

      JsonMob jm = new JsonMob(m.getX(), m.getY(), m.getClass().getName());
      jm.setID(m.getID());
      mobs.add(jm);
    }
  }