示例#1
0
  private boolean chain(int target) {
    if (chainsUsed) return false;

    Ballistica chain = new Ballistica(pos, target, Ballistica.PROJECTILE);

    if (chain.collisionPos != enemy.pos || Level.pit[chain.path.get(1)]) return false;
    else {
      int newPos = -1;
      for (int i : chain.subPath(1, chain.dist)) {
        if (!Level.solid[i] && Actor.findChar(i) == null) {
          newPos = i;
          break;
        }
      }

      if (newPos == -1) {
        return false;
      } else {
        final int newPosFinal = newPos;
        yell("get over here!");
        sprite.parent.add(
            new Chains(
                pos,
                enemy.pos,
                new Callback() {
                  public void call() {
                    Actor.addDelayed(new Pushing(enemy, enemy.pos, newPosFinal), -1);
                    enemy.pos = newPosFinal;
                    Dungeon.level.press(newPosFinal, enemy);
                    Cripple.prolong(enemy, Cripple.class, 4f);
                    if (enemy == Dungeon.hero) {
                      Dungeon.hero.interrupt();
                      Dungeon.observe();
                    }
                    next();
                  }
                }));
      }
    }
    chainsUsed = true;
    return true;
  }
示例#2
0
  private void build(int from, int to, boolean stopTarget, boolean stopChars, boolean stopTerrain) {
    int w = Level.WIDTH;

    int x0 = from % w;
    int x1 = to % w;
    int y0 = from / w;
    int y1 = to / w;

    int dx = x1 - x0;
    int dy = y1 - y0;

    int stepX = dx > 0 ? +1 : -1;
    int stepY = dy > 0 ? +1 : -1;

    dx = Math.abs(dx);
    dy = Math.abs(dy);

    int stepA;
    int stepB;
    int dA;
    int dB;

    if (dx > dy) {

      stepA = stepX;
      stepB = stepY * w;
      dA = dx;
      dB = dy;

    } else {

      stepA = stepY * w;
      stepB = stepX;
      dA = dy;
      dB = dx;
    }

    int cell = from;

    int err = dA / 2;
    while (Level.insideMap(cell)) {

      // if we're in a wall, collide with the previous cell along the path.
      if (stopTerrain && cell != sourcePos && !Level.passable[cell] && !Level.avoid[cell]) {
        collide(path.get(path.size() - 1));
      }

      path.add(cell);

      if ((stopTerrain && cell != sourcePos && Level.losBlocking[cell])
          || (cell != sourcePos && stopChars && Actor.findChar(cell) != null)
          || (cell == to && stopTarget)) {
        collide(cell);
      }

      cell += stepA;

      err += dB;
      if (err >= dA) {
        err = err - dA;
        cell = cell + stepB;
      }
    }
  }