Exemplo n.º 1
0
        public override void HandleCollision(GameObject var)
        {
            Vector2 placeHolderThis = movement;
            Vector2 placeHolderVar = var.Movement;

            movement = placeHolderVar;
            var.Movement = placeHolderThis;
        }
        //Returns an 0 vector if there is no collision
        //Returns a unit vector for the tangent line of intersection
        public Vector2 Intersects(GameObject var)
        {
            //Check to see if a collision occurs
            //This is a simple task of checking position vs the sum of the radii

            //There is a collision
            if (this.Radius + var.Radius > (this.Position - var.Position).Length())
            {

                //Find a normal vector for the tangent line
                Vector2 unitTangent = this.Position - var.Position;
                unitTangent.Normalize();

                Matrix rotMat = Matrix.CreateRotationZ(MathHelper.PiOver2);
                unitTangent = Vector2.Transform(unitTangent, rotMat);

                //Calculate retraction
                this.Position -= this.Movement;
                var.Position -= var.Movement;

                return unitTangent;

            }

            //If this line is reached, there was no collision and we return the empty vector
            return Vector2.Zero;
        }
 public virtual void HandleCollision(GameObject var)
 {
 }
Exemplo n.º 4
0
 private void DrawObject(GameObject var)
 {
     spriteBatch.Draw(var.Sheet.Image, var.Position, null, Color.White, var.Angle, new Vector2(var.Radius, var.Radius), 1, SpriteEffects.None, 1);
 }