Ejemplo n.º 1
0
        public void DrawTest()
        {
            Hexagon hexagon = new Hexagon();

            hexagon.Draw(new FakeAdaptor());
            Assert.IsNotNull(hexagon);
        }
Ejemplo n.º 2
0
        //---------------------------------------------------------------------
        private static void Shapes()
        {
            Action <Surface> draw = surface =>
            {
                using (var c = new Context(surface))
                {
                    c.Antialias = Antialias.Subpixel;

                    // Hexagon:
                    Shape shape = new Hexagon(50);
                    shape.Draw(c, 50, 50);
                    shape.Fill(c, 50, 50, new Color(0.5, 0.5, 0.5));

                    // Square:
                    shape = new Square(50);
                    shape.Draw(c, 150, 50);
                    shape.Fill(c, 150, 50, new Color(0.5, 0.5, 0.5));

                    // Circle:
                    shape = new Circle(50);
                    shape.Draw(c, 100, 150);
                    shape.Fill(c, 100, 150, new Color(0.5, 0.5, 0.5));

                    // Bounding box:
                    var boundingBox = new Square(50);
                    c.LineWidth = 1;
                    var red = new Color(1, 0, 0);
                    boundingBox.Draw(c, 50, 50, red);
                    boundingBox.Draw(c, 150, 50, red);
                    boundingBox.Draw(c, 100, 150, red);
                }
            };

            using (Surface surface = new ImageSurface(Format.Argb32, 180, 180))
            {
                draw(surface);
                surface.WriteToPng("shapes.png");
            }

            using (Surface surface = new PdfSurface("shapes.pdf", 180, 180))
                draw(surface);

            using (Surface surface = new PSSurface("shapes.eps", 300, 300))
                draw(surface);

            using (Surface surface = new SvgSurface("shapes.svg", 180, 180))
                draw(surface);
        }
		public void as_operator () {
			// trail cast, if not compatible, return null
			// Use "as" to test compatability. 
			object[] things = new object[ 4]; 
			things[ 0] = new Hexagon(); 
			things[ 1] = false; 
			things[ 2] = new Manager();
			things[ 3] = "Last thing"; 
			foreach (object item in things) { 
				Hexagon h = item as Hexagon; 
				if (h == null) 
					Console.WriteLine(" Item is not a hexagon"); 
				else { h.Draw(); 
				} 
			}


		}
Ejemplo n.º 4
0
        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Draw(GameTime gameTime)
        {
            Region selectedRegion = null;

            GraphicsDevice.Clear(Color.Black);

            hexagonTilemap.GenerateAtmosphere(camera.BoundingRectangle, camera);

            if (hexagonTexture == null)
            {
                hexagonTexture       = new RenderTarget2D(GraphicsDevice, 2 * hexagonTilemap.TileSize, (int)(SQRT3 * hexagonTilemap.TileSize));
                hexagonBorderTexture = new RenderTarget2D(GraphicsDevice, 2 * hexagonTilemap.TileSize, (int)(SQRT3 * hexagonTilemap.TileSize));
                GraphicsDevice.SetRenderTarget((RenderTarget2D)hexagonTexture);
                GraphicsDevice.Clear(Color.Transparent);
                spriteBatch.Begin();
                Hexagon hexagon = new Hexagon(new Vector2(hexagonTilemap.Tiles[0, 0].Hexagon.Width / 2, hexagonTilemap.Tiles[0, 0].Hexagon.Height / 2), hexagonTilemap.TileSize);
                hexagon.Draw(gameTime, spriteBatch, Color.White, Color.Black);
                spriteBatch.End();
                GraphicsDevice.SetRenderTarget((RenderTarget2D)hexagonBorderTexture);
                spriteBatch.Begin();
                hexagon.Draw(gameTime, spriteBatch, Color.Transparent, Color.Red, 3);
                spriteBatch.End();
                GraphicsDevice.SetRenderTarget(null);
            }

            spriteBatch.Begin(SpriteSortMode.Texture, BlendState.Additive, null, null, null, null, camera.GetViewMatrix());
            if (Mouse.GetState().LeftButton == ButtonState.Pressed)
            {
                Vector2 mousePosition = new Vector2(Mouse.GetState().Position.X, Mouse.GetState().Position.Y);
                mousePosition = camera.ScreenToWorld(mousePosition.X, mousePosition.Y);
                HexagonTile tile     = hexagonTilemap.GetTileAtCoordinates(mousePosition);
                Vector2     position = new Vector2(tile.Hexagon.Position.X,
                                                   tile.Hexagon.Position.Y);
                spriteBatch.Draw(hexagonBorderTexture, position, Color.Red);
                selectedRegion = tile.Region;
                foreach (HexagonTile nt in hexagonTilemap.GetAllNeighbors(tile))
                {
                    Vector2 pos = new Vector2(nt.Hexagon.Position.X,
                                              nt.Hexagon.Position.Y);
                    spriteBatch.Draw(hexagonBorderTexture, pos, Color.Red);
                }
            }
            spriteBatch.End();

            spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.Additive, null, null, null, null, camera.GetViewMatrix());
            if (regionView)
            {
                hexagonTilemap.DrawRegionalMap(spriteBatch, camera, hexagonTexture, selectedRegion);
            }
            else
            {
                hexagonTilemap.DrawMap(spriteBatch, camera, hexagonTexture);
            }
            spriteBatch.End();

            spriteBatch.Begin();
            spriteBatch.Draw(hexagonTexture, new Rectangle(Mouse.GetState().Position, new Point(8, 8)), Color.Red);
            spriteBatch.End();

            base.Draw(gameTime);
        }
Ejemplo n.º 5
0
 public void Draw(Graphics e)
 {
     hexagon.Draw(e);
     gun.Draw(e);
 }