Пример #1
0
  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);
      }
    }
  }
Пример #2
0
  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);
    }
  }
Пример #3
0
  public void bumpInto(int x, int y) {
    byte block = level.getBlock(x, y);
    if (((Level.TILE_BEHAVIORS[block & 0xff]) & Level.BIT_PICKUPABLE) > 0) {
      Mario.getCoin();
      sound.play(
          Art.samples[Art.SAMPLE_GET_COIN], new FixedSoundSource(x * 16 + 8, y * 16 + 8), 1, 1, 1);
      level.setBlock(x, y, (byte) 0);
      addSprite(new CoinAnim(x, y + 1));

      // TODO no idea when this happens... maybe remove coin count
      if (recorder != null) recorder.recordCoin();
    }

    for (Sprite sprite : sprites) {
      sprite.bumpCheck(x, y);
    }
  }
Пример #4
0
 public int getMarioMode() {
   return mario.getMode();
 }
Пример #5
0
  public void reset(MarioAIOptions marioAIOptions) {
    //        System.out.println("\nLevelScene RESET!");
    //        this.gameViewer = setUpOptions[0] == 1;
    //        System.out.println("this.mario.isMarioInvulnerable = " +
    // this.mario.isMarioInvulnerable);
    //    this.levelDifficulty = marioAIOptions.getLevelDifficulty();
    //        System.out.println("this.levelDifficulty = " + this.levelDifficulty);
    //    this.levelLength = marioAIOptions.getLevelLength();
    //        System.out.println("this.levelLength = " + this.levelLength);
    //    this.levelSeed = marioAIOptions.getLevelRandSeed();
    //        System.out.println("levelSeed = " + levelSeed);
    //    this.levelType = marioAIOptions.getLevelType();
    //        System.out.println("levelType = " + levelType);

    GlobalOptions.FPS = marioAIOptions.getFPS();
    //        System.out.println("GlobalOptions.FPS = " + GlobalOptions.FPS);
    GlobalOptions.isPowerRestoration = marioAIOptions.isPowerRestoration();
    //        System.out.println("GlobalOptions.isPowerRestoration = " +
    // GlobalOptions.isPowerRestoration);
    //    GlobalOptions.isPauseWorld = marioAIOptions.isPauseWorld();
    GlobalOptions.areFrozenCreatures = marioAIOptions.isFrozenCreatures();
    //        System.out.println("GlobalOptions = " + GlobalOptions.isPauseWorld);
    //        GlobalOptions.isTimer = marioAIOptions.isTimer();
    //        System.out.println("GlobalOptions.isTimer = " + GlobalOptions.isTimer);
    //        isToolsConfigurator = setUpOptions[11] == 1;
    this.setTimeLimit(marioAIOptions.getTimeLimit());
    //        System.out.println("this.getTimeLimit() = " + this.getTimeLimit());
    //        this.isViewAlwaysOnTop() ? 1 : 0, setUpOptions[13]
    GlobalOptions.isVisualization = marioAIOptions.isVisualization();
    //        System.out.println("visualization = " + visualization);

    killedCreaturesTotal = 0;
    killedCreaturesByFireBall = 0;
    killedCreaturesByStomp = 0;
    killedCreaturesByShell = 0;
    bricksBumped = 0;

    marioInitialPos = marioAIOptions.getMarioInitialPos();
    greenMushroomMode = marioAIOptions.getGreenMushroomMode();

    if (replayer != null) {
      try {
        //            replayer.openNextReplayFile();
        replayer.openFile("level.lvl");
        level = (Level) replayer.readObject();
        level.counters.resetUncountableCounters();
        //            replayer.closeFile();
        //            replayer.closeRecorder();
      } catch (IOException e) {
        System.err.println("[Mario AI Exception] : level reading failed");
        e.printStackTrace();
      } catch (Exception e) {
        e.printStackTrace();
      }
    } else level = LevelGenerator.createLevel(marioAIOptions);

    String fileName = marioAIOptions.getLevelFileName();
    if (!fileName.equals("")) {
      try {
        Level.save(level, new ObjectOutputStream(new FileOutputStream(fileName)));
      } catch (IOException e) {
        System.err.println("[Mario AI Exception] : Cannot write to file " + fileName);
        e.printStackTrace();
      }
    }
    this.levelSeed = level.randomSeed;
    this.levelLength = level.length;
    this.levelHeight = level.height;
    this.levelType = level.type;
    this.levelDifficulty = level.difficulty;

    Sprite.spriteContext = this;
    sprites.clear();
    this.width = GlobalOptions.VISUAL_COMPONENT_WIDTH;
    this.height = GlobalOptions.VISUAL_COMPONENT_HEIGHT;

    Sprite.setCreaturesGravity(marioAIOptions.getCreaturesGravity());
    Sprite.setCreaturesWind(marioAIOptions.getWind());
    Sprite.setCreaturesIce(marioAIOptions.getIce());
    Mario.resetStatic(marioAIOptions);

    bonusPoints = -1;

    mario = new Mario(this);
    // System.out.println("mario = " + mario);
    memo = "";

    sprites.add(mario);
    startTime = 1;
    timeLeft = timeLimit * GlobalOptions.mariosecondMultiplier;

    tickCount = 0;
  }
Пример #6
0
 public boolean isMarioAbleToJump() {
   return mario.mayJump();
 }
Пример #7
0
 public boolean isMarioOnGround() {
   return mario.isOnGround();
 }
Пример #8
0
 public int getMarioStatus() {
   return mario.getStatus();
 }
Пример #9
0
 public boolean isMarioAbleToShoot() {
   return mario.isAbleToShoot();
 }
Пример #10
0
 public boolean isLevelFinished() {
   return (mario.getStatus() != Mario.STATUS_RUNNING);
 }
Пример #11
0
  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();
  }
Пример #12
0
  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) {
      bumpInto(x, y - 1);
      level.setBlock(x, y, (byte) 4);

      if (((Level.TILE_BEHAVIORS[block & 0xff]) & Level.BIT_SPECIAL) > 0) {
        sound.play(
            Art.samples[Art.SAMPLE_ITEM_SPROUT],
            new FixedSoundSource(x * 16 + 8, y * 16 + 8),
            1,
            1,
            1);
        if (!Mario.large) {
          addSprite(new Mushroom(this, x * 16 + 8, y * 16 + 8));
        } else {
          addSprite(new FireFlower(this, x * 16 + 8, y * 16 + 8));
        }

        if (recorder != null) {
          recorder.blockPowerDestroyRecord();
        }
      } else {
        // TODO should only record hidden coins (in boxes)
        if (recorder != null) {
          recorder.blockCoinDestroyRecord();
        }

        Mario.getCoin();
        sound.play(
            Art.samples[Art.SAMPLE_GET_COIN],
            new FixedSoundSource(x * 16 + 8, y * 16 + 8),
            1,
            1,
            1);
        addSprite(new CoinAnim(x, y));
      }
    }

    if ((Level.TILE_BEHAVIORS[block & 0xff] & Level.BIT_BREAKABLE) > 0) {
      bumpInto(x, y - 1);
      if (canBreakBricks) {
        if (recorder != null) {
          recorder.blockEmptyDestroyRecord();
        }

        sound.play(
            Art.samples[Art.SAMPLE_BREAK_BLOCK],
            new FixedSoundSource(x * 16 + 8, y * 16 + 8),
            1,
            1,
            1);
        level.setBlock(x, y, (byte) 0);
        for (int xx = 0; xx < 2; xx++)
          for (int yy = 0; yy < 2; yy++)
            addSprite(
                new Particle(
                    x * 16 + xx * 8 + 4,
                    y * 16 + yy * 8 + 4,
                    (xx * 2 - 1) * 4,
                    (yy * 2 - 1) * 4 - 8));
      }
    }
  }
Пример #13
0
  public void tick() {
    timeLeft--;

    if (widthArrow < 0) {
      widthArrow *= -1;
      tipWidthArrow *= -1;

      xPositionsArrow =
          new int[] {
            xArrow + -widthArrow / 2,
            xArrow + widthArrow / 2 - tipWidthArrow,
            xArrow + widthArrow / 2 - tipWidthArrow,
            xArrow + widthArrow / 2,
            xArrow + widthArrow / 2 - tipWidthArrow,
            xArrow + widthArrow / 2 - tipWidthArrow,
            xArrow + -widthArrow / 2
          };
      yPositionsArrow =
          new int[] {
            yArrow + -heightArrow / 4,
            yArrow + -heightArrow / 4,
            yArrow + -heightArrow / 2,
            yArrow + 0,
            yArrow + heightArrow / 2,
            yArrow + heightArrow / 4,
            yArrow + heightArrow / 4
          };
    }

    if (timeLeft == 0) {
      mario.dieTime();
    }

    xCamO = xCam;
    yCamO = yCam;

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

    float targetXCam = mario.x - 160;

    xCam = targetXCam;

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

    /* if (recorder != null) { recorder.addTick(mario.getKeyMask()); }
     *
     * if (replayer!=null) { mario.setKeys(replayer.nextTick()); } */

    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();

      boolean hasShotCannon = false;
      int xCannon = 0;

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

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

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

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

            st.lastVisibleTick = tick;
          }

          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) {
                  xCannon = x;
                  for (int i = 0; i < 8; i++) {
                    addSprite(
                        new Sparkle(
                            x * 16 + 8,
                            y * 16 + (int) (Math.random() * 16),
                            (float) Math.random() * dir,
                            0,
                            0,
                            1,
                            5));
                  }
                  addSprite(new BulletBill(this, x * 16 + 8 + dir * 8, y * 16 + 15, dir));
                  hasShotCannon = true;
                }
              }
            }
          }
        }

      if (hasShotCannon) {
        sound.play(
            Art.samples[Art.SAMPLE_CANNON_FIRE],
            new FixedSoundSource(xCannon * 16, yCam + 120),
            1,
            1,
            1);
      }

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

      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;
                shell.die();
              }
            }
          }
        }
      }
      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();

    // TODO: THIS IS TEST FLIP
    // if(keys[Mario.KEY_UP] && tick%2 == 0)
    // level.startFlipping = true;

    // if(level.canFlip)
    // flip();
  }