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)); }
public void Remove(Collidable obj) { QuadTreeNode node = obj.GetMapArea(); if (node != null) { obj.GetMapArea().Contents.Remove(obj); } }
public void Insert(Collidable obj) { lock (_insertLock) { _allObjects.Add(obj); _space.Insert(obj); } }
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); } }
/// <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 }
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)); } } }
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); }
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); } } }
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); }
public bool ExistedLastPayload(string connectionID, Collidable obj) { return _lastCache.ContainsKey(connectionID) && _lastCache[connectionID].ContainsKey(obj.ServerID()); }
public KillEventArgs(Collidable killed) { Killed = killed; }
public bool OnMap(Collidable obj) { return Area.Contains(obj.GetBounds()); }
public void Cache(string connectionID, Collidable obj) { _currentCache[connectionID].TryAdd(obj.ServerID(), true); }
/// <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(); }
public void Insert(Collidable obj) { _root.Insert(obj); }
public void HandleOutOfBounds(Collidable obj) { }
public void Monitor(Collidable obj) { _space.Insert(obj); _objects.Add(obj); }
public static bool OnMap(Collidable obj) { return _boundary.OnMap(obj); }
public void Killed(Collidable who) { if (OnKill != null) { OnKill(this, new KillEventArgs(who)); } }
public override void HandleCollisionWith(Collidable c, Map space) { }
/// <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; } } }
public DeathEventArgs(Collidable killedBy) { KilledBy = killedBy; }
/// <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()); }
public void Remove(Collidable obj) { _allObjects.Remove(obj); _space.Remove(obj); }
/// <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(); }
public override bool IsCollidingWith(Collidable c) { return _snapShotManager.GetBoundsSnapShot().IntersectsWith(c.GetBounds()); }
public void UnMonitor(Collidable obj) { _space.Remove(obj); _objects.Remove(obj); }
public List<Collidable> GetPartialCollisionCheckList(Collidable obj) { return _space.GetPartialCollisionCheckList(obj); }
public bool Contains(Collidable obj) { return _allObjects.Contains(obj); }