public static void Update(GameTime delta, List<Entity> entities, TileMap tileMap)
        {
            //Add new particles to the current list
            foreach (Particle particle in SpawnList)
            {
                ParticleList.AddLast(particle);
            }
            SpawnList.Clear();

            //Single threaded update
            if (ParticleList.Count < 1000 || true || false || maybe) // Maybe do this ???
            {
                LinkedListNode<Particle> node = ParticleList.First;
                while (node != null)
                {
                    //Update particle
                    node.Value.Update(delta, entities, tileMap);

                    //Has this particle been destroyed?
                    if (node.Value.IsDestroyed)
                    {
                        LinkedListNode<Particle> remove = node;
                        node = node.Next;
                        ParticleList.Remove(remove);
                        continue;
                    }

                    //Get next particle to update
                    node = node.Next;
                }
            }

            //Parallel update
            else
            {
                Parallel.ForEach(ParticleList, particle => particle.Update(delta, null, null));

                //Remove destroyed particles
                for (LinkedListNode<Particle> node = ParticleList.First; node != null; )
                {
                    LinkedListNode<Particle> next = node.Next;
                    if (node.Value.IsDestroyed) ParticleList.Remove(node);
                    node = next;
                }
            }
        }
        public PlayingState(List<Player> playerList, bool versusMode)
        {
            //Initialize level
            _entities = new List<Entity>(64);
            _tileMap = new TileMap(24, 24);
            _versusMode = versusMode;

            //Initialize players
            _entities.AddRange(playerList);
            _playerList = playerList;

            //Place players somewher safe
            foreach (Player player in playerList)
            {
                player.Position = GetRandomSpawnPosition();
            }

            //Reset particles
            ParticleEngine.Clear();

            Camera.WorldRectangle = new Rectangle(0, 0, _tileMap.RealWidth, _tileMap.RealHeight);

            //Player 1 GUI
            Label player1Name = new Label(_playerList[0].Name, 200, 5);
            components.Add(player1Name);

            _player1Score = new Label("SCORE: 0", 200, 32);
            components.Add(_player1Score);

            //Player 2 GUI
            if (_playerList.Count > 1)
            {
                Label player2Name = new Label(_playerList[1].Name, 500, 5);
                components.Add(player2Name);

                _player2Score = new Label("SCORE: 0", 500, 32);
                components.Add(_player2Score);
            }
        }
 public void Render(TileMap tileMap, int cameraOffset)
 {
     tileMap.Draw(_spriteBatch, cameraOffset);
 }
        public void Update(GameTime delta, List<Entity> entities, TileMap tileMap)
        {
            if (IsCollidable)
            {
                //Area of effect!
                if (_areaOfEffect != null)
                {
                    //Do we hit an gameObject?
                    foreach (Entity entity in entities.Where(entity => entity.IsCollidable && entity.HandleCollision(this, false) && entity.Team != Team && !_areaOfEffect.Contains(entity)))
                    {
                        entity.Damage(_template.GetValue<float>(ParticleValues.Damage), _owner);
                        _areaOfEffect.Add(entity);
                    }
                }

                //Single target only
                else
                {
                    //Did we hit a wall?
                    Point? tileCollision = tileMap.GetCollidedTile(this);
                    if (tileCollision.HasValue)
                    {
                        tileMap.DestroyTile(tileCollision.Value.X, tileCollision.Value.Y, _template.GetValue<float>(ParticleValues.Damage));
                        Destroy();
                        return;
                    }

                    //Do we hit an gameObject?
                    foreach (Entity entity in entities.Where(entity => entity.IsCollidable && entity.HandleCollision(this, false) && entity.Team != Team))
                    {
                        entity.Damage(_template.GetValue<float>(ParticleValues.Damage), _owner);
                        Destroy();
                        return;
                    }
                }

            }

            Update(delta, (KeyboardState?)null, null);

            //Make AOE apply damage to tiles (but only once)
            if (IsCollidable && _areaOfEffect != null && !_aoeFinished)
            {
                _aoeFinished = true;
                Vector2 bounds = new Vector2(Width, Height);
                Point start = tileMap.GetSquareAtPixel(Position - bounds/2);
                Point end = tileMap.GetSquareAtPixel(Position + bounds/2);
                for (int x = start.X; x <= end.X; ++x)
                {
                    for (int y = start.Y; y <= end.Y; ++y)
                    {
                        tileMap.DestroyTile(x, y, _template.GetValue<float>(ParticleValues.Damage));
                    }
                }
            }
        }