public void bump(int x, int y, boolean canBreakBricks) {
    byte block = level.getBlock(x, y);
    if ((Level.TILE_BEHAVIORS[block & 0xff] & Level.BIT_BUMPABLE) > 0) {
      // EHSAN Brick Bump counter added here
      bricksBumped++;
      if (block == 1) {
        Mario.gainHiddenBlock();
      }
      bumpInto(x, y - 1);
      byte blockData = level.getBlockData(x, y);
      if (blockData < 0) {
        level.setBlockData(x, y, (byte) (blockData + 1));
      }

      if (blockData == 0) {
        level.setBlock(x, y, (byte) 4);
        level.setBlockData(x, y, (byte) 4);
      }

      if (((Level.TILE_BEHAVIORS[block & 0xff]) & Level.BIT_SPECIAL) > 0) {
        //        	System.out.println("2222");
        if (randomGen.nextInt(5) == 0 && level.difficulty > 4) {
          addSprite(new GreenMushroom(this, x * cellSize + 8, y * cellSize + 8));
          ++level.counters.greenMushrooms;
        } else {
          if (!Mario.large) {
            addSprite(new Mushroom(this, x * cellSize + 8, y * cellSize + 8));
            ++level.counters.mushrooms;
          } else {
            addSprite(new FireFlower(this, x * cellSize + 8, y * cellSize + 8));
            ++level.counters.flowers;
          }
        }
      } else {

        Mario.gainCoin();
        addSprite(new CoinAnim(x, y));
      }
    }

    if ((Level.TILE_BEHAVIORS[block & 0xff] & Level.BIT_BREAKABLE) > 0) {
      bumpInto(x, y - 1);
      if (canBreakBricks) {
        bricksBumped++;
        level.setBlock(x, y, (byte) 0);
        for (int xx = 0; xx < 2; xx++)
          for (int yy = 0; yy < 2; yy++)
            addSprite(
                new Particle(
                    x * cellSize + xx * 8 + 4,
                    y * cellSize + yy * 8 + 4,
                    (xx * 2 - 1) * 4,
                    (yy * 2 - 1) * 4 - 8));
      } else {
        level.setBlockData(x, y, (byte) 4);
      }
    }
  }
  public void bumpInto(int x, int y) {
    byte block = level.getBlock(x, y);
    if (((Level.TILE_BEHAVIORS[block & 0xff]) & Level.BIT_PICKUPABLE) > 0) {
      Mario.gainCoin();
      level.setBlock(x, y, (byte) 0);
      addSprite(new CoinAnim(x, y + 1));
    }

    for (Sprite sprite : sprites) {
      sprite.bumpCheck(x, y);
    }
  }
Esempio n. 3
0
  public void spawn(LevelScene levelScene, int x, int y, int dir) {
    if (isDead) return;

    if (type == Sprite.KIND_ENEMY_FLOWER) {
      sprite = new FlowerEnemy(levelScene, x * 16 + 15, y * 16 + 24, x, y);
    } else if (type == Sprite.KIND_WAVE_GOOMBA) {
      sprite = new WaveGoomba(levelScene, x * 16 + 8, y * 16 + 15 - 3 * 16, dir, x, y);
    } else if (type == Sprite.KIND_PRINCESS) {
      sprite = new Princess(levelScene, x * 16 - 16, y * 16 - 15, x, y, levelScene);
    } else {
      //            sprite = new Enemy(levelScene, x*16+8, y*16+15, dir, type, winged);
      sprite = new Enemy(levelScene, x * 16 + 8, y * 16 + 15, dir, type, winged, x, y);
    }
    sprite.spriteTemplate = this;
    levelScene.addSprite(sprite);
  }
  public void tick() {
    if (GlobalOptions.isGameplayStopped) return;

    timeLeft--;
    if (timeLeft == 0) mario.die("Time out!");
    xCamO = xCam;
    yCamO = yCam;

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

    float targetXCam = mario.x - 160;

    xCam = targetXCam;

    if (xCam < 0) xCam = 0;
    if (xCam > level.length * cellSize - GlobalOptions.VISUAL_COMPONENT_WIDTH)
      xCam = level.length * cellSize - GlobalOptions.VISUAL_COMPONENT_WIDTH;

    fireballsOnScreen = 0;

    for (Sprite sprite : sprites) {
      if (sprite != mario) {
        float xd = sprite.x - xCam;
        float yd = sprite.y - yCam;
        if (xd < -64
            || xd > GlobalOptions.VISUAL_COMPONENT_WIDTH + 64
            || yd < -64
            || yd > GlobalOptions.VISUAL_COMPONENT_HEIGHT + 64) {
          removeSprite(sprite);
        } else {
          if (sprite instanceof Fireball) fireballsOnScreen++;
        }
      }
    }

    tickCount++;
    level.tick();

    //            boolean hasShotCannon = false;
    //            int xCannon = 0;

    for (int x = (int) xCam / cellSize - 1; x <= (int) (xCam + this.width) / cellSize + 1; x++)
      for (int y = (int) yCam / cellSize - 1; y <= (int) (yCam + this.height) / cellSize + 1; y++) {
        int dir = 0;

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

        SpriteTemplate st = level.getSpriteTemplate(x, y);

        if (st != null) {
          //                        if (st.getType() == Sprite.KIND_SPIKY)
          //                        {
          //                            System.out.println("here");
          //                        }

          if (st.lastVisibleTick != tickCount - 1) {
            if (st.sprite == null || !sprites.contains(st.sprite)) st.spawn(this, x, y, dir);
          }

          st.lastVisibleTick = tickCount;
        }

        if (dir != 0) {
          byte b = level.getBlock(x, y);
          if (((Level.TILE_BEHAVIORS[b & 0xff]) & Level.BIT_ANIMATED) > 0) {
            if ((b % cellSize) / 4 == 3 && b / cellSize == 0) {
              if ((tickCount - x * 2) % 100 == 0) {
                //                                    xCannon = x;
                for (int i = 0; i < 8; i++) {
                  addSprite(
                      new Sparkle(
                          x * cellSize + 8,
                          y * cellSize + (int) (Math.random() * cellSize),
                          (float) Math.random() * dir,
                          0,
                          0,
                          1,
                          5));
                }
                addSprite(new BulletBill(this, x * cellSize + 8 + dir * 8, y * cellSize + 15, dir));

                //                                    hasShotCannon = true;
              }
            }
          }
        }
      }

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

    byte levelElement = level.getBlock(mario.mapX, mario.mapY);
    if (levelElement == (byte) (13 + 3 * 16) || levelElement == (byte) (13 + 5 * 16)) {
      if (levelElement == (byte) (13 + 5 * 16)) mario.setOnTopOfLadder(true);
      else mario.setInLadderZone(true);
    } else if (mario.isInLadderZone()) {
      mario.setInLadderZone(false);
    }

    for (Sprite sprite : sprites) sprite.collideCheck();

    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;
              mario.setRacoon(false);
              // System.out.println("sprite = " + sprite);
              shell.die();
              ++this.killedCreaturesTotal;
            }
          }
        }
      }
    }
    shellsToCheck.clear();

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

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