Пример #1
0
 public void HandleCollision(GameObject obj, BoundingPolygon p, Vector collisionNormal, CollisionResult collisionResult)
 {
     if (collisionNormal.X > 0.8)
     {
         direction = 1;
     }
     else if (collisionNormal.X < -0.8)
     {
         direction = -1;
     }
     else if (obj.Velocity.X > 0)
     {
         direction = 1;
     }
     else if (obj.Velocity.X < 0)
     {
         direction = -1;
     }
 }
Пример #2
0
        //Handle collisions against edges
        public override void Collide(BoundingPolygon p, Vector collisionNormal, CollisionResult collisionResult)
        {
            //if (collisionResult.isIntersecting) return;

            base.Collide(p, collisionNormal, collisionResult);

            // If intersecting, push back
            if (collisionResult.isIntersecting)
            {
                Position += collisionResult.minimumTranslationVector;
            }
            else
            {
                remainingFrameTime -= collisionResult.collisionTime;

                if (collisionResult.hasIntersected)
                    Position -= (1-collisionResult.collisionTime + 1e-6) * Velocity * frameTime;
                else
                    Position -= collisionResult.minimumTranslationVector;

                Velocity = Velocity - ((1.0+objectPhysics.Elasticity)*Velocity.DotProduct(collisionNormal))*collisionNormal;
                Position += remainingFrameTime * Velocity * frameTime;

               				/*
                 * Run the event handlers
                 */
                if (Math.Abs(collisionNormal.X) > 0.8)
                    OnCollidedWithWall();

                if (collisionNormal.Y > 0.5)
                {
                    if (!OnGround)
                    {
                        OnLanded();
                        OnGround = true;
                    }
                    inAirTimer.Restart();
                }
            }
            //	}
        }
Пример #3
0
 public override void Collide(BoundingPolygon p, Vector collisionNormal, CollisionResult collisionResult)
 {
     if (currentState == dieState) return;
     base.Collide (p, collisionNormal, collisionResult);
     if (collisionResult.hitNormal.X > 0.8 && sliding)
     {
         sliding = false;
         objectPhysics.Friction = oldFriction;
     }
 }
Пример #4
0
 public void HandleCollision(GameObject obj, BoundingPolygon p, Vector collisionNormal, CollisionResult collisionResult)
 {
 }
Пример #5
0
 public CollisionEvent(ICollidable obj, BoundingPolygon p, Vector normal, CollisionResult collisionResult)
 {
     collisionType = Type.OBJECT_POLYGON;
     object1 = obj;
     polygon = p;
     collisionNormal = normal;
     this.collisionResult = collisionResult;
 }
Пример #6
0
        /// <summary>
        /// Project a convex polygon on a vector.
        /// </summary>
        private static Projection ProjectPolygon(BoundingPolygon p, Vector axis)
        {
            double min = double.PositiveInfinity, max = double.NegativeInfinity;

            foreach (Vector v in p.Vertices)
            {
                double dot = v.DotProduct(axis);
                if (dot < min) min = dot;
                if (dot > max) max = dot;
            }

            return new Projection(min, max, axis);
        }
Пример #7
0
 /// <summary>
 /// From ICloneable
 /// </summary>
 public object Clone()
 {
     BoundingPolygon p = new BoundingPolygon(vertices);
     p.MoveTo(center.X, center.Y);
     return p; //return new BoundingPolygon(vertices);
 }
Пример #8
0
 /// <summary>
 /// Create a new tile
 /// </summary>
 public Tile(int id, Texture texture, BoundingPolygon boundingPolygon)
 {
     this.Id = id;
     this.BoundingPolygon = boundingPolygon;
     this.Texture = texture;
 }
Пример #9
0
 public virtual void Collide(BoundingPolygon p, Vector collisionNormal, CollisionResult collisionResult)
 {
     if (controller != null)
         controller.HandleCollision(this, p, collisionNormal, collisionResult);
 }