Exemple #1
0
        /// <summary>
        /// AddObject is called to add a new GameObject to the Objects list.
        /// </summary>
        ///
        public void AddObject(GameObject newObject)
        {
            Objects.Add(newObject);


            // Adds to Drawables if drawable.
            if (newObject is Drawable drawable)
            {
                Drawables.Add(drawable);
            }



            // Adds to Collidables if collidable.
            if (newObject is Collider)
            {
                Collidables.Add(newObject);
            }

            if (newObject is Player)
            {
                Player = (Player)newObject;
            }

            if (newObject is Npc)
            {
                Npcs.Add((Npc)newObject);
            }

            if (newObject is EndObject)
            {
                End = (EndObject)newObject;
            }

            if (newObject is Event)
            {
                Events.Add((Event)newObject);
            }
        }
Exemple #2
0
        private void CreateInteractors(XElement objectData)
        {
            // Data taken from the object element.
            Vector2 size     = new Vector2(float.Parse(objectData.Attribute("width").Value), float.Parse(objectData.Attribute("height").Value));
            Vector2 position = new Vector2(float.Parse(objectData.Attribute("x").Value), float.Parse(objectData.Attribute("y").Value) - size.Y);
            string  requires = null;
            string  gives    = null;
            string  route    = null;
            string  subType  = null;

            string actors    = "";
            float  baseDepth = 0.4f;

            #region object property navigation
            if (objectData.Element("properties") != null)
            {
                IEnumerable <XElement> properties = objectData.Element("properties").Elements();
                foreach (XElement property in properties)
                {
                    if (property.Attribute("name").Value == "Requires")
                    {
                        requires = property.Attribute("value").Value;
                    }
                    if (property.Attribute("name").Value == "Gives")
                    {
                        gives = property.Attribute("value").Value;
                    }
                    if (property.Attribute("name").Value == "SubType")
                    {
                        subType = property.Attribute("value").Value;
                    }
                    if (property.Attribute("name").Value == "Route")
                    {
                        route = property.Attribute("value").Value;
                    }
                    if (property.Attribute("name").Value == "Actors")
                    {
                        actors = property.Attribute("value").Value;
                    }
                }
            }


            #endregion

            #region object creation
            if (objectData.Attribute("type").Value == "Interactable")
            {
                InteractableObject currentObject = new InteractableObject(position, size, getTexture(Int32.Parse(objectData.Attribute("gid").Value)).Item1, baseDepth,
                                                                          objectData.Attribute("name").Value, requires, gives);
                levelRead.AddObject(currentObject);
            }
            if (objectData.Attribute("type").Value == "NPC")
            {
                Tuple <Texture2D, string> textureData = getTexture(Int32.Parse(objectData.Attribute("gid").Value));
                Npc currentObject = new Npc(position, size, textureData.Item1, baseDepth, route,
                                            objectData.Attribute("name").Value, textureData.Item2, requires, gives);
                levelRead.AddObject(currentObject);
            }

            if (objectData.Attribute("type").Value == "Actor")
            {
                Tuple <Texture2D, string> textureData = getTexture(Int32.Parse(objectData.Attribute("gid").Value));

                if (subType.Equals("NPC"))
                {
                    Npc currentObject = new Npc(position, size, textureData.Item1, baseDepth, route,
                                                objectData.Attribute("name").Value, textureData.Item2, true, requires, gives);
                    levelRead.AddObject(currentObject);
                }
                else
                {
                    InteractableObject currentObject = new InteractableObject(position, size, getTexture(Int32.Parse(objectData.Attribute("gid").Value)).Item1, baseDepth,
                                                                              objectData.Attribute("name").Value, requires, gives);
                    levelRead.AddObject(currentObject);
                }
            }

            if (objectData.Attribute("type").Value == "Event")
            {
                Event currentObject = new Event(position, size, actors);
                levelRead.AddObject(currentObject);
            }
            if (objectData.Attribute("type").Value == "EndObject")
            {
                EndObject currentObject = new EndObject(position, size, getTexture(Int32.Parse(objectData.Attribute("gid").Value)).Item1, baseDepth, requires);
                levelRead.AddObject(currentObject);
            }
            #endregion
        }