示例#1
0
        public override void Draw(GameTime gameTime)
        {
            if (Visible)
            {
                SpriteBatch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied);
                Rectangle r = new Rectangle((int)Position.X, (int)Position.Y, (int)width, (int)height);
                SpriteBatch.DrawRectangle(r, Color.Yellow);
                for (int x = 0; x < Grid.NumberOfCellsX; x++)
                {
                    for (int y = 0; y < Grid.NumberOfCellsY; y++)
                    {
                        RectangleF cell = new RectangleF(Position.X + x * Grid.CellWidth, Position.Y + y * Grid.CellHeight,
                                                         Grid.CellWidth, Grid.CellHeight);

                        int l = Grid.Get(new Point(x, y)).Length;

                        Color c;
                        if (l > 0)
                        {
                            float f = l / 4f;
                            if (f > 1)
                            {
                                f = 1;
                            }
                            c   = Color.Red;
                            c.A = (byte)(255f * f);
                            SpriteBatch.FillRectangle(Convert(cell), c);
                        }
                        else
                        {
                            c   = Color.Yellow;
                            c.A = (byte)(255f * .5f);
                            SpriteBatch.DrawRectangle(Convert(cell), c);
                        }
                    }
                }
                SpriteBatch.End();
            }
        }
示例#2
0
 public static MonoGame.Extended.RectangleF Convert(RectangleF s)
 {
     return(new MonoGame.Extended.RectangleF(s.X, s.Y, s.Width, s.Height));
 }