/// <summary> /// Notifies the specified subject. /// </summary> /// <param name="subject">The subject.</param> public void Notify(ObservedSubject subject) { if (subject is Asteroid) { Asteroid ast = subject as Asteroid; if (ast.Size == AsteroidSize.large) { UpdateScore(20); } else if (ast.Size == AsteroidSize.medium) { UpdateScore(50); } else { UpdateScore(100); } } else if (subject is EnemyShip && (subject as EnemyShip).IsAlive == false) { EnemyShip ship = subject as EnemyShip; if (ship.Type == TypeShip.bigBossShip) { UpdateScore(200); } } else if (subject is PlayerShip) { if (!(subject as PlayerShip).IsAlive) { UpdateLife(PlayerShip.GetInstance().NumberOfLifes); } else if ((subject as PlayerShip).NumberOfLifes != this.numberOfLife) { this.numberOfLife = PlayerShip.GetInstance().NumberOfLifes; } else if (subject is Bonus) { if ((subject as Bonus).Type == BonusType.invincible) { bonusMessage = "Invincible"; } } } else if (subject is Bonus) { if ((subject as Bonus).Type == BonusType.doublePoints) { if ((subject as Bonus).BonusTime > 0) { bonusMessage = "Double Points"; scoreMultiplier = 2; } else { bonusMessage = ""; scoreMultiplier = 1; } } else if ((subject as Bonus).Type == BonusType.invincible) { if ((subject as Bonus).BonusTime > 0) { bonusMessage = "Invincible"; } else { bonusMessage = ""; } } else if ((subject as Bonus).Type == BonusType.extraPoints) { if ((subject as Bonus).BonusTime > 0) { score += 1000; } } else if ((subject as Bonus).Type == BonusType.slowDown) { if ((subject as Bonus).BonusTime > 0) { bonusMessage = "SlowMotio"; } else { bonusMessage = ""; } } else if ((subject as Bonus).Type == BonusType.none) { if ((subject as Bonus).BonusTime == -1) { scoreMultiplier = 1; bonusMessage = ""; } } } }
/// <summary> /// Loads the asteroids. /// </summary> private void LoadAsteroids() { for (int i = 0; i < LevelManager.GetInstance().NbAsteroids; i++) { Asteroid ast = new Asteroid(Content.Load<Texture2D>("Graphics\\sprites\\asteroid_big"), Vector2.Zero, i, AsteroidSize.large); ast.AddObserver(ui); LevelManager.GetInstance().Asteroids.Add(ast); } }
/// <summary> /// transforms bigger asteroids into smaller asteroids /// </summary> /// <param name="size">The size.</param> /// <param name="bulletRotationAngle">The bullet rotation angle.</param> private void AddSmallerAsteroid(AsteroidSize size, float bulletRotationAngle) { float newRotationAngle = (float)((Math.PI * 2) / 3); Asteroid newAst1; Asteroid newAst2; LevelManager.GetInstance().DeadAsteroids.Add(this); if (size == AsteroidSize.medium) { newAst1 = new Asteroid(Game1.contentManager.Load<Texture2D>("Graphics\\sprites\\asteroid_medium"), this.position, bulletRotationAngle + newRotationAngle, size); newAst2 = new Asteroid(Game1.contentManager.Load<Texture2D>("Graphics\\sprites\\asteroid_medium"), this.position, bulletRotationAngle - newRotationAngle, size); } else { newAst1 = new Asteroid(Game1.contentManager.Load<Texture2D>("Graphics\\sprites\\asteroid_small"), this.position, bulletRotationAngle + newRotationAngle, size); newAst2 = new Asteroid(Game1.contentManager.Load<Texture2D>("Graphics\\sprites\\asteroid_small"), this.position, bulletRotationAngle - newRotationAngle, size); } LevelManager.GetInstance().Asteroids.Add(newAst1); LevelManager.GetInstance().Asteroids.Add(newAst2); }