private Collectable CreateCollectableFromXmlNode(XElement node, Vector2 worldPosition)
        {
            Collectable newCollectable = null;

            switch (node.Name.ToString())
            {
            case GoldenTicket.Data_Node_Name:
                if (!Data.Profile.CurrentAreaData.GoldenTicketHasBeenCollectedFromLevel(worldPosition))
                {
                    newCollectable = new GoldenTicket();
                }
                break;

            case ScoringCandy.Data_Node_Name:
                newCollectable = new ScoringCandy();
                ((ScoringCandy)newCollectable).ScoreValue = (int)node.Attribute("score");
                _candyCount++;
                break;
            }

            if (newCollectable != null)
            {
                newCollectable.ID = string.Concat(Serialized_Data_Identifier, _nextCollectableID++);
                newCollectable.SetTextureAndRelatedValues(node.Attribute("texture").Value);
            }

            return(newCollectable);
        }
 public static void ReinstateSerializedCollectables(List <XElement> collectableData)
 {
     foreach (XElement el in collectableData)
     {
         Collectable newCollectable = (Collectable)Activator.CreateInstance(Type.GetType(el.Attribute("type").Value));
         newCollectable.ID = el.Attribute("id").Value;
         Factory._registerComponent(newCollectable);
     }
 }
        public static void LoadCollectables(XElement collectableDataGroup)
        {
            Factory.Reset();

            if (collectableDataGroup != null)
            {
                foreach (XElement node in collectableDataGroup.Elements())
                {
                    Vector2 worldPosition = new Vector2((float)node.Attribute("x"), (float)node.Attribute("y")) +
                                            (new Vector2(Definitions.Grid_Cell_Pixel_Size) / 2.0f);

                    Collectable toAdd = Factory.CreateCollectableFromXmlNode(node, worldPosition);
                    if (toAdd != null)
                    {
                        toAdd.WorldPosition = worldPosition;
                        Factory._registerComponent(toAdd);
                    }
                }
            }
        }
 public void UpdateFromItemCollection(Collectable collectedItem)
 {
     if (collectedItem is ScoringCandy)
     {
         AddScoreForUnits(((ScoringCandy)collectedItem).ScoreValue, 1);
         _candiesCollected++;
         SoundEffectManager.PlayEffect("collect-candy");
     }
     else if (collectedItem is GoldenTicket)
     {
         HandleGoldenTicketCollection(collectedItem);
     }
 }
 private void HandleCollectableCollection(Collectable collectedItem)
 {
     _levelData.UpdateFromItemCollection(collectedItem);
 }