Esempio n. 1
0
        public Game()
            : base(NominalWidth, NominalHeight, GraphicsMode.Default, "Impressive Solids")
        {
            VSync = VSyncMode.On;

            var ConfigDirectory = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + Path.DirectorySeparatorChar + "ImpressiveSolids";
            if (!Directory.Exists(ConfigDirectory)) {
                Directory.CreateDirectory(ConfigDirectory);
            }

            HighScoreFilename = ConfigDirectory + Path.DirectorySeparatorChar + "HighScore.dat";
            if (File.Exists(HighScoreFilename)) {
                using (var Stream = new FileStream(HighScoreFilename, FileMode.Open)) {
                    using (var Reader = new BinaryReader(Stream)) {
                        try {
                            HighScore = Reader.ReadInt32();
                        } catch (IOException) {
                            HighScore = 0;
                        }
                    }
                }
            } else {
                HighScore = 0;
            }

            Keyboard.KeyDown += new EventHandler<KeyboardKeyEventArgs>(OnKeyDown);

            TextureBackground = new Texture(new Bitmap("textures/background.png"));
            for (var i = 0; i < ColorsCount; i++) {
                ColorTextures[i] = new Texture(new Bitmap("textures/solids/" + i + ".png"));
            }

            var LabelFont = new Font(new FontFamily(GenericFontFamilies.SansSerif), 20, GraphicsUnit.Pixel);
            var LabelColor = Color4.SteelBlue;
            NextStickLabel = new TextRenderer(LabelFont, LabelColor, "Next");
            ScoreLabel = new TextRenderer(LabelFont, LabelColor, "Score");
            HighScoreLabel = new TextRenderer(LabelFont, LabelColor, "High score");

            var ScoreFont = new Font(new FontFamily(GenericFontFamilies.SansSerif), 50, GraphicsUnit.Pixel);
            var ScoreColor = Color4.Tomato;
            ScoreRenderer = new TextRenderer(ScoreFont, ScoreColor);
            HighScoreRenderer = new TextRenderer(ScoreFont, ScoreColor);

            var GameStateFont = new Font(new FontFamily(GenericFontFamilies.SansSerif), 30, GraphicsUnit.Pixel);
            var GameStateColor = Color4.Tomato;
            GameOverLabel = new TextRenderer(GameStateFont, GameStateColor, "Game over");
            PauseLabel = new TextRenderer(GameStateFont, GameStateColor, "Pause");
            PlayingGameLabel = new TextRenderer(GameStateFont, GameStateColor, "Playing");

            var GameStateHintFont = new Font(new FontFamily(GenericFontFamilies.SansSerif), 25, GraphicsUnit.Pixel);
            var GameStateHintColor = Color4.SteelBlue;
            GameOverHint = new TextRenderer(GameStateHintFont, GameStateHintColor, "Press Enter");
            UnpauseHint = new TextRenderer(GameStateHintFont, GameStateHintColor, "Press Space");
            PauseHint = new TextRenderer(GameStateHintFont, GameStateHintColor, "Space pauses");
        }
Esempio n. 2
0
        public void Render()
        {
            if ((null == Label) || ("" == Label)) {
                return;
            }

            if (NeedToRenderTexture) {
                using (var Bitmap = new Bitmap(Width, Height)) {
                    var Rectangle = new Rectangle(0, 0, Bitmap.Width, Bitmap.Height);
                    using (Graphics Graphics = Graphics.FromImage(Bitmap)) {
                        Graphics.Clear(System.Drawing.Color.Transparent);
                        Graphics.TextRenderingHint = TextRenderingHint.AntiAliasGridFit;
                        Graphics.DrawString(Label, Font, Brushes.White, Rectangle);

                        if (null != Texture) {
                            Texture.Dispose();
                        }
                        Texture = new Texture(Bitmap);
                    }
                }
                NeedToRenderTexture = false;
            }

            Texture.Bind();

            GL.Color4(Color);

            GL.Begin(BeginMode.Quads);

            GL.TexCoord2(0, 0);
            GL.Vertex2(0, 0);

            GL.TexCoord2((float)Texture.Width / Texture.PotWidth, 0);
            GL.Vertex2(Width, 0);

            GL.TexCoord2((float)Texture.Width / Texture.PotWidth, (float)Texture.Height / Texture.PotHeight);
            GL.Vertex2(Width, Height);

            GL.TexCoord2(0, (float)Texture.Height / Texture.PotHeight);
            GL.Vertex2(0, Height);

            GL.End();
        }