Example #1
0
 /// <summary>
 /// Draw a box on the screen.
 /// </summary>
 /// <param name="rect">The RotRect of the box.</param>
 /// <param name="col">The color.</param>
 public void DrawBox(RotRect rect, Color col)
 {
     // we need to draw this using wrapping, otherwise the rotation origin messes up.
     // this is because rect.Width / 2 could be 100 / 2 = 50, but Pixel is always 1x1.
     // this causes XNA to take origin 50x50 using texture 1x1 by f*****g up the rotation.
     // if we turn on wrapping, the source rectangle is the drawrect width/height, which solves this problem.
     Draw(Pixel, rect, col, false, false, true);
 }
Example #2
0
        /// <summary>
        /// Draw an outlined box on the screen.
        /// </summary>
        /// <param name="rect">The RotRect of the box.</param>
        /// <param name="bordersize">The border size.</param>
        /// <param name="col">The color.</param>
        public void DrawOutlinedBox(RotRect rect, float bordersize, Color col)
        {
            if (bordersize == 0)
            {
                return;
            }

            bordersize *= Camera.Scale;

            Vector2[] avec = rect.GetRotatedPosArray();             // [topLeft, topRight, botRight, botLeft]
            DrawLine(avec[0], avec[1], bordersize, col);            // top left to top right
            DrawLine(avec[1], avec[2], bordersize, col);            // top right to bottom right
            DrawLine(avec[0], avec[3], bordersize, col);            // top left to bottom left
            DrawLine(avec[2], avec[3], bordersize, col);            // bottom left to bottom right
        }
Example #3
0
        /// <summary>
        /// Test if the RotRect intersects with another RotRect.
        /// </summary>
        /// <param name="other">The other RotRect to test.</param>
        /// <returns>True if they intersect, false if they don't.</returns>
        public bool Intersects(RotRect other)
        {
            Vector2[] points      = GetRotatedPosArray();
            Vector2[] otherPoints = other.GetRotatedPosArray();

            if (PointInPolygon(points[0], otherPoints) ||
                PointInPolygon(points[1], otherPoints) ||
                PointInPolygon(points[2], otherPoints) ||
                PointInPolygon(points[3], otherPoints) ||

                PointInPolygon(otherPoints[0], points) ||
                PointInPolygon(otherPoints[1], points) ||
                PointInPolygon(otherPoints[2], points) ||
                PointInPolygon(otherPoints[3], points)
                )
            {
                return(true);
            }

            if (SpecialMath.LineSegmentsIntersect(points[0], points[1], otherPoints[0], otherPoints[1]) ||
                SpecialMath.LineSegmentsIntersect(points[1], points[2], otherPoints[0], otherPoints[1]) ||
                SpecialMath.LineSegmentsIntersect(points[2], points[3], otherPoints[0], otherPoints[1]) ||
                SpecialMath.LineSegmentsIntersect(points[3], points[0], otherPoints[0], otherPoints[1]) ||
                SpecialMath.LineSegmentsIntersect(points[0], points[1], otherPoints[1], otherPoints[2]) ||
                SpecialMath.LineSegmentsIntersect(points[1], points[2], otherPoints[1], otherPoints[2]) ||
                SpecialMath.LineSegmentsIntersect(points[2], points[3], otherPoints[1], otherPoints[2]) ||
                SpecialMath.LineSegmentsIntersect(points[3], points[0], otherPoints[1], otherPoints[2]) ||
                SpecialMath.LineSegmentsIntersect(points[0], points[1], otherPoints[2], otherPoints[3]) ||
                SpecialMath.LineSegmentsIntersect(points[1], points[2], otherPoints[2], otherPoints[3]) ||
                SpecialMath.LineSegmentsIntersect(points[2], points[3], otherPoints[2], otherPoints[3]) ||
                SpecialMath.LineSegmentsIntersect(points[3], points[0], otherPoints[2], otherPoints[3]) ||
                SpecialMath.LineSegmentsIntersect(points[0], points[1], otherPoints[3], otherPoints[0]) ||
                SpecialMath.LineSegmentsIntersect(points[1], points[2], otherPoints[3], otherPoints[0]) ||
                SpecialMath.LineSegmentsIntersect(points[2], points[3], otherPoints[3], otherPoints[0]) ||
                SpecialMath.LineSegmentsIntersect(points[3], points[0], otherPoints[3], otherPoints[0])
                )
            {
                return(true);
            }

            return(false);
        }
Example #4
0
        public Vector2 Render(GameTime gameTime, Vector2 vPos, Vector2 vSize, AnimationState state, float fRotation, float fOverX, float fOverY, Color color, float fDepth)
        {
            Animation pAnim = this;

            if (ani_pAliasOwner != null)
            {
                pAnim = ani_pAliasOwner;
            }

            CustomSpriteBatch rend = pAnim.ani_pSheet.ans_pSpriteBatch;
            Texture2D         tex  = pAnim.ani_pSheet.ans_pTexture;

            if (state.iCurrentFrame >= pAnim.ani_saFrames.Count)
            {
                state.Reset();
            }

            AnimationFrame frame = pAnim.ani_saFrames[state.iCurrentFrame];

            RotRect rectDest = new RotRect();

            rectDest.width  = vSize.X;
            rectDest.height = vSize.Y;

            float fOffsetX = pAnim.ani_rectOffset.X;
            float fOffsetY = pAnim.ani_rectOffset.Y;

            float fWidth = pAnim.ani_rectOffset.Width;

            if (fWidth == 0)
            {
                fWidth = vSize.X;
            }
            if (ani_bFlipH)
            {
                fOffsetX -= ((fOffsetX - rectDest.width / 2) * 2) + fWidth;
            }

            float fHeight = pAnim.ani_rectOffset.Height;

            if (fHeight == 0)
            {
                fHeight = vSize.Y;
            }
            if (ani_bFlipV)
            {
                fOffsetY -= ((fOffsetY - rectDest.height / 2) * 2) + fHeight;
            }

            rectDest.x = vPos.X - fOffsetX;
            rectDest.y = vPos.Y - fOffsetY;

            Rectangle rectSrc = new Rectangle();

            rectSrc.X      = (int)frame.anf_vOffset.X;
            rectSrc.Y      = (int)frame.anf_vOffset.Y;
            rectSrc.Width  = (int)pAnim.ani_vSize.X;
            rectSrc.Height = (int)pAnim.ani_vSize.Y;

            if (fOverX != 0)
            {
                rectDest.width = fOverX;
            }
            if (fOverY != 0)
            {
                rectDest.height = fOverY;
            }

            rend.CurrentDepth = fDepth;
            rend.Draw(tex, rectSrc, rectDest, color, ani_bFlipH, ani_bFlipV, false);

            if (!frame.anf_bPause)
            {
                state.fCurrentFrameCounter += gameTime.ElapsedGameTime.TotalMilliseconds;

                if (state.fCurrentFrameCounter++ >= frame.anf_fTime)
                {
                    AdvanceFrame(state);
                }
            }

            // hmm..
            if (fOverX != 0)
            {
                fWidth = fOverX;
            }
            if (fOverY != 0)
            {
                fHeight = fOverY;
            }

            return(new Vector2((int)fWidth, (int)fHeight));
        }
Example #5
0
        /// <summary>
        /// Draw a texture with a shading color that can be flipped horizontally or vertically, as well as wrapped.
        /// </summary>
        /// <param name="texture">The texture.</param>
        /// <param name="sourceRectangle">The source rectangle.</param>
        /// <param name="destinationRectangle">The RotRect to draw to on the screen in world coordinates.</param>
        /// <param name="color">Shading color to use.</param>
        /// <param name="flipH">Whether to flip the texture horizontally.</param>
        /// <param name="flipV">Whether to flip the texture vertically.</param>
        /// <param name="wrapping">Whether to use texture wrapping.</param>
        public void Draw(Texture2D texture, Rectangle?sourceRectangle, RotRect destinationRectangle, Color color, bool flipH, bool flipV, bool wrapping)
        {
            if (texture == null)
            {
                return;
            }

            RotRect drawRect = destinationRectangle;

            if (Camera.AllowScaling && Camera.AllowTransforming)
            {
                drawRect.width  *= Camera.Scale;
                drawRect.height *= Camera.Scale;
            }

            SpriteEffects se = SpriteEffects.None;

            if (flipH)
            {
                se |= SpriteEffects.FlipHorizontally;
            }
            if (flipV)
            {
                se |= SpriteEffects.FlipVertically;
            }

            Rectangle rectSrc = Rectangle.Empty;

            if (sourceRectangle.HasValue)
            {
                rectSrc = sourceRectangle.Value;
            }
            else
            {
                if (wrapping)
                {
                    rectSrc = new Rectangle(0, 0, (int)drawRect.width, (int)drawRect.height);
                }
                else
                {
                    rectSrc = new Rectangle(0, 0, texture.Width, texture.Height);
                }
            }

            Vector2 vOrigin = Vector2.Zero;

            if (destinationRectangle.anchorInCenter)
            {
                vOrigin = new Vector2(rectSrc.Width / 2.0f, rectSrc.Height / 2.0f);
            }

            Vector2 vTransformedPos = Vector2.Transform(new Vector2(drawRect.x, drawRect.y), GetTransformation());

            drawRect.x = vTransformedPos.X;
            drawRect.y = vTransformedPos.Y;

            float fRot = 0.0f;

            if (Camera.AllowRotating && Camera.AllowTransforming)
            {
                fRot = Camera.Rotation;
            }

            if (wrapping)
            {
                this.spriteBatch.Draw(texture, drawRect.ToRectangle(),
                                      rectSrc, color, drawRect.rotation + fRot, vOrigin, se, CurrentDepth);
            }
            else
            {
                this.spriteBatch.Draw(texture, drawRect.ToRectangle(),
                                      rectSrc, color, drawRect.rotation + fRot, vOrigin, se, CurrentDepth);
            }
        }
Example #6
0
 /// <summary>
 /// Draw a texture with a shading color that can be flipped horizontally or vertically, as well as wrapped.
 /// </summary>
 /// <param name="texture">The texture.</param>
 /// <param name="destinationRectangle">The RotRect to draw to on the screen in world coordinates.</param>
 /// <param name="color">Shading color to use.</param>
 /// <param name="flipH">Whether to flip the texture horizontally.</param>
 /// <param name="flipV">Whether to flip the texture vertically.</param>
 /// <param name="wrapping">Whether to use texture wrapping.</param>
 public void Draw(Texture2D texture, RotRect destinationRectangle, Color color, bool flipH, bool flipV, bool wrapping)
 {
     Draw(texture, null, destinationRectangle, color, flipH, flipV, wrapping);
 }
Example #7
0
 /// <summary>
 /// Draw a texture with a shading color that can be flipped horizontally or vertically.
 /// </summary>
 /// <param name="texture">The texture.</param>
 /// <param name="destinationRectangle">The RotRect to draw to on the screen in world coordinates.</param>
 /// <param name="color">Shading color to use.</param>
 /// <param name="flipH">Whether to flip the texture horizontally.</param>
 /// <param name="flipV">Whether to flip the texture veritcally.</param>
 public void Draw(Texture2D texture, RotRect destinationRectangle, Color color, bool flipH, bool flipV)
 {
     Draw(texture, destinationRectangle, color, flipH, flipV, false);
 }
Example #8
0
 /// <summary>
 /// Draw a texture with a shading color.
 /// </summary>
 /// <param name="texture">The texture.</param>
 /// <param name="destinationRectangle">The RotRect to draw to on the screen in world coordinates.</param>
 /// <param name="color">Shading color to use.</param>
 public void Draw(Texture2D texture, RotRect destinationRectangle, Color color)
 {
     this.Draw(texture, destinationRectangle, color, false, false, false);
 }