예제 #1
0
        private void simpleOpenGlControl1_KeyPress(object sender, KeyPressEventArgs e)
        {
            bool found = false;

            // this condition will be check if the keyChar in the dictionary of controls

            /* foreach (var i in controls)
             * {
             *   if (string.Compare(e.KeyChar.ToString(), i.Value.ToString(), StringComparison.OrdinalIgnoreCase) == 0)
             *   {
             *       found = true;
             *       break;
             *   }
             *
             * }
             * if (!found)
             *   return;*/

            /* if (!(renderer.cam.mPosition.to_array()[2] < new vec3(0, 0, 1900)[2] && renderer.cam.mPosition.to_array()[2] > new vec3(0, 0, -1900)[2] && renderer.pos[0] < 1950 && (renderer.pos[0] > -1950)))
             * {
             *   //renderer.cam.Walk(5);
             *   return;
             * }*/

            // MessageBox.Show(renderer.BackwardSide[0].ToString() + " "+ renderer.cam.mPosition.x.ToString());

            /*   if (renderer.BackwardSide.x == renderer.cam.mPosition.x && renderer.BackwardSide.y == renderer.cam.mPosition.y && renderer.BackwardSide.z == renderer.cam.mPosition.z)
             *     return;*/
            if (PlayerCollisionDetection(e.KeyChar))
            {
                if (Renderer.GameSoundIsOpened)
                {
                    walkingSound.Stop();
                    playerCollisionSound.Play();
                }

                return;
            }

            if (Renderer.GameSoundIsOpened)
            {
                if (!walking)
                {
                    walkingSound.PlayLooping();
                }
            }

            float speed = 5f;

            renderer.pos = renderer.cam.GetCameraPosition();
            if (string.Compare(e.KeyChar.ToString(), controls["Left"].ToString(), StringComparison.OrdinalIgnoreCase) == 0 && renderer.cam.mPosition.to_array()[2] > new vec3(0, 0, -1850)[2] && (renderer.pos[0] < 1850))
            {
                renderer.cam.Strafe(-speed);

                //WPressed = false; SPressed = false; DPressed = false;
            }
            else
            {
                renderer.cam.Strafe(2 * speed);
            }


            if (string.Compare(e.KeyChar.ToString(), controls["Right"].ToString(), StringComparison.OrdinalIgnoreCase) == 0 && renderer.cam.mPosition.to_array()[2] < new vec3(0, 0, 1550)[2] && (renderer.pos[0] > -1850))
            {
                renderer.cam.Strafe(speed);
                //WPressed = false; SPressed = false; APressed = false;
            }
            else
            {
                renderer.cam.Strafe(-2 * speed);
            }

            if (string.Compare(e.KeyChar.ToString(), controls["Backward"].ToString(), StringComparison.OrdinalIgnoreCase) == 0)
            {
                if (renderer.cam.mPosition.to_array()[2] > new vec3(0, 0, -1900)[2] && renderer.cam.mPosition.to_array()[2] < new vec3(0, 0, 1900)[2] && renderer.pos[0] > -1500 && (renderer.pos[0] < 1500))
                {
                    renderer.cam.Walk(-speed);
                }

                /*  else
                 * {
                 *   // MessageBox.Show(renderer.cam.mPosition.to_array()[2].ToString());
                 *    renderer.cam.Walk(2 * speed);
                 * }*/
            }
            if (string.Compare(e.KeyChar.ToString(), controls["Forward"].ToString(), StringComparison.OrdinalIgnoreCase) == 0)
            {
                if (renderer.cam.mPosition.to_array()[2] < new vec3(0, 0, 1900)[2] && renderer.cam.mPosition.to_array()[2] > new vec3(0, 0, -1900)[2] && renderer.pos[0] < 1950 && (renderer.pos[0] > -1950))
                {
                    renderer.cam.Walk(speed);
                    //APressed = false; SPressed = false; DPressed = false;
                }

                /* else
                 * {
                 *
                 *   renderer.cam.Walk(-2 * speed);
                 * }*/
            }


            if (string.Compare(e.KeyChar.ToString(), controls["Switch"].ToString(), StringComparison.OrdinalIgnoreCase) == 0)
            {
                if (mouse_move == true)
                {
                    mouse_move = false;
                }

                else
                {
                    mouse_move = true;
                }
            }
            if (e.KeyChar == 'c')
            {
                //   MessageBox.Show("about = " + renderer.about.ToString() + "   option = " + renderer.option_screen.ToString() + "   load = " + renderer.load.ToString());

                if (renderer.about == true)
                {
                    /// about ==> option
                    renderer.option_screen = false;
                }
                else
                {
                    /// play ==> option (khrog)
                    renderer.set_health_wolf();
                    renderer.option_screen = false;
                    simpleButton1.Visible  = false;
                    simpleButton2.Visible  = false;
                    simpleButton3.Visible  = false;
                    simpleButton4.Visible  = false;
                    simpleButton5.Visible  = false;
                    simpleButton6.Visible  = false;
                }
                renderer.about = false;
                label6.Visible = false;
                label7.Visible = false;
                label8.Visible = false;
            }
            label6.Text = "X: " + renderer.cam.GetCameraPosition().x;
            label7.Text = "Y: " + renderer.cam.GetCameraPosition().y;
            label8.Text = "Z: " + renderer.cam.GetCameraPosition().z;

            //label7.Text = "X: " + renderer.cam.mAngleX;
            //label8.Text = "Y: " + renderer.cam.mAngleY;
            walking = true;
        }