Ejemplo n.º 1
0
        void introduccion_Pressed(GUIButton btn)
        {
            GUI.Controls.GUIDialog guiIntroduccion = new DialogoIntroduccion();

            Father.AddChildWindow(
                guiIntroduccion,
                new Point(
                    (Father.Size.Width - guiIntroduccion.Size.Width) / 2,
                    (Father.Size.Height - guiIntroduccion.Size.Height) / 2));

            Father.Focus = guiIntroduccion;
        }
Ejemplo n.º 2
0
        public void Ejecutar()
        {
            Size resolucion       = Properties.Settings.Default.Resolucion;
            int  profunidadBits   = Properties.Settings.Default.ProfundidadBits;
            bool pantallaCompleta = Properties.Settings.Default.PantallaCompleta;

            if (GraphicEngine.Instance.Inicializar(
                    "Espacio Infinito",
                    resolucion.Width, resolucion.Height,
                    profunidadBits,
                    pantallaCompleta))
            {
                Inicializar();

                InicializarJoystick();

                InicializarGalaxia(true);

                DialogoIntroduccion guiDialogoInfo = new DialogoIntroduccion();

                guiEngine.Root.AddChildWindow(
                    guiDialogoInfo,
                    new Point(
                        (guiEngine.Root.Size.Width - guiDialogoInfo.Size.Width) / 2,
                        (guiEngine.Root.Size.Height - guiDialogoInfo.Size.Height) / 2));

                guiEngine.Root.Focus = guiDialogoInfo;

                Sdl.SDL_Event evt;

                Sdl.SDL_EnableKeyRepeat(Sdl.SDL_DEFAULT_REPEAT_INTERVAL, Sdl.SDL_DEFAULT_REPEAT_DELAY);

                while (!salir)
                {
                    if (reiniciar)
                    {
                        InicializarGalaxia(false);

                        reiniciar = false;
                    }

                    //Primero consumo todos los eventos pendientes en la cola de eventos de SDL
                    Sdl.SDL_PollEvent(out evt);

                    do
                    {
                        //Determino si pasarle los eventos a la GUI o al GameEngine

                        bool hayDialogosEnGUI = false;

                        foreach (GUI.GUIWindow wnd in guiEngine.Root.Childs)
                        {
                            if (wnd is GUI.Controls.GUIDialog)
                            {
                                hayDialogosEnGUI = true;
                                break;
                            }
                        }

                        if (hayDialogosEnGUI)
                        {
                            pasarTeclasAGUI = true;
                            if (!enDemo)
                            {
                                Pausa = true;
                            }
                            else
                            {
                                Pausa = false;
                            }
                        }
                        else
                        {
                            pasarTeclasAGUI = false;
                            Pausa           = false;
                        }

                        //Despacho los eventos
                        switch (evt.type)
                        {
                        case Sdl.SDL_QUIT:
                            salir = true;
                            break;

                        case Sdl.SDL_KEYDOWN:
                        case Sdl.SDL_KEYUP:
                            ProcesarEventoKey(evt.key.keysym.sym, evt.key.state == Sdl.SDL_PRESSED);
                            break;

                        case Sdl.SDL_JOYBUTTONDOWN:
                        case Sdl.SDL_JOYBUTTONUP:
                            if (!pasarTeclasAGUI)
                            {
                                if (evt.jbutton.button == 0)
                                {
                                    ProcesarEventoKey(Sdl.SDLK_SPACE, evt.jbutton.state == Sdl.SDL_PRESSED);
                                }
                                else if (evt.jbutton.button == 1)
                                {
                                    ProcesarEventoKey(Sdl.SDLK_ESCAPE, evt.jbutton.state == Sdl.SDL_PRESSED);
                                }
                            }
                            else
                            {
                                if (evt.jbutton.button == 0)
                                {
                                    ProcesarEventoKey(Sdl.SDLK_RETURN, evt.jbutton.state == Sdl.SDL_PRESSED);
                                }
                                else if (evt.jbutton.button == 1)
                                {
                                    ProcesarEventoKey(Sdl.SDLK_ESCAPE, evt.jbutton.state == Sdl.SDL_PRESSED);
                                }
                            }
                            break;

                        case Sdl.SDL_JOYAXISMOTION:
                            if (evt.jaxis.axis == 0)
                            {
                                //Movimiento en X

                                if (evt.jaxis.val > ToleranciaJoytstick)
                                {
                                    ProcesarEventoKey(Sdl.SDLK_LEFT, false);
                                    ProcesarEventoKey(Sdl.SDLK_RIGHT, true);
                                }
                                else if (evt.jaxis.val < -ToleranciaJoytstick)
                                {
                                    ProcesarEventoKey(Sdl.SDLK_LEFT, true);
                                    ProcesarEventoKey(Sdl.SDLK_RIGHT, false);
                                }
                                else
                                {
                                    ProcesarEventoKey(Sdl.SDLK_LEFT, false);
                                    ProcesarEventoKey(Sdl.SDLK_RIGHT, false);
                                }
                            }
                            else if (evt.jaxis.axis == 1)
                            {
                                //Movimiento en Y

                                if (evt.jaxis.val > ToleranciaJoytstick)
                                {
                                    ProcesarEventoKey(Sdl.SDLK_DOWN, true);
                                    ProcesarEventoKey(Sdl.SDLK_UP, false);
                                }
                                else if (evt.jaxis.val < -ToleranciaJoytstick)
                                {
                                    ProcesarEventoKey(Sdl.SDLK_DOWN, false);
                                    ProcesarEventoKey(Sdl.SDLK_UP, true);
                                }
                                else
                                {
                                    ProcesarEventoKey(Sdl.SDLK_DOWN, false);
                                    ProcesarEventoKey(Sdl.SDLK_UP, false);
                                }
                            }

                            break;
                        }
                    } while (Sdl.SDL_PollEvent(out evt) == 1);

                    //Ahora realizo el proceso del Game (Dibujar, etc..)
                    Procesar();
                }

                GraphicEngine.Instance.Finalizar();
            }
            else
            {
                Properties.Settings.Default.Reset();
                Properties.Settings.Default.Save();
                MessageBox.Show("No se pudo iniciar el modo gráfico.\nLa configuración fue reseteada, pruebe iniciar el juego nuevamente", "Fallo al iniciar el modo gráfico", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }