Ejemplo n.º 1
0
        public Corral(Point size, WorldObject toTrack)
        {
            subject = toTrack;

            bounds = new BoxCollider(size);
            AddComponent(bounds);
            bounds.CollisionStart += TriggerEvents;
            bounds.CollisionEnd += TriggerEvents;
        }
Ejemplo n.º 2
0
        private static bool CircularComponentCheck(WorldObject root, HashSet<WorldObject> log)
        {
            // check if the root is in the log, if it is, that means that we have a loop
            if (log.Contains(root))
                return false;

            // otherwise add the root, and perform a recursive call on all of the components.
            log.Add(root);
            foreach(WorldObject wo in root.GetComponents())
            {
                // if any fail, then stop checking.
                if (!CircularComponentCheck(wo, log))
                    return false;
            }

            // if none failed, then it checks out
            return true;
        }
Ejemplo n.º 3
0
        protected virtual void OnOwnerChanged(WorldObject owner)
        {
            if (OwnerChanged != null)
                OwnerChanged(this, new WorldObjectEventArgs(owner));

            Layer = owner == null ? null : owner.Layer;
        }
Ejemplo n.º 4
0
 public void RemoveComponent(WorldObject component)
 {
     if (_components.Contains(component))
     {
         _components.Remove(component);
         OnComponentRemoved(component);
     }
 }
Ejemplo n.º 5
0
        public void AddComponent(WorldObject component)
        {
            _components.Add(component);
            if (component.Owner != this)
                component.Owner = this;
            OnComponentAdded(component);

            if (!CircularComponentCheck(RootObject))
                throw new InvalidComponentsException("An invalid component configuration was detected. Make sure you do not have duplicate components or a circular arrangement of components.");
        }
Ejemplo n.º 6
0
 public static bool CircularComponentCheck(WorldObject root)
 {
     return CircularComponentCheck(root, new HashSet<WorldObject>());
 }
Ejemplo n.º 7
0
 public WorldObjectEventArgs(WorldObject worldObject)
 {
     WorldObject = worldObject;
 }
Ejemplo n.º 8
0
 public WorldObject(WorldObject owner)
 {
     Initialize(owner, Vector2.Zero);
 }
Ejemplo n.º 9
0
 public void Remove(WorldObject worldObject)
 {
     WorldObjects.Remove(worldObject);
     OnWorldObjectRemoved(worldObject);
 }
Ejemplo n.º 10
0
 public void Add(WorldObject worldObject)
 {
     WorldObjects.Add(worldObject);
     OnWorldObjectAdded(worldObject);
 }
Ejemplo n.º 11
0
        private void UnsubscribeFromManagers(WorldObject worldObject)
        {
            if (worldObject is ICollidable)
                CollisionManager.AddCollidable(worldObject as ICollidable);
            else if (worldObject is IDrawManageable)
                DrawManager.Remove(worldObject as IDrawManageable);

            // unsubscribe the components recursively
            foreach (WorldObject wo in worldObject.GetComponents())
            {
                UnsubscribeFromManagers(wo);
            }
        }
Ejemplo n.º 12
0
        private void SubscribeToManagers(WorldObject worldObject)
        {
            if (worldObject is ICollidable)
                CollisionManager.AddCollidable(worldObject as ICollidable);
            else if (worldObject is IDrawManageable)
                DrawManager.AddDrawable(worldObject as IDrawManageable);

            // subscribe components recursively
            foreach (WorldObject wo in worldObject.GetComponents())
            {
                SubscribeToManagers(wo);
            }
        }
Ejemplo n.º 13
0
        private void OnWorldObjectRemoved(WorldObject worldObject)
        {
            if (WorldObjectRemoved != null) WorldObjectRemoved(this, new WorldObjectEventArgs(worldObject));

            // remove the worldObject from the Managers
            UnsubscribeFromManagers(worldObject);
        }
Ejemplo n.º 14
0
        private void OnWorldObjectAdded(WorldObject worldObject)
        {
            if (WorldObjectAdded != null) WorldObjectAdded(this, new WorldObjectEventArgs(worldObject));

            // set the layer
            worldObject.Layer = this;

            // hook up events
            worldObject.UpdateOrderChanged += worldObject_UpdateOrderChanged;

            // refresh the update order
            SortUpdateOrder();

            // add the worldObject to the Managers
            SubscribeToManagers(worldObject);
        }
Ejemplo n.º 15
0
        private void Initialize(WorldObject owner = null, Vector2? position = null, params WorldObject[] components)
        {
            Owner = owner;
            _components = new List<WorldObject>(components);

            BasePosition = position ?? Vector2.Zero;
            BaseScale = new Vector2(1, 1);
            BaseRotation = 0;

            Enabled = true;
            UpdateOrder = 0;
        }
Ejemplo n.º 16
0
 private void OnComponentRemoved(WorldObject component)
 {
     if (ComponentRemoved != null)
         ComponentRemoved(this, new WorldObjectEventArgs(component));
 }
Ejemplo n.º 17
0
 protected override void OnOwnerChanged(WorldObject owner)
 {
     base.OnOwnerChanged(owner);
     _baseObject = RootObject;
 }
Ejemplo n.º 18
0
 public WorldObject(WorldObject owner = null, Vector2? position = null, params WorldObject[] components)
 {
     Initialize(owner, position ?? null, components);
 }
Ejemplo n.º 19
0
 public Body()
 {
     _baseObject = RootObject;
 }