Example #1
0
  @Override
  public Object clone() throws CloneNotSupportedException {
    LevelScene c = (LevelScene) super.clone();
    c.mario = (Mario) this.mario.clone();
    c.level = (Level) this.level.clone();
    c.mario.world = c;

    List<Sprite> clone = new ArrayList<Sprite>(this.sprites.size());
    for (Sprite item : this.sprites) {
      if (item == mario) {
        clone.add(c.mario);
      } else {
        Sprite s = (Sprite) item.clone();
        if (s.kind == Sprite.KIND_SHELL && ((Shell) s).carried && c.mario.carried != null)
          c.mario.carried = s;
        s.world = c;
        clone.add(s);
      }
    }
    c.sprites = clone;
    return c;
  }
Example #2
0
  public void tick() {
    // advance the world state. directly from the original physics engine.
    timeLeft--;
    if (timeLeft == 0) {
      mario.die();
    }
    xCamO = xCam;
    yCamO = yCam;

    if (startTime > 0) {
      startTime++;
    }

    float targetXCam = mario.x - 160;

    xCam = targetXCam;

    if (xCam < 0) xCam = 0;
    if (xCam > level.width * 16 - 320) xCam = level.width * 16 - 320;

    fireballsOnScreen = 0;

    for (Sprite sprite : sprites) {
      if (sprite != mario) {
        float xd = sprite.x - xCam;
        float yd = sprite.y - yCam;
        if (xd < -64 || xd > 320 + 64 || yd < -64 || yd > 240 + 64) {
          removeSprite(sprite);
        } else {
          if (sprite instanceof Fireball) {
            fireballsOnScreen++;
          }
        }
      }
    }
    if (paused) {
      for (Sprite sprite : sprites) {
        if (sprite == mario) {
          sprite.tick();
        } else {
          sprite.tickNoMove();
        }
      }
    } else {
      tick++;
      level.tick();

      for (int x = (int) xCam / 16 - 1; x <= (int) (xCam + 320) / 16 + 1; x++)
        for (int y = (int) yCam / 16 - 1; y <= (int) (yCam + 240) / 16 + 1; y++) {
          int dir = 0;

          if (x * 16 + 8 > mario.x + 16) dir = -1;
          if (x * 16 + 8 < mario.x - 16) dir = 1;

          if (dir != 0) {
            byte b = level.getBlock(x, y);
            if (((Level.TILE_BEHAVIORS[b & 0xff]) & Level.BIT_ANIMATED) > 0) {
              if ((b % 16) / 4 == 3 && b / 16 == 0) {
                if ((tick - x * 2) % 100 == 0) {
                  addSprite(new BulletBill(this, x * 16 + 8 + dir * 8, y * 16 + 15, dir));
                }
              }
            }
          }
        }

      for (Sprite sprite : sprites) {
        sprite.tick();
      }

      for (Sprite sprite : sprites) {
        sprite.collideCheck();
      }
      // System.out.println("Sim Mario ya: " + mario.ya);
      for (Shell shell : shellsToCheck) {
        for (Sprite sprite : sprites) {
          if (sprite != shell && !shell.dead) {
            if (sprite.shellCollideCheck(shell)) {
              if (mario.carried == shell && !shell.dead) {
                mario.carried = null;
                shell.die();
              }
              enemiesKilled++;
            }
          }
        }
      }
      shellsToCheck.clear();

      for (Fireball fireball : fireballsToCheck) {
        for (Sprite sprite : sprites) {
          if (sprite != fireball && !fireball.dead) {
            if (sprite.fireballCollideCheck(fireball)) {
              fireball.die();
              enemiesKilled++;
            }
          }
        }
      }
      fireballsToCheck.clear();
    }

    sprites.addAll(0, spritesToAdd);
    sprites.removeAll(spritesToRemove);
    spritesToAdd.clear();
    spritesToRemove.clear();
  }