Exemple #1
0
            public void render(double x, double y, double size, int alpha, PumpkinFont font)
            {
                int colorFadeVal = alpha - fade;

                if (colorFadeVal > 1)
                {
                    RenderText(txt, x, y, size, Color.FromArgb(colorFadeVal, hue), font);
                }
                else
                {
                    delete = true;
                }

                if (timer > duration)
                {
                    fade++;
                }
                timer++;
            }
Exemple #2
0
        public static void LAUNCH(Action loadAction, Action <MouseState, KeyboardState, double, double> logicAction, Action renderAction, Action <string> cmdAction,
                                  int size, double orth, bool fullscreen, Color bgColor, string winName, int fps, string fontDir)
        {
            Console.WriteLine("> launching...");
            orthR = 1920 * orth; orthL = -1920 * orth; orthU = 1080 * orth; orthD = -1080 * orth;
            winW  = 1500 * size; winH = 845 * size;
            double cmdTxtX = orthL + 50, cmdTxtY = orthD + 100, cmdInputY = orthD + 50, boxX = orthR - 100, boxY = orthU - 100, boxAngle = 0;
            string buildName   = ENGINE_NAME.ToLower() + " - " + winName.ToLower();
            int    splashTimer = 0;

            using (var game = new GameWindow(winW, winH, OpenTK.Graphics.GraphicsMode.Default, winName + " - " + ENGINE_NAME))
            {
                game.Load += (sender, e) =>
                {
                    GL.Ortho(orthL, orthR, orthD, orthU, -1, 1);
                    if (fullscreen)
                    {
                        game.WindowState = WindowState.Fullscreen;
                    }
                    GL.ClearColor(bgColor);
                    game.VSync = VSyncMode.Off;

                    try
                    {
                        game.Icon  = new Icon(fontDir + @"/icon.ico");
                        logoSplash = new TysonBitmap(fontDir + "/splash.png", true);
                        cmdFont    = new PumpkinFont(fontDir, "#abcdefghijklmnopqrstuvwxyz1234567890().+-", 3 * CMD_SCALE, 2 * CMD_SCALE, 1.402 * CMD_SCALE);
                        cursorFont = new PumpkinFont(fontDir, "^", 3.05 * CMD_SCALE, 2.5 * CMD_SCALE, 2 * CMD_SCALE, false);
                    }
                    catch
                    {
                        Console.WriteLine("> Error: failed to load cmd font!");
                        Console.WriteLine("> cmd off");
                        CMD_ON = false;
                    }

                    loadAction();
                    Console.WriteLine("> initializing complete");
                    ADD_CMD_LINE("press / (forward slash) to open cmd");
                };

                game.Resize += (sender, e) => { GL.Viewport(0, 0, game.Width, game.Height); };

                game.UpdateFrame += (sender, e) =>
                {
                    mStat   = Mouse.GetState();
                    keyStat = Keyboard.GetState();

                    if (exit || keyStat[Key.Escape])
                    {
                        game.Exit();
                    }

                    if (splashTimer >= 1000)
                    {
                        if (SHOW_MOUSE)
                        {
                            Mouse.SetPosition(500, 500);
                            System.Windows.Forms.Cursor.Hide();
                        }

                        mouseX = mStat.X;
                        mouseY = -mStat.Y;


                        if (CMD_ON)
                        {
                            if (keyStat[Key.Tilde])
                            {
                                if (!toggle[0])
                                {
                                    if (cmdInput)
                                    {
                                        DEACTIVATE_CMD();
                                    }
                                    else
                                    {
                                        ACTIVATE_CMD();
                                    }
                                }
                                toggle[0] = true;
                            }
                            else
                            {
                                toggle[0] = false;
                            }

                            if (cmdInput)
                            {
                                if (keyStat[Key.Up])
                                {
                                    cmdInStr.SetString(oldtxt);
                                }

                                if (inTxt.Length > 0)
                                {
                                    if (keyStat[Key.Enter])
                                    {
                                        if (!toggle[1])
                                        {
                                            ADD_CMD_LINE(inTxt);
                                            if (inTxt[0].ToString() == "/")
                                            {
                                                PERFORM_COMMAND(inTxt);
                                                cmdAction(inTxt);
                                            }
                                            oldtxt = inTxt;
                                            cmdInStr.Clear();
                                        }
                                        toggle[1] = true;
                                    }
                                    else
                                    {
                                        toggle[1] = false;
                                    }
                                }
                            }
                            else
                            {
                                if (keyStat[Key.Slash])
                                {
                                    ACTIVATE_CMD();
                                    cmdInStr.SetString("/");
                                }
                            }

                            if (!PAUSE)
                            {
                                boxAngle += 0.1;
                            }
                        }

                        if (!PAUSE)
                        {
                            logicAction(mStat, keyStat, mouseX, mouseY);
                        }
                    }
                };

                game.RenderFrame += (sender, e) =>
                {
                    GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

                    if (splashTimer < 2000)
                    {
                        if (logoSplash != null)
                        {
                            logoSplash.Render(0, 0, 500, 219);
                        }
                        else
                        {
                            splashTimer = 3000;
                        }
                        splashTimer++;
                    }
                    else
                    {
                        renderAction();

                        if (CMD_ON)
                        {
                            RenderBoxTheta(boxX, boxY, 50, 50, SPIN_BOX_HUE, boxAngle);

                            for (int i = 0; i < cmd_list.Count; i++)
                            {
                                if (cmdInput)
                                {
                                    cmd_list[i].render(cmdTxtX, (cmdTxtY - (i * FONT_SPACING_VERT)) + cmdYshift, CMD_TXT_ABSTRACT_SIZE_DEFAULT, 255, cmdFont);
                                }
                                else
                                {
                                    cmd_list[i].render(cmdTxtX, (cmdTxtY - (i * FONT_SPACING_VERT)) + cmdYshift, CMD_TXT_ABSTRACT_SIZE_DEFAULT, CMD_HUD_ALPHA, cmdFont);
                                }
                                if (cmd_list[i].isDelete())
                                {
                                    REMOVE_CMD_LINE(i);
                                }
                            }

                            if (cmdInput)
                            {
                                inTxt = cmdInStr.GetInput(keyStat);
                                RenderBox(0, orthD, orthL * 2, 100, Color.White);
                                RenderText(inTxt, cmdTxtX, cmdInputY, CMD_TXT_ABSTRACT_SIZE_DEFAULT, Color.Black, cmdFont);
                                RenderText(inTxt + "^", cmdTxtX, cmdInputY, CMD_TXT_ABSTRACT_SIZE_DEFAULT, Color.Red, cursorFont);
                            }

                            RenderText(buildName, cmdTxtX, boxY, 15, BUILD_TXT_HUE, cmdFont);
                        }

                        if (SHOW_MOUSE)
                        {
                            RenderTriangle(mouseX, mouseY - CMD_TXT_ABSTRACT_SIZE_DEFAULT, CMD_TXT_ABSTRACT_SIZE_DEFAULT, Color.Red);
                        }
                    }

                    game.SwapBuffers();
                };
                Console.WriteLine("> done");
                game.Run(fps);
            }
        }
Exemple #3
0
        // PUBLIC FUNCTIONS
        public static void RenderText(string txt, double X, double Y, double size, Color hue, PumpkinFont font)
        {
            double offset  = 0;
            double offsetA = size * font.spacing;

            for (int i = 0; i < txt.Length; i++)
            {
                font.RenderLetter(txt[i].ToString(), X + (i * offsetA) - offset, Y, size * font.width, size * font.height, hue);

                switch (txt[i].ToString())
                {
                case "f":
                case "t":
                case "r":
                case "s":
                case "k":
                    offset += (size * font.spacing) / 3;
                    break;

                case "i":
                case "l":
                    offset += (size * font.spacing) / 2;
                    break;

                case "j":
                    offset += (size * font.spacing) / 3;
                    break;
                }
            }
        }