private void RemoveCollectedCollectables()
        {
            // Remove Collected Collectables
            for (Int32 index = 0; index < Collectables.Count; index++)
            {
                if (Collectables[index].IsCollected)
                {
                    CollectablesCollectionManger.CollectableEntities.Remove(Collectables[index]);
                    Game.CollectablesDrawingManager.DrawableEntities.Remove(Collectables[index]);
                    CollectablesUpdateManger.UpdatableEntities.Remove(Collectables[index]);
                    switch (Collectables[index].CollectionEntityType)
                    {
                    case CollectableEntityType.Health: HealthCollectablesSpawned--; break;

                    case CollectableEntityType.Gasoline: GasolineCollectablesSpawned--; break;

                    case CollectableEntityType.PistolAmmo: PistolAmmoCollectablesSpawned--; break;

                    case CollectableEntityType.ShotgunAmmo: ShotgunAmmoCollectablesSpawned--; break;

                    case CollectableEntityType.Energy: EnergyCollectablesSpawned--; break;

                    default: break;
                    }
                    Collectables.Remove(Collectables[index]);
                }
            }
        }
        public void Update(GameTime gameTime)
        {
            Player.Update(gameTime);
            Collectables.ForEach(c => c.Update(gameTime));

            List <Collectable> collected = Collectables.FindAll(c => c.HasCollidedWithPlayer);

            foreach (var item in collected)
            {
                AllTheSpritesWithinTheScene.Remove(item);
                Collectables.Remove(item);
            }



            var spawnPointsWithinTheViewport   = AllSpawnPoints.FindAll(c => Helper.CurrentGame.GraphicsDevice.Viewport.Bounds.Contains(c.SpritePosition - new Vector2(Camera.CamPos.X, Camera.CamPos.Y)));
            var despawnPointsWithinTheViewport = AllDespawnPoints.FindAll(c => Helper.CurrentGame.GraphicsDevice.Viewport.Bounds.Contains(c.SpritePosition - new Vector2(Camera.CamPos.X, Camera.CamPos.Y)));

            if (spawnPointsWithinTheViewport.Count > 0 && despawnPointsWithinTheViewport.Count > 0)
            {
                if (!AllEnemies.Peek().IsVisible)
                {
                    AllEnemies.Peek().IsVisible         = true;
                    AllEnemies.Peek().SpritePosition    = spawnPointsWithinTheViewport.ElementAt(Helper.random.Next(spawnPointsWithinTheViewport.Count)).SpritePosition;
                    AllEnemies.Peek().TargetDestination = despawnPointsWithinTheViewport.ElementAt(Helper.random.Next(despawnPointsWithinTheViewport.Count)).SpritePosition;
                }
            }

            if (AllEnemies.Peek().IsVisible)
            {
                AllEnemies.Peek().Update(gameTime);
                if (AllEnemies.Peek().TargetReached)
                {
                    AllEnemies.Enqueue(AllEnemies.Dequeue());
                }
            }


            if (Collectables.Count <= 0)
            {
                Gameover = true;
            }
        }
Exemple #3
0
        /// <summary>
        /// Checks interactions with collectables (bonus drops).
        /// </summary>
        private void CheckCollectables()
        {
            for (int i = 0; i < Collectables.Count; i++)
            {
                var collectable = Collectables[i];
                collectable.UpdatePosition();

                Vector hitDirection = new Vector();

                if (collectable.Intersect(PlayerPaddle, ref hitDirection))
                {
                    CurrentPlayerStats.LastCollectable = collectable.Type;
                    switch (collectable.Type)
                    {
                    case Collectable.CollectableType.clone_all:
                        List <PlayerBall> tempList = new List <PlayerBall>();
                        foreach (var ball in Balls)
                        {
                            tempList.Add(ball.CreateClone());
                        }
                        foreach (var clonedBall in tempList)
                        {
                            Balls.Add(clonedBall);
                        }
                        break;

                    case Collectable.CollectableType.increase_width:
                        if (PlayerPaddle.Width < GameAreaWidth / 2)
                        {
                            PlayerPaddle.Width += 20;
                        }
                        break;

                    case Collectable.CollectableType.decrease_width:
                        if (PlayerPaddle.Width > 40)
                        {
                            PlayerPaddle.Width -= 20;
                        }
                        break;

                    case Collectable.CollectableType.decrease_speed:
                        IncreaseSpeed(-0.5);
                        break;

                    case Collectable.CollectableType.add_life:
                        CurrentPlayerStats.Lives += 1;
                        break;

                    case Collectable.CollectableType.increase_damage:
                        foreach (var ball in Balls)
                        {
                            ball.Damage += 1;
                        }
                        break;
                    }
                    Collectables.Remove(collectable);
                }

                // Collectable is destroyed when lands on death trigger
                foreach (var trigger in CurrentLevel.DeathTriggers)
                {
                    if (collectable.Intersect(trigger, ref hitDirection))
                    {
                        Collectables.Remove(collectable);
                        continue;
                    }
                }
            }
        }