Ejemplo n.º 1
0
        /// <summary>
        /// Destroys the two way relationship between the object and the list.
        /// </summary>
        /// <param name="list">the list to remove the game object from</param>
        /// <param name="gameObject">the game object to remove</param>
        /// <returns>true if the removal was successful, false otherwise</returns>
        protected internal static bool RemoveFromList(List<GameObject> list, GameObject gameObject)
        {
            //remove the game object from the list only if that list contains the object,
            //and that objects lists belonging to field contains the list
            if (gameObject._listsBelongingTo.Contains(list) && list.Contains(gameObject))
            {
                list.Remove(gameObject);
                gameObject._listsBelongingTo.Remove(list);

                //return true, as the removal was successful
                return true;
            }

            //return false if there was no removal
            return false;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Establishes a two way relationship between the list the game object is being added to,
        /// and the object being added to the list
        /// </summary>
        /// <param name="list">The list to add the game object to</param>
        /// <param name="gameObject">the object to add</param>
        protected internal static void AddToList(List<GameObject> list, GameObject gameObject)
        {
            ///the two checks ensure an object is only ever added to a list once,
            ///and that the lists belonging to only every contains one instance of the list
            if (!list.Contains(gameObject))
            {
                //add the entity to the list
                list.Add(gameObject);
            }

            if (!gameObject._listsBelongingTo.Contains(list))
            {
                //add the list to the collection of lists the gameobject belongs to
                gameObject._listsBelongingTo.Add(list);
            }
        }
Ejemplo n.º 3
0
 private static int CompareByDrawLayer(GameObject a, GameObject b)
 {
     return a.DrawLayer.CompareTo(b.DrawLayer);
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Sets the Parent of this object to the given argument
        /// </summary>
        /// <param name="aParent">The parent of this object</param>
        public void SetParent(GameObject aParent)
        {
            if (this._parent != null)
            {
                this._parent._children.Remove(this);
            }

            this._parent = aParent;
            if (_parent != null)
            {
                _parent._children.Add(this);
            }

            this._topParent = GetHighestParent();
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Sets this Camera to follow a game object
 /// </summary>
 /// <param name="aTarget">The object to follow</param>
 /// <param name="aOffsetVector">The offset of this camera's position relative to the target's position</param>
 /// <param name="aFollowOffset">distance the camera should be from the target</param>
 /// <param name="rotationOffset">the difference in rotation between the target and camera</param>
 public void Follow(GameObject aTarget, Vector2 aOffsetVector, float aFollowOffset, float rotationOffset)
 {
     Target = aTarget;
     OffsetVector = aOffsetVector;
     FollowOffset = aFollowOffset;
     SourceRotationOffset = rotationOffset;
 }