Example #1
0
 public void HandleCollision(PlayerStriker playerStriker, GameTime gameTime)
 {
     CheckBounce();
     if (CheckIntersect(playerStriker))
     {
         velocity += (position - playerStriker.position) * (float)gameTime.ElapsedGameTime.TotalSeconds;
     }
     velocity *= friction;
     position += velocity;
 }
Example #2
0
        public bool CheckIntersect(PlayerStriker playerStriker)
        {
            var playerX = playerStriker.position.X;
            var playerY = playerStriker.position.Y;

            var deltax   = position.X - playerX;
            var deltay   = position.Y - playerY;
            var distance = Math.Sqrt(deltax * deltax + deltay * deltay);

            if (distance < radius + playerStriker.radius)
            {
                velocity *= collisionSlowdown;  //slow it down
                return(true);
            }
            return(false);
        }