/// <summary> /// Updates the score. /// </summary> /// <param name="score">The score.</param> private void UpdateScore(int score) { this.score += score * scoreMultiplier; if (this.score > 10000 * nbLifeUP) { nbLifeUP++; UpdateLife(PlayerShip.GetInstance().NumberOfLifes + 1); } }
public UI() { this.numberOfLife = STARTING_LIFE; this.score = 0; this.scoreMultiplier = 1; this.AddObserver(PlayerShip.GetInstance()); playerLifeImage = Game1.contentManager.Load <Texture2D>("Graphics\\sprites\\PlayerShipLife"); backGroundUI = Game1.contentManager.Load <Texture2D>("Graphics\\UI\\UI"); origin = new Vector2(LIFE_ORIGIN_POS, LIFE_ORIGIN_POS); scoreFont = Game1.contentManager.Load <SpriteFont>("kootenay"); textPos = Vector2.Zero; this.bonusMessage = ""; }
/// <summary> /// Updates this instance. /// </summary> public void Update() { if (this.type != BonusType.none) { if (this.type == BonusType.extraLife) { PlayerShip.GetInstance().AddLife(); this.type = BonusType.none; } if (this.type == BonusType.extraPoints) { bonusTime = 0; this.NotifyAllObservers(); this.type = BonusType.none; } UpdateTimer(); } }
/// <summary> /// Moves this instance. /// </summary> public new void Move() { if (PlayerShip.GetInstance().CurrentBonus.Type == BonusType.slowDown) { if (!this.isSlow) { this.isSlow = true; this.velocity.X /= 2; this.velocity.Y /= 2; } if (PlayerShip.GetInstance().CurrentBonus.BonusTime < 0) { this.isSlow = false; this.velocity.X *= 2; this.velocity.Y *= 2; } } base.Move(); }
/// <summary> /// Gets the instance. /// </summary> /// <returns></returns> public static PlayerShip GetInstance() { if (ship == null) { ship = new PlayerShip(); } return ship; }
/// <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 = ""; } } } }