示例#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));
        }
示例#2
0
 public void Remove(Collidable obj)
 {
     QuadTreeNode node = obj.GetMapArea();
     if (node != null)
     {
         obj.GetMapArea().Contents.Remove(obj);
     }
 }
示例#3
0
文件: Map.cs 项目: EugeneWang/ShootR
 public void Insert(Collidable obj)
 {
     lock (_insertLock)
     {
         _allObjects.Add(obj);
         _space.Insert(obj);
     }
 }
示例#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);
     }
 }
示例#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
        }
示例#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));
                }
            }
        }
示例#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);
 }
示例#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);
         }
     }
 }
示例#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);
        }
示例#10
0
 public bool ExistedLastPayload(string connectionID, Collidable obj)
 {
     return _lastCache.ContainsKey(connectionID) && _lastCache[connectionID].ContainsKey(obj.ServerID());
 }
示例#11
0
 public KillEventArgs(Collidable killed)
 {
     Killed = killed;
 }
示例#12
0
 public bool OnMap(Collidable obj)
 {
     return Area.Contains(obj.GetBounds());
 }
示例#13
0
 public void Cache(string connectionID, Collidable obj)
 {
     _currentCache[connectionID].TryAdd(obj.ServerID(), true);
 }
示例#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();
 }
示例#15
0
 public void Insert(Collidable obj)
 {
     _root.Insert(obj);
 }
示例#16
0
文件: Map.cs 项目: EugeneWang/ShootR
        public void HandleOutOfBounds(Collidable obj)
        {

        }
示例#17
0
 public void Monitor(Collidable obj)
 {
     _space.Insert(obj);
     _objects.Add(obj);
 }
示例#18
0
文件: Map.cs 项目: EugeneWang/ShootR
 public static bool OnMap(Collidable obj)
 {
     return _boundary.OnMap(obj);
 }
示例#19
0
文件: Ship.cs 项目: AbhiLegend/ShootR
 public void Killed(Collidable who)
 {
     if (OnKill != null)
     {
         OnKill(this, new KillEventArgs(who));
     }
 }
示例#20
0
文件: Ship.cs 项目: AbhiLegend/ShootR
 public override void HandleCollisionWith(Collidable c, Map space)
 {
 }
示例#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;
                }
            }
        }
示例#22
0
 public DeathEventArgs(Collidable killedBy)
 {
     KilledBy = killedBy;
 }
示例#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());
 }
示例#24
0
文件: Map.cs 项目: EugeneWang/ShootR
 public void Remove(Collidable obj)
 {
     _allObjects.Remove(obj);
     _space.Remove(obj);
 }
示例#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();
 }
示例#26
0
文件: Ship.cs 项目: EugeneWang/ShootR
 public override bool IsCollidingWith(Collidable c)
 {
     return _snapShotManager.GetBoundsSnapShot().IntersectsWith(c.GetBounds());
 }
示例#27
0
 public void UnMonitor(Collidable obj)
 {
     _space.Remove(obj);
     _objects.Remove(obj);
 }
示例#28
0
文件: Map.cs 项目: EugeneWang/ShootR
 public List<Collidable> GetPartialCollisionCheckList(Collidable obj)
 {
     return _space.GetPartialCollisionCheckList(obj);
 }
示例#29
0
文件: Map.cs 项目: EugeneWang/ShootR
 public bool Contains(Collidable obj)
 {
     return _allObjects.Contains(obj);
 }
 public DeathEventArgs(Collidable killedBy)
 {
     KilledBy = killedBy;
 }