예제 #1
0
  /**
   * Run an update on the model.
   *
   * @param input Input variables to the model.
   * @param timeElapsed Time in seconds since last update.
   */
  public void update(final ModelInput input, final float timeElapsed) {
    player.update(input, timeElapsed);
    for (AbstractBullet bullet : bulletManager.getBullets()) {
      bullet.doMovement(timeElapsed);
    }
    for (AbstractEnemy enemy : enemyManager.getEnemies()) {
      enemy.update(timeElapsed);
    }
    for (WeaponPickup pickup : pickupManager.getPickups()) {
      pickup.doMovement(timeElapsed);
    }

    enemySpawner.update(timeElapsed);

    checkCollisions();

    spawnPickups();
    enemyManager.clearDeadEnemies();
    bulletManager.clearBulletsOffScreen();
    pickupManager.clearPickupsOffScreen();
  }
예제 #2
0
  private void checkCollisions() {
    final List<IBullet> playerBullets = bulletManager.getBulletsFrom(PlayerID.PLAYER1);
    final List<IBullet> enemyBullets = bulletManager.getBulletsFrom(PlayerID.ENEMY);

    // Check player bullets against enemies
    for (IBullet b : playerBullets) {
      for (IEnemy e : enemyManager.getEnemies()) {
        if (b.collidesWith(e.getShip())) {
          e.getShip().receiveDamage(b.getDamage());
          pcs.firePropertyChange(Constants.EVENT_ENEMY_DAMAGED, null, e.getShip());
          b.markForRemoval();
        }
      }
    }

    // Check enemy bullets against player
    if (!player.isInvincible()) {
      for (IBullet b : enemyBullets) {
        if (b.collidesWith(player.getShip())) {
          player.getShip().receiveDamage(b.getDamage());
          pcs.firePropertyChange(Constants.EVENT_ENTITY_INVINCIBLE, null, player);
          b.markForRemoval();
          break;
        }
      }
    }

    // Check Items against player
    for (int i = 0; i < pickupManager.getPickups().size(); i++) {
      WeaponPickup wp = pickupManager.getPickups().get(i);
      if (wp.collidesWith(player.getShip())) {
        player.giveWeapon(WeaponFactory.getNewWeapon(wp.getObjectName()));
        pickupManager.removePickup(i);
        i--;
      }
    }
  }