コード例 #1
0
 /// <summary>
 /// Adds the bonus.
 /// </summary>
 /// <param name="_type">The _type.</param>
 public override void AddBonus(Bonus.Type _type)
 {
     base.AddBonus(_type);
     if (_type == Bonus.Type.STOP_TIME)
     {
         velocity = Vector2.Zero;
     }
     else if (_type == Bonus.Type.ASTEROID_EXPLODE)
     {
         Bullet fakeBullet = new Bullet();
         fakeBullet.Initialize(sprite, position);
         HasCollided(fakeBullet);
     }
 }
コード例 #2
0
        /// <summary>
        /// Updates this instance.
        /// @see Initialize
        /// @see AddBonusObserver
        /// @see AddDrawableObject
        /// </summary>
        public void Update()
        {
            if (!paused)
            {
                scene.Update(AsteroidGame.screenBox);

                if (DateTime.Now - timeLastObjectSpawned >= objectSpawningDelay)
                {
                    timeLastObjectSpawned = DateTime.Now;
                    Bonus bonus = null;
                    Vector2 position = new Vector2(RandomGenerator.GetRandomFloat(0, AsteroidGame.screenBox.Max.X), RandomGenerator.GetRandomFloat(170, AsteroidGame.screenBox.Max.Y));
                    switch (RandomGenerator.GetRandomInt(0, 4))
                    {
                        case 0:
                            bonus = new Bonus(Bonus.Type.SHRINK);
                            bonus.Initialize(new Sprite(content.Load<Texture2D>("Graphics\\hatChef"), 0.3f), position);
                            bonus.AddBonusObserver(Player.GetInstance());
                            break;
                        case 1:
                            bonus = new Bonus(Bonus.Type.BIGGER_BULLETS);
                            bonus.Initialize(new Sprite(content.Load<Texture2D>("Graphics\\hatBiggerBullet"), 0.3f), position);
                            bonus.AddBonusObserver(Player.GetInstance());
                            break;
                        case 2:
                            bonus = new Bonus(Bonus.Type.STOP_TIME);
                            bonus.Initialize(new Sprite(content.Load<Texture2D>("Graphics\\hat_time"), 0.3f), position);
                            foreach(Asteroid asteroid in scene.GetAllAsteroids())
                            {
                                bonus.AddBonusObserver(asteroid);
                            }
                            break;
                        case 3:
                            bonus = new Bonus(Bonus.Type.ASTEROID_EXPLODE);
                            bonus.Initialize(new Sprite(content.Load<Texture2D>("Graphics\\hatExplosion"), 0.3f), position);
                            foreach (Asteroid asteroid in scene.GetAllAsteroids())
                            {
                                bonus.AddBonusObserver(asteroid);
                            }
                            break;
                        case 4:
                            bonus = new Bonus(Bonus.Type.SCORE_TWICE);
                            bonus.Initialize(new Sprite(content.Load<Texture2D>("Graphics\\hat2X"), 0.3f), new Vector2(700, 500));
                            bonus.AddBonusObserver(Player.GetInstance());
                            break;
                    }
                    scene.AddDrawableObject(bonus);
                    scene.AddDrawableObject(EnemyFactory.createEnemy(RandomGenerator.GetRandomInt(1, 3)));
                }

                if (scene.onlyHasPlayer())
                {
                    AsteroidGame.gameState = new PlayState(level + 1);
                    AsteroidGame.gameState.LoadContent(content);
                }
            }
        }
コード例 #3
0
 /// <summary>
 /// Adds the bonus.
 /// </summary>
 /// <param name="_type">The _type.</param>
 public virtual void AddBonus(Bonus.Type _type)
 {
 }
コード例 #4
0
ファイル: Player.cs プロジェクト: SamuelDaigle/TP1-Asteroids
 /// <summary>
 /// Adds the bonus.
 /// </summary>
 /// <param name="_type">The _type.</param>
 public override void AddBonus(Bonus.Type _type)
 {
     if (_type == Bonus.Type.SHRINK && !hasShrunk)
     {
         hasShrunk = true;
         sprite.Scale /= 2;
     }
     else if (_type == Bonus.Type.BIGGER_BULLETS)
     {
         for (int i = 0; i < MAX_NB_BULLETS; i++)
         {
             Bullet bullet = bullets.Dequeue();
             bullet.SpriteImage.Scale = 0.1f;
             bullets.Enqueue(bullet);
         }
     }
     else if (_type == Bonus.Type.SCORE_TWICE)
     {
         scoreRatio = 2;
     }
 }