/** * 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)); }
/** @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); }
/** * 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(); }