コード例 #1
0
 /** spawns a pickup for every enemy marked as "should spawn a pickup" */
 private void spawnPickups() {
   for (IEnemy enemy : enemyManager.getEnemies()) {
     if (enemy.shouldSpawnPickup()) {
       pickupManager.addPickup(
           new WeaponPickup(enemy.getShip().getPositionClone(), enemy.getWeapon().getName()));
     }
   }
 }
コード例 #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--;
      }
    }
  }