コード例 #1
0
        private void DrawGrid(GameTime gameTime, SpriteBatch spriteBatch)
        {
            Vector2   pos = new Vector2(0, 0);
            Rectangle rec;


            for (int j = 0; j < cellArray.GetLength(1); j++)
            {
                for (int i = 0; i < cellArray.GetLength(0); i++)
                {
                    pos.X += cellWidth;
                    if (cellArray[i, j].type != 0)
                    {
                        rec = new Rectangle((int)pos.X, (int)pos.Y, cellWidth, cellWidth);
                        DrawPrimitives.DrawRectangle(rec, WhitePixel, getColor(cellArray[i, j].type), spriteBatch, true, 1);
                        DrawPrimitives.DrawRectangle(rec, WhitePixel, Color.Black, spriteBatch, false, 1);
                        spriteBatch.DrawString(font1, cellArray[i, j].count.ToString(), new Vector2(pos.X + 5, pos.Y + 5), Color.Red);

                        DrawConnector(pos, spriteBatch, 0, cellArray[i, j].north);
                        DrawConnector(pos, spriteBatch, 1, cellArray[i, j].south);
                        DrawConnector(pos, spriteBatch, 2, cellArray[i, j].east);
                        DrawConnector(pos, spriteBatch, 3, cellArray[i, j].west);
                    }
                }
                pos.X  = 0;
                pos.Y += cellWidth;
            }
        }
コード例 #2
0
    //Currently now showing stats.
    public static void DrawHealthBar(SpriteBatch spriteBatch, Texture2D whitePixel, Rectangle rec, Color col, bool showStats, bool border, int val, int totalVal)
    {
        //Draw the Health Bar
        float ratio = (float)val / (float)totalVal;

        int healthWidth = (int)Math.Round(rec.Width * ratio);

        Rectangle drawRec = rec;

        drawRec.Width = healthWidth;

        if (border)
        {
            Rectangle borderRec = new Rectangle(rec.X - 1, rec.Y - 1, rec.Width + 2, rec.Height + 2);
            DrawPrimitives.DrawRectangle(borderRec, whitePixel, Color.White, spriteBatch, false, 2);
        }

        DrawPrimitives.DrawRectangle(drawRec, whitePixel, col, spriteBatch, true, 2);
    }
コード例 #3
0
        public void DrawRectangle(string color, float width, float height, float CenterX, float CenterY)
        {
#if DOTNET
            Pen   p          = new Pen(Brushes.Black, 1);
            float upperleftX = CenterX - width / 2;
            float upperleftY = CenterY - height / 2;
            oGraphics?.DrawRectangle(p, upperleftX, upperleftY, width, height);
            DrawPrimitives?.DrawRectangle(color, width, height, CenterX, CenterY);
#else
            this.context.save();

            this.context.lineWidth = 1;
            this.context.beginPath();

            this.context.strokeStyle = color;

            this.context.strokeRect(CenterX - width / 2, CenterY - height / 2, width, height);

            this.context.closePath();
            this.context.stroke();

            this.context.restore();
#endif
        }
コード例 #4
0
        //draw the connectors of 10 x 10 cells
        private void DrawConnector(Vector2 pos, SpriteBatch spriteBatch, int dir, bool isConn)
        {
            Color c = Color.Black;

            if (isConn)
            {
                c = Color.White;
            }

            Rectangle rec;

            switch (dir)
            {
            case 0:     //north
                rec = new Rectangle((int)pos.X + (cellWidth / 2), (int)pos.Y, 2, 4);
                break;

            case 1:     //south
                rec = new Rectangle((int)pos.X + (cellWidth / 2), (int)pos.Y + (cellWidth - 4), 2, 4);
                break;

            case 2:     //east
                rec = new Rectangle((int)pos.X + (cellWidth - 4), (int)pos.Y + (cellWidth / 2), 4, 2);
                break;

            case 3:     //west
                rec = new Rectangle((int)pos.X, (int)pos.Y + (cellWidth / 2), 4, 2);
                break;

            default:
                rec = new Rectangle((int)pos.X, (int)pos.Y, 0, 0);
                break;
            }

            DrawPrimitives.DrawRectangle(rec, WhitePixel, c, spriteBatch, true, 1);
        }