Exemple #1
0
 private static void OnKeyboardDown(byte key, int x, int y)
 {
     if (key == 'w')
     {
         up = true;
     }
     else if (key == 's')
     {
         down = true;
     }
     else if (key == 'd')
     {
         right = true;
     }
     else if (key == 'a')
     {
         left = true;
     }
     else if (key == ' ')
     {
         space = true;
     }
     else if (key == 27)
     {
         Glut.glutLeaveMainLoop();
     }
 }
Exemple #2
0
 private static void OnKeyboardDown(byte key, int x, int y)
 {
     if (key == 27)
     {
         Glut.glutLeaveMainLoop();
     }
 }
Exemple #3
0
 private static void OnKeyboardUp(byte key, int x, int y)
 {
     if (key == 'l')
     {
         lighting = !lighting;
     }
     else if (key == 'f')
     {
         fullscreen = !fullscreen;
         if (fullscreen)
         {
             Glut.glutFullScreen();
         }
         else
         {
             Glut.glutPositionWindow(0, 0);
             Glut.glutReshapeWindow(1280, 720);
         }
     }
     else if (key == 32)
     {
         autoRotate = !autoRotate;
     }
     else if (key == 27)
     {
         Glut.glutLeaveMainLoop();
     }
 }
Exemple #4
0
        private static void OnKeyboardDown(byte key, int x, int y)
        {
            if (key == 'w')
            {
                zCam -= mov + 0.2f;
            }
            else if (key == 's')
            {
                zCam += mov + 0.2f;
            }

            if (key == 'd')
            {
                xCam += mov;
            }
            else if (key == 'a')
            {
                xCam -= mov;
            }

            if (key == 'q')
            {
                yCam -= mov;
            }
            else if (key == 'e')
            {
                yCam += mov;
            }

            if (key == 27)
            {
                Glut.glutLeaveMainLoop();
            }
        }
Exemple #5
0
        private static void OnKeyboardDown(byte key, int x, int y)
        {
            switch (key)
            {
            //escape
            case 27:
                Glut.glutLeaveMainLoop();
                break;

            case (byte)'w':
                up = true;
                break;

            case (byte)'a':
                left = true;
                break;

            case (byte)'d':
                right = true;
                break;

            case (byte)'s':
                down = true;
                break;

            case (byte)'r':
                xangle = 0;
                yangle = 0;
                zangle = 0;
                break;
            }
        }
Exemple #6
0
 private static void OnKeyboard(byte key, int x, int y)
 {
     // exit the program if the ESC key is pressed
     if (key == 27)
     {
         Glut.glutLeaveMainLoop();
     }
 }
Exemple #7
0
 private static void OnKeyboardDown(byte key, int x, int y)
 {
     if (key == 'w') up = true;
     else if (key == 's') down = true;
     else if (key == 'd') right = true;
     else if (key == 'a') left = true;
     else if (key == 27) Glut.glutLeaveMainLoop();
 }
Exemple #8
0
        private static void OnKeyboardDown(byte key, int x, int y)
        {
            if (key == 'w')
            {
                up = true;
            }
            else if (key == 's')
            {
                down = true;
            }
            else if (key == 'd')
            {
                right = true;
            }
            else if (key == 'a')
            {
                left = true;
            }
            else if (key == 'p')
            {
                if (maxdiffuse <= maximumDiffuse)
                {
                    maxdiffuse = maxdiffuse + 0.1f;
                }
            }
            else if (key == 'o')
            {
                if (maxdiffuse >= minimumDiffuse)
                {
                    maxdiffuse = maxdiffuse - 0.1f;
                }
            }
            else if (key == ']')
            {
                if (ambient <= maximumAmbient)
                {
                    ambient = ambient + 0.05f;
                }
            }
            else if (key == '[')
            {
                if (ambient >= minimumAmbient)
                {
                    ambient = ambient - 0.05f;
                }
            }
            else if (key == 27)
            {
                Glut.glutLeaveMainLoop();
            }

            if (key == 27)
            {
                Glut.glutLeaveMainLoop();
            }
        }
Exemple #9
0
        //======================================================================
        // cette fonction est invoquée par OpenGl lorsqu'on appuie sur une touche normale (A,Z,E, ...)
        // P_Touche contient le code de la touche, P_X et P_Y contiennent les coordonnées de la souris quand on appuie sur une touche
        static void Gestion_Clavier(byte P_Touche, int P_X, int P_Y)
        {
            Console.WriteLine($"Touche Normale : {P_Touche}. La souris est en {P_X} {P_Y}");

            if (P_Touche == 27)             // 27 est la touche "Échap"
            {
                Glut.glutLeaveMainLoop();
            }



            Glut.glutPostRedisplay();             // demander d'afficher une Frame (cela invoquera Afficher_Ma_Scene )
        }
Exemple #10
0
        private void OnKeyboardDown(byte key, int x, int y)
        {
            player.KeyInput(key);

            if (key == 'l')
            {
                map.ResizeMap(false);
                Console.WriteLine("Py Pos: " + (map.mapY + player.position.Z));
            }

            if (key == 27)
            {
                Glut.glutLeaveMainLoop();
            }
        }
Exemple #11
0
 private static void OnKeyboardUp(byte key, int x, int y)
 {
     if (key == 'w')
     {
         up = false;
     }
     else if (key == 's')
     {
         down = false;
     }
     else if (key == 'd')
     {
         right = false;
     }
     else if (key == 'a')
     {
         left = false;
     }
     else if (key == 'l')
     {
         lighting = !lighting;
     }
     else if (key == 'f')
     {
         fullscreen = !fullscreen;
         if (fullscreen)
         {
             Glut.glutFullScreen();
         }
         else
         {
             Glut.glutPositionWindow(0, 0);
             Glut.glutReshapeWindow(1280, 720);
         }
     }
     else if (key == 32)
     {
         shoot = false;
     }
     else if (key == 27)
     {
         Glut.glutLeaveMainLoop();
     }
 }
Exemple #12
0
        static void Gestion_Clavier(byte P_Touche, int P_X, int P_Y)
        {
            Console.WriteLine($"Touche Normale : {P_Touche}. La souris est en {P_X} {P_Y}");

            if (P_Touche == 27)             // Echap
            {
                Glut.glutLeaveMainLoop();
            }

            if (P_Touche == 97)             // A
            {
                Liste_objet.AddFirst(new C_CARRE());
            }

            if (P_Touche == 122)             // Z
            {
                Liste_objet.AddFirst(new C_CERCLE());
            }

            Glut.glutPostRedisplay();             // demander d'afficher une Frame (cela invoquera Afficher_Ma_Scene )
        }
Exemple #13
0
        private void OnRenderFrame()
        {
            if (exit)
            {
                Glut.glutLeaveMainLoop();
            }
            else
            {
                watch.Stop();
                float deltaTime = (float)watch.ElapsedTicks / Stopwatch.Frequency;
                float tempfps   = 1.0f / deltaTime;
                fps = fps * 0.9f + tempfps * 0.1f;
                // linear interpolate retained fps with this frames fps with a strong weighting to former.
                watch.Restart();

                if (layerInfo.ShowInfo)
                {
                    Camera  tempCam     = theSceneManager.TheCamera;
                    Vector4 tempViewDir = tempCam.Orientation.ToAxisAngle();
                    string  tempText    = string.Format(
                        "FPS: {0:0.00}, Mouse: [({1:0},{2:0}),{3:0.0},{4:0.0},{5:0.0}], Camera: Pos[{6:0.0},{7:0.0},{8:0.0}]",
//                        "FPS: {0:0.00}, Mouse: [({1:0},{2:0}),{3:0.0},{4:0.0},{5:0.0}], Camera: Pos[{6:0.0},{7:0.0},{8:0.0}] Dir[{9:0.0},{10:0.0},{11:0.0}]",
                        fps, mouseCoord.x, mouseCoord.y, mouseWorld.x, mouseWorld.y, mouseWorld.z,
                        tempCam.Position.x, tempCam.Position.y, tempCam.Position.z
//                        tempViewDir.x, tempViewDir.y, tempViewDir.z
                        );
                    layerInfo.GameInfo = tempText;
                }


                // set camForward the viewport and clear the previous depth and color buffers
                Gl.Viewport(0, 0, width, height);
                Gl.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);


                theSceneManager.OnRenderFrame(deltaTime);

                Glut.glutSwapBuffers();
            }
        }
Exemple #14
0
 private static void OnKeyDown(byte key, int x, int y)
 {
     if (key == 'w')
     {
         xangle -= step;
     }
     else if (key == 's')
     {
         xangle += step;
     }
     else if (key == 'a')
     {
         yangle -= step;
     }
     else if (key == 'd')
     {
         yangle += step;
     }
     else if (key == ' ')
     {
         stopwatch = stopwatch == null?System.Diagnostics.Stopwatch.StartNew() : null;
     }
     else if (key == 'f')
     {
         fullscreen = !fullscreen;
         if (fullscreen)
         {
             Glut.glutFullScreen();
         }
         else
         {
             Glut.glutPositionWindow(0, 0);
         }
     }
     else if (key == 27)
     {
         Glut.glutLeaveMainLoop();
     }
 }
Exemple #15
0
 private static void OnKeyboardDown(byte key, int x, int y)
 {
     if (key == 'w')
     {
         up = true;
     }
     else if (key == 's')
     {
         down = true;
     }
     else if (key == 'd')
     {
         right = true;
     }
     else if (key == 'a')
     {
         left = true;
     }
     else if (key == 'e')
     {
         eKey = true;
     }
     else if (key == 'q')
     {
         qKey = true;
     }
     else if (key == 'r')
     {
         moveSpeed = 6;
     }
     else if (key == 'o')
     {
         isFlying = !isFlying;
     }
     else if (key == 27)
     {
         Glut.glutLeaveMainLoop();
     }
 }
Exemple #16
0
 private static void OnKeyboardDown(byte key, int x, int y)
 {
     if (key == 'w')
     {
         up = true;             //zamiana stanu podanych zmiennych
     }
     else if (key == 's')
     {
         down = true;                  //zamiana stanu podanych zmiennych
     }
     else if (key == 'd')
     {
         right = true;                  //zamiana stanu podanych zmiennych
     }
     else if (key == 'a')
     {
         left = true;                  //zamiana stanu podanych zmiennych
     }
     else if (key == 27)
     {
         Glut.glutLeaveMainLoop();                 //wyjscie z glownej petli
     }
 }
Exemple #17
0
        public static void Init()
        {
            Vector2 buttonSize = new Vector2(0.3, 0.08);

            btn_Back_Title = new Button(new Vector2(0, -0.7), buttonSize, "Back", TextStyle.Chiller_SingleLine_Large, delegate() { SwitchTo(State.Main); });
            backgroundhue  = 180;

            #region Home Screen
            btn_Main_Play    = new Button(new Vector2(0, 0.3), buttonSize, "Play", TextStyle.Chiller_SingleLine_Large, delegate() { SwitchTo(State.WorldSelect); });
            btn_Main_Credits = new Button(new Vector2(0, -0.05), buttonSize, "Credits", TextStyle.Chiller_SingleLine_Large, delegate() { SwitchTo(State.Credits); });
            btn_Main_Help    = new Button(new Vector2(0, -0.4), buttonSize, "Help", TextStyle.Chiller_SingleLine_Large, delegate() { SwitchTo(State.Help); });
            btn_Main_Exit    = new Button(new Vector2(0, -0.75), buttonSize, "Exit", TextStyle.Chiller_SingleLine_Large, delegate() { Glut.glutLeaveMainLoop(); });
            #endregion

            #region Background
            txt_Main_Title = new Text("TITLE HERE", new TextStyle(TextAlignment.Center, TextFont.Chiller, 3f, 2f, 1, 1f, new Vector3(1, 1, 1)), new Vector2(0, 1));
            backgroundpos  = Vector2.Zero;
            float s = 1f / Program.AspectRatio;
            float imageAspectRatio = (float)Textures.TitleBackgroundTex.Size.Width / Textures.TitleBackgroundTex.Size.Height;
            background = GuiModel.CreateRectangle(new Vector2(s * imageAspectRatio, s), Textures.TitleBackgroundTex);
            background.vao.UpdateUVs(new Vector2[] {
                backgroundpos + new Vector2(0, 1f),
                backgroundpos + new Vector2(0, 0),
                backgroundpos + new Vector2(1, 0),
                backgroundpos + new Vector2(1, 1f)
            });
            #endregion

            #region Credits
            TextStyle tstyle = new TextStyle(TextAlignment.Center, TextFont.Chiller, 0.8f, 1.8f, 1 << 30, 0.5f, new Vector3(1, 1, 1));
            txt_CreditsInfo = new Text("Copyright Alex Tan (2016). Apache License. https://github.com/Pilex1/2D-Game/blob/master/LICENSE" + Environment.NewLine + Environment.NewLine + "- code, bugs, game design, bugs, graphics, bugs, everything you see here, bugs. Did I mention bugs?" + Environment.NewLine + Environment.NewLine + "Help me continue making these projects:" + Environment.NewLine + Environment.NewLine + "Visit my github repositories to view and download the full source code plus my other projects" + Environment.NewLine + " - https://github.com/Pilex1" + Environment.NewLine + " - https://github.com/Pilex1/2D-Game" + Environment.NewLine + Environment.NewLine + "Subscribe to my youtube channel where I post videos of Mandelbrot renders and game development" + Environment.NewLine + " - Pilex", tstyle, new Vector2(0, 0.9));
            #endregion

            #region World Pickers
            btnWorldPickers = new List <Button>();

            txtboxWorldPickers = new List <Textbox>();
            worlds             = new HashSet <string>();
            ResetWorldPickers();
            #endregion

            #region New World
            //creating new world
            txtbx_NewWorld_Name = new Textbox(new Vector2(0, 0.5), new Vector2(0.3, 0.03), TextFont.Chiller, 0.6f);
            txtbx_NewWorld_Seed = new Textbox(new Vector2(0, 0.2), new Vector2(0.3, 0.03), TextFont.Chiller, 0.6f);
            float offset = 0.15f;
            txt_NewWorld_Name        = new Text("World Name", tstyle, new Vector2(0, 0.5 + offset));
            txt_NewWorld_Seed        = new Text("Seed", tstyle, new Vector2(0, 0.2 + offset));
            btn_NewWorld_CreateWorld = new Button(new Vector2(0, -0.3), new Vector2(0.3, 0.08), "Create", TextStyle.Chiller_SingleLine_Large, delegate() {
                string worldname = txtbx_NewWorld_Name.GetText();
                worlds.Add(worldname);
                Program.SwitchToGame(worldname, int.Parse(txtbx_NewWorld_Seed.GetText()));
            });
            btn_NewWorld_RandSeed = new Button(new Vector2(0.5, 0.2), new Vector2(0.15, 0.03), "Random seed", TextStyle.Chiller_SingleLine_Small, delegate() {
                int irand = MathUtil.RandInt(Program.Rand, 1 << 24, 1 << 30);
                txtbx_NewWorld_Seed.SetText(irand.ToString());
            });
            btn_NewWorld_Back = new Button(new Vector2(0, -0.7), buttonSize, "Back", TextStyle.Chiller_SingleLine_Large, delegate() {
                txtbx_NewWorld_Name.ClearText();
                txtbx_NewWorld_Name.disabled = true;

                txtbx_NewWorld_Seed.ClearText();
                txtbx_NewWorld_Seed.disabled = true;

                SwitchTo(State.WorldSelect);
            });
            #endregion

            #region Help
            txt_Help = new Text("How to play:" + Environment.NewLine + "W A S D - movement" + Environment.NewLine + "Left click - destroy tile" + Environment.NewLine + "Right click - interact / place tile" + Environment.NewLine + "E - open / close inventory" + Environment.NewLine + "Mousewheel and keys 1 to 9 - hotbar selection" + Environment.NewLine + Environment.NewLine + "Debug controls: (pretend these don't exist)" + Environment.NewLine + "F1 - toggle tile data view" + Environment.NewLine + "F - toggle flying", tstyle, new Vector2(0, 0.9));
            #endregion

            SwitchTo(State.Main);
        }
Exemple #18
0
 public static void StopMainLoop()
 {
     Glut.glutLeaveMainLoop();
 }
Exemple #19
0
 public void OnEscClick()
 {
     Glut.glutLeaveMainLoop();
 }
Exemple #20
0
        private static void KeyboardPress(byte key, int x, int y)
        {
            if (key == '[')
            {
                pyramidRodationSide = -1;
            }
            else if (key == ']')
            {
                pyramidRodationSide = 1;
            }
            else if (key == 'q')
            {
                pyramidSpeed = 0;
            }
            else if (key == 'w')
            {
                pyramidSpeed = 1;
            }
            else if (key == 'e')
            {
                pyramidSpeed = 2;
            }
            else if (key == 'r')
            {
                pyramidSpeed = 3;
            }
            else if (key == 't')
            {
                pyramidSpeed = 4;
            }

            else if (key == '.')
            {
                cubeRotationSide = -1;
            }
            else if (key == '/')
            {
                cubeRotationSide = 1;
            }
            else if (key == 'z')
            {
                cubeSpeed = 0;
            }
            else if (key == 'x')
            {
                cubeSpeed = 1;
            }
            else if (key == 'c')
            {
                cubeSpeed = 2;
            }
            else if (key == 'v')
            {
                cubeSpeed = 3;
            }
            else if (key == 'b')
            {
                cubeSpeed = 4;
            }

            else if (key == 27)
            {
                Glut.glutLeaveMainLoop();
            }
        }
Exemple #21
0
        }//OnReshape end

        public static void OnKeyboardDown(byte key, int x, int y)
        {
            if (key == 'w')
            {
                Data.up = true;
            }
            else if (key == 's')
            {
                Data.down = true;
            }
            else if (key == 'd')
            {
                Data.right = true;
            }
            else if (key == 'a')
            {
                Data.left = true;
            }
            else if (key == '-')
            {
                Data.cameraPos.z += 0.1f;
            }
            else if (key == '+' || key == '=')
            {
                Data.cameraPos.z -= 0.1f;
            }
            else if (key == '4')
            {
                Data.cameraPos.x -= 0.1f;
            }
            else if (key == '6')
            {
                Data.cameraPos.x += 0.1f;
            }
            else if (key == '7')
            {
                Data.lightDir.x += 0.5f;
            }
            else if (key == '8')
            {
                Data.lightDir.y += 0.5f;
            }
            else if (key == '9')
            {
                Data.lightDir.z -= 0.5f;
            }
            else if (key == '1')
            {
                Data.lightDir.x -= 0.5f;
            }
            else if (key == '2')
            {
                Data.lightDir.y -= 0.5f;
            }
            else if (key == '3')
            {
                Data.lightDir.z -= 0.5f;
            }
            else if (key == 27)
            {
                Glut.glutLeaveMainLoop();
            }
        }