コード例 #1
0
        public virtual void OnCollideWith <TCollidable>(ICollidable target, CollisionMoment collisionMoment, ICollisionContainer container)
            where TCollidable : class, ICollidable
        {
            var self = this as TCollidable;

            if (self == null)
            {
                return;
            }

            var collisionTarget = target as ICollidable <TCollidable>;

            collisionTarget?.OnCollideWith(self, collisionMoment, container);
        }
コード例 #2
0
        /// <summary>
        /// Applies the given collision moment to the current collidable's movement vectors.
        /// This method adjusts position, velocity, and acceleration for the current update
        /// cycle according to the collision edges and time alpha value reported by the given
        /// collision information.
        /// </summary>
        /// <param name="collisionMoment">Collision moment.</param>
        protected void ApplyToMovement(CollisionMoment collisionMoment)
        {
            var modifier = Vector2.One;

            if (collisionMoment.ThisEdge.IsTop() || collisionMoment.ThisEdge.IsBottom())
            {
                modifier = new Vector2(modifier.X, collisionMoment.TimeAlpha);
            }
            else if (collisionMoment.ThisEdge.IsLeft() || collisionMoment.ThisEdge.IsRight())
            {
                modifier = new Vector2(collisionMoment.TimeAlpha, modifier.Y);
            }

            this.Acceleration *= modifier;
            this.Velocity     *= modifier;
            this.Position     += Vector2.Negate(this.Velocity * (Vector2.One - modifier));
        }
コード例 #3
0
 public CollisionEventArgs(ICollidable entityOne, ICollidable entityTwo, CollisionMoment moment)
 {
     this.EntityOne       = entityOne;
     this.EntityTwo       = entityTwo;
     this.CollisionMoment = moment;
 }
コード例 #4
0
 public abstract void OnCollideWith(ICollidable target, CollisionMoment collisionMoment, ICollisionContainer container);