Пример #1
0
 private void OnCollisionStay2D(Collision2D other)
 {
     if (IsPenguin(other.collider))
     {
         OnCollisionStay.Invoke(currentPenguin);
     }
 }
Пример #2
0
 public override void Update(double totalSeconds)
 {
     base.Update(totalSeconds);
     #region Collision update
     if (TranslationVector != Vector2.Zero)
     {
         _boundingCircle.Center = new Point2(WorldPosition.X, WorldPosition.Y);
     }
     foreach (AEntity entity in GameDatas.AllEntities.Values)
     {
         if (entity is CollidableEntity && this != entity)
         {
             if (_boundingCircle.Intersects(((CollidableEntity)entity)._boundingCircle))
             {
                 if (!_collideWith.ContainsKey(entity.Id))
                 {
                     ((CollidableEntity)entity).OnCollisionEnter?.Invoke(null, this);
                     OnCollisionEnter?.Invoke(null, (CollidableEntity)entity);
                 }
                 else
                 {
                     ((CollidableEntity)entity).OnCollisionStay?.Invoke(null, this);
                     OnCollisionStay?.Invoke(null, (CollidableEntity)entity);
                 }
             }
             else
             {
                 ((CollidableEntity)entity).OnCollisionExit?.Invoke(null, this);
                 OnCollisionExit?.Invoke(null, (CollidableEntity)entity);
             }
         }
     }
     #endregion Collision update
 }
Пример #3
0
        public override void OnUpdate(float deltaTime)
        {
            base.OnUpdate(deltaTime);
            if (Parent == null || Parent.Parent == null)
            {
                return;
            }

            if (ContinouslyCheckCollisions)
            {
                //TODO add a way to change Program.world to world
                foreach (GameObject child in Program.world.GetCurrentChildren())
                {
                    Collider coll = child.GetFirst <Collider>();
                    if (coll == null || coll.Parent == null || coll == this || coll.Parent.transform == null)
                    {
                        continue;
                    }

                    if (CollidesWith(coll))
                    {
                        OnCollisionStay?.Invoke(this, coll);
                        if (Parent == null)
                        {
                            return;
                        }
                    }
                }
            }
        }
Пример #4
0
        public void HandlePhysicsEvents()
        {
            for (int i = 0; i < currentlyCollidingWith.Count; i++)
            {
                if (lastCollidedWith.Contains(currentlyCollidingWith[i]))
                {
                    //Collided with it last frame.
                    if (coll.isTrigger)
                    {
                        OnTriggerStay?.Invoke(currentlyCollidingWith[i]);
                    }
                    else
                    {
                        OnCollisionStay?.Invoke(new TFCollision(currentlyCollidingWith[i]));
                    }
                }
                else
                {
                    //Did not collide with last frame.
                    if (coll.isTrigger)
                    {
                        OnTriggerEnter?.Invoke(currentlyCollidingWith[i]);
                    }
                    else
                    {
                        OnCollisionEnter?.Invoke(new TFCollision(currentlyCollidingWith[i]));
                    }
                }
            }

            for (int w = 0; w < lastCollidedWith.Count; w++)
            {
                //If we've exited collision with a collider.
                if (!currentlyCollidingWith.Contains(lastCollidedWith[w]))
                {
                    if (coll.isTrigger)
                    {
                        OnTriggerExit?.Invoke(lastCollidedWith[w]);
                    }
                    else
                    {
                        OnCollisionExit?.Invoke(new TFCollision(lastCollidedWith[w]));
                    }
                }
            }
            lastCollidedWith = new List <TFCollider>(currentlyCollidingWith);
            currentlyCollidingWith.Clear();
        }
Пример #5
0
 public void CheckIfStillIntersecting()
 {
     foreach (Collider item in IntersectingColliders)
     {
         if (shape.Intersects(item.shape))
         {
             OnCollisionStay?.Invoke(this, new Collision()
             {
                 Caller = this, otherCollider = item
             });
         }
         else
         {
             OnCollisionExit?.Invoke(this, new Collision()
             {
                 Caller = this, otherCollider = item
             });
         }
     }
 }
Пример #6
0
 private void OnMovingObjectClientCollision(ClientBase sender, MovingObjectClientCollision packet)
 {
     for (int i = 0; i < packet.uidsLength; i++)
     {
         Collider collider = ((Collider)Program.networkManager.Get(packet.uids[i]));
         if (collider == null || collider.Parent == null || collider.Parent.Parent == null)
         {
             continue;
         }
         //TODO CHECK IF ITS BETTER TO BATCH CALL INSTEAD OF INVOKE MANY TIMES.
         Invoke(InvokeCollision);
         void InvokeCollision()
         {
             if (collider == null || collider.Parent == null || collider.Parent.Parent == null || Parent == null || Parent.Parent == null)
             {
                 return;
             }
             collider.OnCollisionStay?.Invoke(collider, this);
             OnCollisionStay?.Invoke(this, collider);
         }
     }
 }
Пример #7
0
 public void ExecuteEventsWithCurrentCollisions(bool tellOtherColliderAboutCollision = false)
 {
     foreach (GameObject child in Game1.instance.world.GetCurrentChildren())
     {
         Collider coll = child.GetFirst <Collider>();
         if (coll == null || coll.Parent == null || coll == this || coll.Parent.transform == null)
         {
             continue;
         }
         if (CollidesWith(coll))
         {
             OnCollisionStay?.Invoke(this, coll);
             if (tellOtherColliderAboutCollision)
             {
                 coll.OnCollisionStay?.Invoke(coll, this);
             }
             if (Parent == null)
             {
                 return;
             }
         }
     }
 }
 void DispatchOnCollisionStay(Collision collision)
 {
     OnCollisionStay?.Invoke(collision, GetCollidingBone(collision));
 }
Пример #9
0
 private void Internal_onCollisionStay(ref CollisionData p0)
 {
     OnCollisionStay?.Invoke(p0);
 }
 void OnCollisionStay2D(Collision2D collision)
 {
     OnCollisionStay?.Invoke(collision);
 }
Пример #11
0
 private void OnCollisionStay2D(Collision2D other)
 {
     OnCollisionStay?.Invoke(other, gameObject);
 }
Пример #12
0
 void DispatchOnCollisionStay(Collision collision, CollisionEventDispatcher dispatcher)
 {
     OnCollisionStay?.Invoke(collision, bones[dispatcher]);
 }
 void OnCollisionStay2D(Collision2D other)
 {
     OnCollisionStay?.Invoke(other);
 }
Пример #14
0
 public static void CollisionStay(BC_CollisionData data)
 {
     //DebugManager.LogToFile("[OnCollisionStay] " + data.collider.name + " is colliding with " + data.myCollider.name + " at point " + data.point.ToString() + " with normal of " + data.normal.ToString());
     OnCollisionStay?.Invoke(data);
 }