コード例 #1
0
        public void Initialize(TileType type, Vector2 position, BufferSet set)
        {
            //allow only one initalization.
            if (!initalized)
            {
                Position = position;
                this.set = set;

                if (type == TileType.MINE)
                {
                    Type = type;
                    tex  = Resources.Textures["mine"];
                    //Visible = true;
                }

                else
                {
                    Type = TileType.EMPTY;
                    tex  = Resources.Textures["emptyTile"];
                }

                maskedTex  = Resources.Textures["blankTile"];
                initalized = true;
            }
            else
            {
                throw new InvalidOperationException("Can't initalize a tile twice!");
            }
        }
コード例 #2
0
        public void Initialize(TileType type, Vector2 position, BufferSet set)
        {
            //allow only one initalization.
            if (!initalized)
            {
                Position = position;
                this.set = set;

                if (type == TileType.MINE)
                {
                    Type = type;
                    tex = Resources.Textures["mine"];
                    //Visible = true;
                }

                else
                {
                    Type = TileType.EMPTY;
                    tex = Resources.Textures["emptyTile"];
                }

                maskedTex = Resources.Textures["blankTile"];
                initalized = true;
            }
            else
                throw new InvalidOperationException("Can't initalize a tile twice!");
        }
コード例 #3
0
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            //load all shaders/programs
            Resources.Shaders.Add("baseShaderVert", new Shader(@"Shaders/baseShader.vert", ShaderType.VertexShader));
            Resources.Shaders.Add("baseShaderFrag", new Shader(@"Shaders/baseShader.frag", ShaderType.FragmentShader));
            Resources.Programs.Add("baseShader", new Program(Resources.Shaders["baseShaderVert"], Resources.Shaders["baseShaderFrag"]));

            //load all textures
            Resources.Textures.Add("mine", new Texture(@"Textures/mine.png"));
            Resources.Textures.Add("blankTile", new Texture(@"Textures/blankTile.png"));
            Resources.Textures.Add("tileHover", new Texture(@"Textures/tileHover.png"));
            Resources.Textures.Add("tileMouseDown", new Texture(@"Textures/tileMouseDown.png"));
            Resources.Textures.Add("emptyTile", new Texture(@"Textures/emptyTile.png"));
            Resources.Textures.Add("youlost", new Texture(@"Textures/youlost.png"));
            Resources.Textures.Add("youwin", new Texture(@"Textures/youwin.png"));
            Resources.Textures.Add("flag", new Texture(@"Textures/flag.png"));
            Resources.Textures.Add("num1", new Texture(@"Textures/num1.png"));
            Resources.Textures.Add("num2", new Texture(@"Textures/num2.png"));
            Resources.Textures.Add("num3", new Texture(@"Textures/num3.png"));
            Resources.Textures.Add("num4", new Texture(@"Textures/num4.png"));
            Resources.Textures.Add("num5", new Texture(@"Textures/num5.png"));
            Resources.Textures.Add("num6", new Texture(@"Textures/num6.png"));
            Resources.Textures.Add("num7", new Texture(@"Textures/num7.png"));
            Resources.Textures.Add("num8", new Texture(@"Textures/num8.png"));

            //generate a single set of VBOs for a standard-sized square
            squareSet = new BufferSet();
            bannerSet = new BufferSet();

            float[] vertices = new float[]
            {
                -.5f, .5f,               //top left
                -.5f, -.5f,              //bottom left
                .5f, -.5f,               //bottom right
                .5f, .5f                 // top right
            };

            float[] texCoords = new float[]
            {
                0, 0,                //top left
                0, 1,                //bottom left
                1, 1,                //bottom right
                1, 0                 //top right
            };

            //triangles
            byte[] indices = new byte[]
            {
                0, 1, 2,
                0, 2, 3
            };

            squareSet.SetVertices(vertices);
            squareSet.SetTexCoords(texCoords);
            squareSet.SetIndices(indices);

            Random r = new Random();

            //choose a random point on the tileset that's not already chosen.
            for (int i = 0; i < mines; i++)
            {
                Point p = new Point(0, 0);
                do
                {
                    p = new Point(r.Next(tileset[0].Length), r.Next(tileset.Length));
                }while (tileset[p.Y][p.X].Type == TileType.MINE);

                tileset[p.Y][p.X].Initialize(TileType.MINE, new Vector2(p.X, p.Y), squareSet);
            }

            for (int i = 0; i < tileset.Length; i++)
            {
                for (int j = 0; j < tileset[0].Length; j++)
                {
                    Tile t = tileset[i][j];
                    if (!t.Initialized)
                    {
                        t.Initialize(TileType.EMPTY, new Vector2(j, i), squareSet);
                    }
                }
            }

            for (int i = 0; i < tileset.Length; i++)
            {
                for (int j = 0; j < tileset[0].Length; j++)
                {
                    tileset[i][j].GenerateNumbers(new Point(j, i), tileset);
                }
            }

            /*float left = -0.25f;
             * float right = (tileset[0].Length / 2) - 0.25f;*/
            float left   = -0.5f;
            float right  = tileset[0].Length;
            float bottom = -(right - left) / 4;
            float top    = (right - left) / 4;

            float[] bannerVertices = new float[]
            {
                left, top,
                left, bottom,
                right, bottom,
                right, top
            };

            bannerSet.SetVertices(bannerVertices);
            bannerSet.SetTexCoords(texCoords);
            bannerSet.SetIndices(indices);

            GL.ClearColor(new Color4(233, 255, 210, 255));
            GL.Enable(EnableCap.CullFace);
            GL.FrontFace(FrontFaceDirection.Ccw);
            GL.CullFace(CullFaceMode.Back);
            GL.Enable(EnableCap.Blend);
            GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);
        }
コード例 #4
0
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            //load all shaders/programs
            Resources.Shaders.Add("baseShaderVert", new Shader(@"Shaders/baseShader.vert", ShaderType.VertexShader));
            Resources.Shaders.Add("baseShaderFrag", new Shader(@"Shaders/baseShader.frag", ShaderType.FragmentShader));
            Resources.Programs.Add("baseShader", new Program(Resources.Shaders["baseShaderVert"], Resources.Shaders["baseShaderFrag"]));

            //load all textures
            Resources.Textures.Add("mine", new Texture(@"Textures/mine.png"));
            Resources.Textures.Add("blankTile", new Texture(@"Textures/blankTile.png"));
            Resources.Textures.Add("tileHover", new Texture(@"Textures/tileHover.png"));
            Resources.Textures.Add("tileMouseDown", new Texture(@"Textures/tileMouseDown.png"));
            Resources.Textures.Add("emptyTile", new Texture(@"Textures/emptyTile.png"));
            Resources.Textures.Add("youlost", new Texture(@"Textures/youlost.png"));
            Resources.Textures.Add("youwin", new Texture(@"Textures/youwin.png"));
            Resources.Textures.Add("flag", new Texture(@"Textures/flag.png"));
            Resources.Textures.Add("num1", new Texture(@"Textures/num1.png"));
            Resources.Textures.Add("num2", new Texture(@"Textures/num2.png"));
            Resources.Textures.Add("num3", new Texture(@"Textures/num3.png"));
            Resources.Textures.Add("num4", new Texture(@"Textures/num4.png"));
            Resources.Textures.Add("num5", new Texture(@"Textures/num5.png"));
            Resources.Textures.Add("num6", new Texture(@"Textures/num6.png"));
            Resources.Textures.Add("num7", new Texture(@"Textures/num7.png"));
            Resources.Textures.Add("num8", new Texture(@"Textures/num8.png"));

            //generate a single set of VBOs for a standard-sized square
            squareSet = new BufferSet();
            bannerSet = new BufferSet();

            float[] vertices = new float[]
            {
                -.5f, .5f, //top left
                -.5f, -.5f, //bottom left
                .5f, -.5f, //bottom right
                .5f, .5f // top right
            };

            float[] texCoords = new float[]
            {
                0, 0, //top left
                0, 1, //bottom left
                1, 1, //bottom right
                1, 0 //top right
            };

            //triangles
            byte[] indices = new byte[]
            {
                0, 1, 2,
                0, 2, 3
            };

            squareSet.SetVertices(vertices);
            squareSet.SetTexCoords(texCoords);
            squareSet.SetIndices(indices);

            Random r = new Random();

            //choose a random point on the tileset that's not already chosen.
            for (int i = 0; i < mines; i++)
            {
                Point p = new Point(0, 0);
                do
                {
                    p = new Point(r.Next(tileset[0].Length), r.Next(tileset.Length));
                }
                while (tileset[p.Y][p.X].Type == TileType.MINE);

                tileset[p.Y][p.X].Initialize(TileType.MINE, new Vector2(p.X, p.Y), squareSet);
            }

            for (int i = 0; i < tileset.Length; i++)
            {
                for (int j = 0; j < tileset[0].Length; j++)
                {
                    Tile t = tileset[i][j];
                    if (!t.Initialized)
                        t.Initialize(TileType.EMPTY, new Vector2(j, i), squareSet);
                }
            }

            for (int i = 0; i < tileset.Length; i++)
            {
                for (int j = 0; j < tileset[0].Length; j++)
                {
                    tileset[i][j].GenerateNumbers(new Point(j, i), tileset);
                }
            }

            /*float left = -0.25f;
            float right = (tileset[0].Length / 2) - 0.25f;*/
            float left = -0.5f;
            float right = tileset[0].Length;
            float bottom = -(right - left) / 4;
            float top = (right - left) / 4;

            float[] bannerVertices = new float[]
            {
                left, top,
                left, bottom,
                right, bottom,
                right, top
            };

            bannerSet.SetVertices(bannerVertices);
            bannerSet.SetTexCoords(texCoords);
            bannerSet.SetIndices(indices);

            GL.ClearColor(new Color4(233, 255, 210, 255));
            GL.Enable(EnableCap.CullFace);
            GL.FrontFace(FrontFaceDirection.Ccw);
            GL.CullFace(CullFaceMode.Back);
            GL.Enable(EnableCap.Blend);
            GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);
        }