コード例 #1
0
 public void RotateWhenShooting(float rotateSpeed, float startRotation, float endRotation)
 {
     rotate             = true;
     this.rotateSpeed   = rotateSpeed;
     this.startRotation = GameConstants.DegreesToRadians(startRotation);
     this.endRotation   = GameConstants.DegreesToRadians(endRotation);
 }
コード例 #2
0
        /* old; slow
         * public bool CheckForPlayerDiagonally(bool facingRight, float distance, float angle, float angleOffset)
         * {
         *  float addExtentToDistance = (extents.X > extents.Y) ? extents.X : extents.Y;
         *  distance += addExtentToDistance;
         *
         *  // Convert angles from degrees to radians
         *  angle = GameConstants.DegreesToRadians(angle);
         *  angleOffset = GameConstants.DegreesToRadians(angleOffset);
         *
         *  float angleInterval = GameConstants.DegreesToRadians(10);
         *  int angleCounter = (int)Math.Ceiling((angleOffset * 2) / angleInterval);
         *
         *  // in the middle of the enemy
         *  Vector2 rayStart = new Vector2(Position.X, Position.Y);
         *  Vector2 rayEnd;
         *
         *  // the starting angle
         *  angle = angle - angleOffset;
         *
         *  // check from the starting angle to the final angle, which is angle + angleOffset
         *  for (int i = 0; i <= angleCounter; i++)
         *  {
         *      rayEnd = rayStart + GameConstants.VectorFromAngle(angle, distance, facingRight);
         *      if (rayCastForPlayer(rayStart, rayEnd))
         *      {
         *          playerAngle = angle;
         *          return true;
         *      }
         *
         *      angle += angleInterval;
         *  }
         *
         *  return false;
         * }
         */

        public bool CheckForPlayerDiagonally(bool facingRight, float distance, float angle)
        {
            float addExtentToDistance = (extents.X > extents.Y) ? extents.X : extents.Y;

            distance += addExtentToDistance;

            // Convert angles from degrees to radians
            angle = GameConstants.DegreesToRadians(angle);

            // in the middle of the enemy
            Vector2 rayStart = new Vector2(Position.X, Position.Y);
            Vector2 rayEnd   = rayStart + GameConstants.VectorFromAngle(angle, distance, facingRight);

            if (rayCastForPlayer(rayStart, rayEnd))
            {
                this.PlayerAngle = angle;
                return(true);
            }

            return(false);
        }