コード例 #1
0
    public void DrawArrow()
    {
        ShadowPosition current   = CurrentPosition;
        float          direction = TKMath.GetAngle(player.Position, current.position),
                       distance  = MathHelper.Clamp((player.Position - current.position).Length, 0f, 6f) / 20f;

        Color c = player.Color;

        c.A = 0.4f;

        circleMesh.Color = c;
        arrowMesh.Color  = c;

        #region Circle
        GL.Enable(EnableCap.StencilTest);

        GL.StencilMask(0xff);
        GL.Clear(ClearBufferMask.StencilBufferBit);

        GL.StencilFunc(StencilFunction.Never, 1, 0xff);
        GL.StencilOp(StencilOp.Replace, StencilOp.Keep, StencilOp.Keep);

        circleMesh.Reset();
        circleMesh.Translate(player.Position);
        circleMesh.RotateZ(direction);
        circleMesh.Translate(-distance, 0f);
        circleMesh.Scale(2.2f - distance * 1.5f);

        circleMesh.Draw();

        GL.StencilFunc(StencilFunction.Notequal, 1, 0xff);
        GL.StencilOp(StencilOp.Incr, StencilOp.Keep, StencilOp.Incr);

        circleMesh.Reset();
        circleMesh.Translate(player.Position);
        circleMesh.Scale(2f);

        circleMesh.RotateZ(direction);

        circleMesh.Draw();

        #endregion
        distance = distance * 3f - 0.5f;

        GL.StencilFunc(StencilFunction.Notequal, 1, 0xff);

        if (distance > 0)
        {
            arrowMesh.Reset();
            arrowMesh.Translate(player.Position);
            arrowMesh.RotateZ(direction);
            arrowMesh.Translate(0.9f, 0);
            arrowMesh.Scale(distance, 0.5f);

            arrowMesh.Draw();
        }

        GL.Disable(EnableCap.StencilTest);
    }
コード例 #2
0
        public void InitialPosition()
        {
            ShadowPosition expectedPosition = ShadowPosition.GetInitialPosition();
            Position       position         = Position.GetInitialPosition();

            Assert.Equal(expectedPosition.SideToMove, position.SideToMove);

            Assert.Equal(expectedPosition.GetVector(Color.White), position.GetVector(Color.White));
            Assert.Equal(expectedPosition.GetVector(Color.Black), position.GetVector(Color.Black));

            Assert.Equal(expectedPosition.GetVector(Piece.Pawn), position.GetVector(Piece.Pawn));
            Assert.Equal(expectedPosition.GetVector(Piece.Knight), position.GetVector(Piece.Knight));
            Assert.Equal(expectedPosition.GetVector(Piece.Bishop), position.GetVector(Piece.Bishop));
            Assert.Equal(expectedPosition.GetVector(Piece.Rook), position.GetVector(Piece.Rook));
            Assert.Equal(expectedPosition.GetVector(Piece.Queen), position.GetVector(Piece.Queen));
            Assert.Equal(expectedPosition.GetVector(Piece.King), position.GetVector(Piece.King));
        }
コード例 #3
0
    public PlayerShadow(Player p, Mesh m)
    {
        player  = p;
        mesh    = new Mesh(m.Vertices, m.UV);
        tileset = new Tileset(m.Tileset);

        mesh.Tileset = tileset;

        positionBuffer = new ShadowPosition[(int)(bufferLength / updateRate)];
        for (int i = 0; i < positionBuffer.Length; i++)
        {
            positionBuffer[i] = new ShadowPosition(p.Position, p.playerTileset, p.dir);
        }

        circleMesh = Mesh.CreateFromTexture(Art.Load("Res/circlebig.png"));
        arrowMesh  = new Mesh(new Vector3[] {
            new Vector3(-0.1f, 0f, 0f),
            new Vector3(0f, 0.5f, 0f),
            new Vector3(0f, -0.5f, 0f),
            new Vector3(1f, 0f, 0f)
        });
    }
コード例 #4
0
            /// <summary>
            /// Returns the standard initial position.
            /// </summary>
            public static ShadowPosition GetInitialPosition()
            {
                var initialPosition = new ShadowPosition
                {
                    sideToMove = Color.White
                };

                initialPosition.piecePerSquare[0] = ColoredPieceOrEmpty.WhiteRook;
                initialPosition.piecePerSquare[1] = ColoredPieceOrEmpty.WhiteKnight;
                initialPosition.piecePerSquare[2] = ColoredPieceOrEmpty.WhiteBishop;
                initialPosition.piecePerSquare[3] = ColoredPieceOrEmpty.WhiteQueen;
                initialPosition.piecePerSquare[4] = ColoredPieceOrEmpty.WhiteKing;
                initialPosition.piecePerSquare[5] = ColoredPieceOrEmpty.WhiteBishop;
                initialPosition.piecePerSquare[6] = ColoredPieceOrEmpty.WhiteKnight;
                initialPosition.piecePerSquare[7] = ColoredPieceOrEmpty.WhiteRook;

                for (int sq = 8; sq < 16; ++sq)
                {
                    initialPosition.piecePerSquare[sq] = ColoredPieceOrEmpty.WhitePawn;
                }

                for (int sq = 48; sq < 56; ++sq)
                {
                    initialPosition.piecePerSquare[sq] = ColoredPieceOrEmpty.BlackPawn;
                }

                initialPosition.piecePerSquare[56] = ColoredPieceOrEmpty.BlackRook;
                initialPosition.piecePerSquare[57] = ColoredPieceOrEmpty.BlackKnight;
                initialPosition.piecePerSquare[58] = ColoredPieceOrEmpty.BlackBishop;
                initialPosition.piecePerSquare[59] = ColoredPieceOrEmpty.BlackQueen;
                initialPosition.piecePerSquare[60] = ColoredPieceOrEmpty.BlackKing;
                initialPosition.piecePerSquare[61] = ColoredPieceOrEmpty.BlackBishop;
                initialPosition.piecePerSquare[62] = ColoredPieceOrEmpty.BlackKnight;
                initialPosition.piecePerSquare[63] = ColoredPieceOrEmpty.BlackRook;

                return(initialPosition);
            }
コード例 #5
0
 public void UpdateBuffer()
 {
     positionBuffer[positionBufferIndex] = new ShadowPosition(player.Position, player.playerTileset, player.dir);
     positionBufferIndex = (positionBufferIndex + 1) % positionBuffer.Length;
 }
コード例 #6
0
        internal static GraphicsPath RoundedRectPart(Rectangle bounds, int radius, ShadowPosition position)
        {
            int          diameter = radius * 2;
            Size         size     = new Size(diameter, diameter);
            Rectangle    arc      = new Rectangle(bounds.Location, size);
            GraphicsPath path     = new GraphicsPath {
                FillMode = FillMode.Alternate,
            };

            if (radius == 0)
            {
                path.AddRectangle(bounds);
                return(path);
            }

            if (position == ShadowPosition.Right)
            {
                arc.X = bounds.Right - diameter;
                path.AddArc(arc, 270, 90);
                arc.Y = bounds.Bottom - diameter;
                path.AddArc(arc, 0, 90);
            }
            else if (position == ShadowPosition.BottomRight)
            {
                arc.X = bounds.Right - diameter;
                path.AddArc(arc, 270, 90);
                arc.Y = bounds.Bottom - diameter;
                path.AddArc(arc, 0, 90);
                arc.X = bounds.Left;
                path.AddArc(arc, 90, 90);
            }
            else if (position == ShadowPosition.Bottom)
            {
                arc.X = bounds.Right - diameter;
                arc.Y = bounds.Bottom - diameter;
                path.AddArc(arc, 0, 90);
                arc.X = bounds.Left;
                path.AddArc(arc, 90, 90);
            }
            else if (position == ShadowPosition.BottomLeft)
            {
                arc.X = bounds.Right - diameter;
                arc.Y = bounds.Bottom - diameter;
                path.AddArc(arc, 0, 90);
                arc.X = bounds.Left;
                path.AddArc(arc, 90, 90);
                arc.Y = bounds.Top;
                path.AddArc(arc, 180, 90);
            }
            else if (position == ShadowPosition.Left)
            {
                arc.Y = bounds.Bottom - diameter;
                arc.X = bounds.Left;
                path.AddArc(arc, 90, 90);
                arc.Y = bounds.Top;
                path.AddArc(arc, 180, 90);
            }
            else if (position == ShadowPosition.TopLeft)
            {
                arc.Y = bounds.Bottom - diameter;
                arc.X = bounds.Left;
                path.AddArc(arc, 90, 90);
                arc.Y = bounds.Top;
                path.AddArc(arc, 180, 90);
                arc.X = bounds.Right - diameter;
                path.AddArc(arc, 270, 90);
            }
            else if (position == ShadowPosition.Top)
            {
                path.AddArc(arc, 180, 90);
                arc.X = bounds.Right - diameter;
                path.AddArc(arc, 270, 90);
            }
            else if (position == ShadowPosition.TopRight)
            {
                path.AddArc(arc, 180, 90);
                arc.X = bounds.Right - diameter;
                path.AddArc(arc, 270, 90);
                arc.Y = bounds.Bottom - diameter;
                path.AddArc(arc, 0, 90);
            }

            return(path);
        }
コード例 #7
0
        public static void DrawRoundedRectanglePart(this Graphics graphics, Pen pen, Rectangle bounds, int cornerRadius, ShadowPosition position)
        {
            using GraphicsPath path = RoundedRectPart(bounds, cornerRadius, position);
            path.Flatten(new Matrix(), 0.12f);

            PointF prevP = new PointF();
            int    total = path.PathPoints.Length;
            int    count = 1;
            float  penSize;

            int trim;

            if (position == ShadowPosition.Bottom || position == ShadowPosition.Top || position == ShadowPosition.Left || position == ShadowPosition.Right)
            {
                trim = 1;
            }
            else
            {
                trim = 2;
            }

            foreach (PointF p in path.PathPoints)
            {
                if (prevP.IsEmpty || count <= trim || count >= total - trim)
                {
                    prevP = p; count++; continue;
                }

                if (count <= 3 || count >= total - 3)
                {
                    penSize = 1;
                }
                else if (count <= 5 || count >= total - 5)

                {
                    penSize = 2;
                }
                else if (count <= 8 || count >= total - 8)
                {
                    penSize = 3;
                }
                else
                {
                    penSize = pen.Width;
                }

                if (penSize > pen.Width)
                {
                    penSize = pen.Width;
                }

                graphics.DrawLine(new Pen(pen.Color, penSize), prevP, p);
                prevP = p;
                count++;
            }
        }