Esempio n. 1
0
  // Configurations for player upon death
  public void playerDeath() {
    SoundManager.get().playSound("death");
    deathTimer = new MillisecTimer();
    playerModel.death();
    distanceScrolled = 0.0f;
    scrollDelta = 0;
    activeBullets.clear();
    activeEnemies.clear();
    loadObjects(levelFile, queuedEnemies, levelPickups);

    // Game Over if player runs out of lives
    if (playerModel.getLives() < 0) {
      modelController.setMainModel(new GameOverModel(modelController));
      modelController
          .getViewController()
          .setMainView(new GameOverView(modelController.getViewController()));
    }
  }
Esempio n. 2
0
  /**
   * manages the boss. Checks if boss is dead and goes to next level, Check if boss is shot. Flips
   * boss image as necessary and finally handles the boss shooting
   */
  private void updateBoss(float dt) {

    if (boss != null) {

      // Check if boss needs flipped (Boss cannot access the player to get his x and y position so I
      // calculate this here)
      if (playerModel.getXPos() > boss.getXPos() + 30 && boss.direction == false) {
        boss.direction = true;
        if (boss.curFrame == 2) {
          boss.curFrame = 1;
        } else {
          boss.curFrame = 0;
        }
      } else if (playerModel.getXPos() < boss.getXPos() + 30 && boss.direction == true) {
        boss.direction = false;
        if (boss.curFrame == 1) {
          boss.curFrame = 2;
        } else {
          boss.curFrame = 3;
        }
      }
      //

      // Check if boss gets shot
      ArrayList<Bullet> bulletsToRemove = new ArrayList<Bullet>();
      for (Bullet b : playerModel.getBulletList()) {
        if (boss.checkBullet(b)) {
          bulletsToRemove.add(b);
        }
      }
      playerModel.getBulletList().removeAll(bulletsToRemove);

      // Check if player is hit by spinning arm
      // Here I check each piece of arm individually
      for (int i = 0; i < boss.armPieces.size(); i++) {
        // Player dies if he collides with arm
        if (Utils.boxCollision(
            new Rectangle(boss.armPieces.get(i).x, boss.armPieces.get(i).y, 32, 32),
            playerModel.getBoundingBox())) {
          boss.setXPos(300);
          boss.theta = 0;
          playerDeath();
        }
      }

      // check if boss is dead (Boss doesn't have enough access to change to a new test level)
      if (boss.health <= 0) {
        modelController.setMainModel(new LevelModel(modelController, "assets/underworld.json"));
        modelController
            .getViewController()
            .setMainView(new LevelView(modelController.getViewController(), "next"));
        SoundManager sm = SoundManager.get();
        sm.playSound("underworld");
        sm.stopSound("music");
      }

      // boss shoots 3 bullets at a time
      if (boss.shootBullet()) {

        if (boss.direction == false) {
          Vector2 playerPos =
              new Vector2(
                  playerModel.getXPos(),
                  playerModel
                      .getYPos()); // Obtains player's location to shoot towards that direction

          Vector2 enemyPos = new Vector2(boss.xPos + 8, boss.yPos + 19);
          Vector2 dir = playerPos.sub(enemyPos);
          activeBullets.add(new EnemyBullet(boss.xPos + 8, boss.yPos + 19, dir));

          enemyPos = new Vector2(boss.xPos + 5, boss.yPos + 47);
          dir = playerPos.sub(enemyPos);
          activeBullets.add(new EnemyBullet(boss.xPos + 5, boss.yPos + 47, dir));

          enemyPos = new Vector2(boss.xPos + 8, boss.yPos + 72);
          dir = playerPos.sub(enemyPos);
          activeBullets.add(new EnemyBullet(boss.xPos + 8, boss.yPos + 72, dir));

        } else {

          Vector2 playerPos =
              new Vector2(
                  playerModel.getXPos(),
                  playerModel
                      .getYPos()); // Obtains player's location to shoot towards that direction

          Vector2 enemyPos = new Vector2(boss.xPos + 84, boss.yPos + 19);
          Vector2 dir = playerPos.sub(enemyPos);
          activeBullets.add(new EnemyBullet(boss.xPos + 84, boss.yPos + 19, dir));

          enemyPos = new Vector2(boss.xPos + 88, boss.yPos + 47);
          dir = playerPos.sub(enemyPos);
          activeBullets.add(new EnemyBullet(boss.xPos + 88, boss.yPos + 47, dir));

          enemyPos = new Vector2(boss.xPos + 84, boss.yPos + 72);
          dir = playerPos.sub(enemyPos);
          activeBullets.add(new EnemyBullet(boss.xPos + 84, boss.yPos + 72, dir));
        }
      }

      boss.update(dt);
    }
  }