예제 #1
0
 /**
  * Resets the game
  *
  * @param difficulty Which difficulty it should be reset to.
  */
 public void reset(Difficulty difficulty) {
   bulletManager.clearAllBullets();
   enemyManager.clearAllEnemies();
   pickupManager.clearAllPickups();
   enemySpawner = new EnemySpawner(new RandomWaveList(difficulty));
   enemySpawner.addPropertyChangeListener(enemyManager);
   player.reset();
   player.giveWeapon(new BasicWeapon(bulletManager));
 }
예제 #2
0
  /** @param difficulty Which difficulty level the game model should be on. */
  public GameModel(Difficulty difficulty) {
    bulletManager = new BulletManager();
    enemyManager = new EnemyManager();
    pickupManager = new PickupManager();
    WeaponFactory.initialize(bulletManager);
    enemySpawner = new EnemySpawner(new RandomWaveList(difficulty));
    enemySpawner.addPropertyChangeListener(enemyManager);
    player = new Player(PlayerID.PLAYER1, bulletManager);
    pcs = new PropertyChangeSupport(this);

    // Player listens when enemies are killed
    enemyManager.addPropertyChangeListener(player);
  }
예제 #3
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();
  }