Beispiel #1
0
        protected void drawHex(Vector3 position, Vector3 color, Texture texture)
        {
            Vector3[] hexVectors = getHexVectors();
            Vector2[] hexUVs     = getHexUVs();
            int[]     top        = getHexTriangleIndices(HexTriangleType.Top);
            int[]     topRight   = getHexTriangleIndices(HexTriangleType.TopRight);
            int[]     topLeft    = getHexTriangleIndices(HexTriangleType.TopLeft);
            int[]     botLeft    = getHexTriangleIndices(HexTriangleType.BotLeft);
            int[]     bot        = getHexTriangleIndices(HexTriangleType.Bot);
            int[]     botRight   = getHexTriangleIndices(HexTriangleType.BotRight);

            GL.BindTexture(TextureTarget.Texture2D, texture.GetId());
            GL.Begin(PrimitiveType.Triangles);

            for (int i = 0; i < 3; i++)
            {
                GL.Color3(color); GL.TexCoord2(hexUVs[top[i]].X, hexUVs[top[i]].Y); GL.Vertex3((position + (hexVectors[top[i]])).X, (position + hexVectors[top[i]]).Y, (position + hexVectors[top[i]]).Z);
            }

            for (int i = 0; i < 3; i++)
            {
                GL.Color3(color); GL.TexCoord2(hexUVs[topRight[i]].X, hexUVs[topRight[i]].Y); GL.Vertex3((position + hexVectors[topRight[i]]).X, (position + hexVectors[topRight[i]]).Y, (position + hexVectors[topRight[i]]).Z);
            }

            for (int i = 0; i < 3; i++)
            {
                GL.Color3(color); GL.TexCoord2(hexUVs[topLeft[i]].X, hexUVs[topLeft[i]].Y); GL.Vertex3((position + hexVectors[topLeft[i]]).X, (position + hexVectors[topLeft[i]]).Y, (position + hexVectors[topLeft[i]]).Z);
            }

            for (int i = 0; i < 3; i++)
            {
                GL.Color3(color); GL.TexCoord2(hexUVs[botLeft[i]].X, hexUVs[botLeft[i]].Y); GL.Vertex3((position + hexVectors[botLeft[i]]).X, (position + hexVectors[botLeft[i]]).Y, (position + hexVectors[botLeft[i]]).Z);
            }

            for (int i = 0; i < 3; i++)
            {
                GL.Color3(color); GL.TexCoord2(hexUVs[bot[i]].X, hexUVs[bot[i]].Y); GL.Vertex3((position + hexVectors[bot[i]]).X, (position + hexVectors[bot[i]]).Y, (position + hexVectors[bot[i]]).Z);
            }

            for (int i = 0; i < 3; i++)
            {
                GL.Color3(color); GL.TexCoord2(hexUVs[botRight[i]].X, hexUVs[botRight[i]].Y); GL.Vertex3((position + hexVectors[botRight[i]]).X, (position + hexVectors[botRight[i]]).Y, (position + hexVectors[botRight[i]]).Z);
            }

            GL.End();
            GL.BindTexture(TextureTarget.Texture2D, 0);
        }
Beispiel #2
0
        public WizardWarsGameWindow() : base(800, 600, GraphicsMode.Default, "WizardWars 0.0.1")
        {
            VSync = VSyncMode.On;

            lib.Texture _texGrass      = new lib.Texture("G:\\Archive\\Pictures\\2D\\Textures\\grass_64x64.png");
            lib.Texture _texGrassWater = new lib.Texture("G:\\Archive\\Pictures\\2D\\Textures\\grass_water_64x64.png");
            lib.Texture _texWater      = new lib.Texture("G:\\Archive\\Pictures\\2D\\Textures\\water_64x64.png");
            lib.Texture _texHouse      = new lib.Texture("G:\\Archive\\Pictures\\2D\\Textures\\house_64x64_2.png");
            lib.Texture _texGrid       = new lib.Texture("G:\\Archive\\Pictures\\2D\\Textures\\grid_64x64.png");
            lib.Texture _hexGrid       = new lib.Texture("G:\\Archive\\Pictures\\2D\\Textures\\hex_64x64.png");
            textureIdGrid = _hexGrid.GetId();

            List <lib.MapLayer> _mapLayers = new List <lib.MapLayer>();

            lib.Texture[,] terrainTextures = new lib.Texture[9, 9];
            for (int x = 0; x < 9; x++)
            {
                for (int y = 0; y < 9; y++)
                {
                    if (x % 2 == 0 && y % 8 == 0)
                    {
                        terrainTextures[x, y] = _texGrass;
                    }
                    else
                    {
                        terrainTextures[x, y] = _texGrass;
                    }
                }
            }
            lib.MapLayer terrainLayer = new lib.MapLayer(terrainTextures);
            _mapLayers.Add(terrainLayer);


            // Resources layer
            lib.Texture[,] resourcesTextures = new lib.Texture[9, 9];
            for (int x = 0; x < 9; x++)
            {
                for (int y = 0; y < 9; y++)
                {
                    //if (x == 3 && y == 2)
                    resourcesTextures[x, y] = _texHouse;
                    //else
                    // resourcesTextures[x, y] = _texGrass;
                }
            }
            lib.MapLayer resourcesLayer = new lib.MapLayer(resourcesTextures);
            _mapLayers.Add(resourcesLayer);

            // GridLayer
            lib.Texture[,] gridTextures = new lib.Texture[9, 9];
            for (int x = 0; x < 9; x++)
            {
                for (int y = 0; y < 9; y++)
                {
                    gridTextures[x, y] = _texGrid;
                }
            }
            lib.MapLayer gridLayer = new lib.MapLayer(gridTextures);
            _mapLayers.Add(gridLayer);


            hexMap = new lib.HexMap(new lib.MapDimension(9), new lib.MapDimension(9), _mapLayers);
        }