Beispiel #1
0
        public double DistanceFrom(Collidable from)
        {
            Vector2 myCenter = this.Center(),
                    theirCenter = from.Center();

            return Math.Sqrt(Math.Pow(myCenter.X - theirCenter.X, 2) + Math.Pow(myCenter.Y - theirCenter.Y, 2));
        }
Beispiel #2
0
 public void Remove(Collidable obj)
 {
     QuadTreeNode node = obj.GetMapArea();
     if (node != null)
     {
         obj.GetMapArea().Contents.Remove(obj);
     }
 }
Beispiel #3
0
 public void Insert(Collidable obj)
 {
     lock (_insertLock)
     {
         _allObjects.Add(obj);
         _space.Insert(obj);
     }
 }
Beispiel #4
0
 public override void HandleCollisionWith(Collidable c, Map space)
 {
     if (c is Ship)
     {
         c.LifeController.Heal(_healAmount);
         Dispose(); // Destroy bullet when collision  
         base.HandleCollisionWith(c, space);
     }
 }
Beispiel #5
0
        /// <summary>
        /// When a bullet hits another object it must be destroyed.  So we dispose of it.
        /// </summary>
        /// <param name="c">The object that I colided with.</param>
        public override void HandleCollisionWith(Collidable c, Map space)
        {
            base.HandleCollisionWith(c, space);
            DamageDealt = DamageController.Damage;
            c.LifeController.Hurt(DamageDealt, this);

            if(c is Ship)
            {
                (c as Ship).StatRecorder.BulletCollision(this);
            }

            Dispose(); // Destroy bullet when collision
        }
Beispiel #6
0
        public void Hurt(double life, Collidable hurtBy = null)
        {
            Health -= life;

            // Dead
            if (Health <= 0)
            {
                Health = 0;
                Alive = false;

                if (OnDeath != null)
                {
                    OnDeath(Host, new DeathEventArgs(hurtBy));
                }
            }
        }
Beispiel #7
0
 private void SetCollidableContractMembers(object[] result, Collidable obj)
 {
     result[CollidableCompressionContract.Collided] = Convert.ToInt32(obj.Collided);
     result[CollidableCompressionContract.CollidedAtX] = Math.Round(obj.CollidedAt.X, 2);
     result[CollidableCompressionContract.CollidedAtY] = Math.Round(obj.CollidedAt.Y, 2);
     result[CollidableCompressionContract.ForcesX] = Math.Round(obj.MovementController.Forces.X, 2);
     result[CollidableCompressionContract.ForcesY] = Math.Round(obj.MovementController.Forces.Y, 2);
     result[CollidableCompressionContract.Mass] = obj.MovementController.Mass;
     result[CollidableCompressionContract.PositionX] = Math.Round(obj.MovementController.Position.X, 2);
     result[CollidableCompressionContract.PositionY] = Math.Round(obj.MovementController.Position.Y, 2);
     result[CollidableCompressionContract.Rotation] = Math.Round(obj.MovementController.Rotation, 2);
     result[CollidableCompressionContract.VelocityX] = Math.Round(obj.MovementController.Velocity.X, 2);
     result[CollidableCompressionContract.VelocityY] = Math.Round(obj.MovementController.Velocity.Y, 2);
     result[CollidableCompressionContract.ID] = obj.ID;
     result[CollidableCompressionContract.Disposed] = Convert.ToInt32(obj.Disposed);
     result[CollidableCompressionContract.Alive] = Convert.ToInt32(obj.LifeController.Alive);
     result[CollidableCompressionContract.Health] = Math.Round(obj.LifeController.Health, 2);
 }
Beispiel #8
0
 public void ReverseInsert(Collidable obj)
 {
     // Check if object has left the bounds of this node then go up another level
     if (!this.Bounds.Contains(obj.GetBounds()))
     {
         // NOTE: If you get an error here chances are an object is out of bounds. aka off the quad tree map.
         // In order to avoid an additional check we assume that the obj is smaller than
         // the root node.
         if (this.Parent != null)
         {
             this.Parent.ReverseInsert(obj);
         }
         else
         {
             obj.SetMapArea(this);
             lock (_locker)
             {
                 this.Contents.Add(obj);
             }
         }
     }
     else
     {
         obj.SetMapArea(this);
         lock (_locker)
         {
             this.Contents.Add(obj);
         }
     }
 }
Beispiel #9
0
        public void Insert(Collidable obj)
        {
            foreach (QuadTreeNode node in Children)
            {
                if (node.Bounds.Contains(obj.GetBounds()))
                {
                    node.Insert(obj);
                    return;
                }
            }

            // When we get here we're then "this" is currently the largest node to fit our object OR
            // We're at a leaf node caused by the smallest possible partition width/height.
            lock (_locker)
            {
                Contents.Add(obj);
            }
            obj.SetMapArea(this);
        }
Beispiel #10
0
 public bool ExistedLastPayload(string connectionID, Collidable obj)
 {
     return _lastCache.ContainsKey(connectionID) && _lastCache[connectionID].ContainsKey(obj.ServerID());
 }
Beispiel #11
0
 public KillEventArgs(Collidable killed)
 {
     Killed = killed;
 }
Beispiel #12
0
 public bool OnMap(Collidable obj)
 {
     return Area.Contains(obj.GetBounds());
 }
Beispiel #13
0
 public void Cache(string connectionID, Collidable obj)
 {
     _currentCache[connectionID].TryAdd(obj.ServerID(), true);
 }
Beispiel #14
0
 /// <summary>
 /// Will return all objects "underneath" (in the tree) the obj.
 /// Called partial because if an object "above" the obj is colliding
 /// with it this function will not return that object.  Therefore when
 /// calling this function be sure to traverse the whole collision list.
 /// </summary>
 /// <param name="obj">Object to check collisions</param>
 public List<Collidable> GetPartialCollisionCheckList(Collidable obj)
 {
     return obj.GetMapArea().GetSubTreeContents();
 }
Beispiel #15
0
 public void Insert(Collidable obj)
 {
     _root.Insert(obj);
 }
Beispiel #16
0
        public void HandleOutOfBounds(Collidable obj)
        {

        }
Beispiel #17
0
 public void Monitor(Collidable obj)
 {
     _space.Insert(obj);
     _objects.Add(obj);
 }
Beispiel #18
0
 public static bool OnMap(Collidable obj)
 {
     return _boundary.OnMap(obj);
 }
Beispiel #19
0
 public void Killed(Collidable who)
 {
     if (OnKill != null)
     {
         OnKill(this, new KillEventArgs(who));
     }
 }
Beispiel #20
0
 public override void HandleCollisionWith(Collidable c, Map space)
 {
 }
Beispiel #21
0
        /// <summary>
        /// Updates the object and returns whether it still belongs to this node
        /// </summary>
        /// <param name="obj">Object to Update in the quad tree</param>
        /// <returns>Whether the object moved</returns>
        private bool UpdateObject(Collidable obj)
        {
            obj.ClearMapArea();
            lock (_locker)
            {
                this.Contents.Remove(obj);
            }

            // Check if object has left the bounds of this node and is not root
            if (!this.Bounds.Contains(obj.GetBounds()) && this.Parent != null)
            {
                // We now belong to a parent
                this.Parent.ReverseInsert(obj);
                return true;
            }
            else // We're within the same node, but could be in children, must insert
            {
                this.Insert(obj);
                // If we didn't move quad tree nodes
                if (obj.GetMapArea() == this)
                {
                    return false;
                }
                else
                {
                    return true;
                }
            }
        }
Beispiel #22
0
 public DeathEventArgs(Collidable killedBy)
 {
     KilledBy = killedBy;
 }
Beispiel #23
0
 /// <summary>
 /// Calculates whether me and the collidable object <paramref name="c"/> are colliding.
 /// </summary>
 /// <param name="c">The object to check the collision against.</param>
 /// <returns>Whether or not I am colliding with <paramref name="c"/>.</returns>
 public virtual bool IsCollidingWith(Collidable c)
 {
     return _bounds.IntersectsWith(c.GetBounds());
 }
Beispiel #24
0
 public void Remove(Collidable obj)
 {
     _allObjects.Remove(obj);
     _space.Remove(obj);
 }
Beispiel #25
0
 /// <summary>
 /// Called when there is a collision with another object "<paramref name="c"/>."
 /// </summary>
 /// <param name="c">The object that I colided with</param>
 public virtual void HandleCollisionWith(Collidable c, Map space)
 {
     HandleCollision();
 }
Beispiel #26
0
 public override bool IsCollidingWith(Collidable c)
 {
     return _snapShotManager.GetBoundsSnapShot().IntersectsWith(c.GetBounds());
 }
Beispiel #27
0
 public void UnMonitor(Collidable obj)
 {
     _space.Remove(obj);
     _objects.Remove(obj);
 }
Beispiel #28
0
 public List<Collidable> GetPartialCollisionCheckList(Collidable obj)
 {
     return _space.GetPartialCollisionCheckList(obj);
 }
Beispiel #29
0
 public bool Contains(Collidable obj)
 {
     return _allObjects.Contains(obj);
 }
 public DeathEventArgs(Collidable killedBy)
 {
     KilledBy = killedBy;
 }