コード例 #1
0
ファイル: RightTriangle.cs プロジェクト: smldev/smlimitless
        /// <summary>
        ///   Draws this triangle to the screen.
        /// </summary>
        /// <param name="debug">Draws some useful debug information.</param>
        public void Draw(bool debug)
        {
            GameServices.SpriteBatch.DrawLine(1f, Color.White, Point90, Point1);
            GameServices.SpriteBatch.DrawLine(1f, Color.White, Point90, Point2);
            GameServices.SpriteBatch.DrawLine(1f, Color.White, Point1, Point2);

            if (debug)
            {
                // Draw the line coincident to the slope. For the inverted
                // Y-axis, the slope-intercept formula, solved for x, is x = (-y
                // + b) / m
                Vector2 screenSize = GameServices.ScreenSize;
                Vector2 lineStart = new Vector2((-screenSize.Y + YIntersect) / Slope, screenSize.Y);
                Vector2 lineEnd = new Vector2(YIntersect / Slope, 0f);
                GameServices.SpriteBatch.DrawLine(1f, Color.ForestGreen, lineStart, lineEnd);

                // DrawLine is a little weird with drawing the right-triangle -
                // the bounds look visually larger than the triangle, even though
                // they are the right sizes. So we'll correct the bounds so they
                // look right.
                Rectangle drawBounds = new Rectangle((int)Bounds.X + 1, (int)Bounds.Y - 1, (int)Bounds.Width, (int)Bounds.Height);
                drawBounds.DrawOutline(Color.Red);

                // Draw some useful debug information.
                GameServices.DebugFont.DrawString(ToString(), new Vector2(Bounds.X, Bounds.Y));
            }
        }