예제 #1
0
 private void init()
 {
     d_lis = new disps();
     scroll = Content.Load<Texture2D>("graphics/sc" + nivel);
     naveP = new Prota(g_nave, g_disp);
     naveP.set_pos(-150, 0);
     scrollP = new Vector2(0);
     ind = 0;
     objeto=null;
     contad = 0;
     efecto = -1;
     salvado = false;
     ener = 100;
     record = 0;
     max_record = EO.load(StorageContainer.TitleLocation + "/Content/datos/datos.txt");
     View = Matrix.CreateLookAt(cameraPosition, Vector3.Zero, Vector3.Down);
     for (int z = 0; z < totalEnem; z++)
         enemigos[z] = null;
 }
예제 #2
0
        protected override void Update(GameTime gameTime)
        {
            ltime=gameTime.TotalRealTime.Seconds;
            //            int cont = 0;
            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || ext)
                this.Exit();

            keyboardState = Keyboard.GetState();
            if (keyboardState.IsKeyDown(Keys.Escape))
            {
                if (pantalla == -1)
                {
                    cameraPosition.Z = -900;
                    View = Matrix.CreateLookAt(cameraPosition, Vector3.Zero, Vector3.Down);
                }
                pantalla = 0;
            }

            if (keyboardState.IsKeyDown(Keys.P) && (pantalla==3 || pantalla==4))
            {
                if (!pres)
                    if (pantalla == 3)
                        pantalla = 4;
                    else
                        pantalla = 3;
                pres = true;
            }
            else
                pres = false;
            switch (pantalla)
            {
                case -2:    //inicializa todo
                    time = lastTime();
                    pantalla = -1;
                    cameraPosition.Z = -450;
                    break;
                case -1:    //anima introducción
                    if (++contad<70)
                    {
                        cameraPosition.Z += 4;
                        logo.mueve(0, contad/2.001f);
                        logo.rotar(cameraPosition.Z / 27.5f, 0, 0);
                        logo.tamanio(contad / 35f);
                        View = Matrix.CreateLookAt(cameraPosition, Vector3.Zero, Vector3.Down);
                    }
                    if (contad>120)
                    {
                        cameraPosition.Z = -900;
                        View = Matrix.CreateLookAt(cameraPosition, Vector3.Zero, Vector3.Down);
                        contad = 0;
                        pantalla = 0;
                    }
                    break;
                case 2:

                    if (lastTime() - time > 3)
                    {
                        pantalla = 3;
                    }

                    break;
                case 3:
                    #region juego
                    if (efecto != -1)
                    {
                        switch (efecto)
                        {
                            case 1:
                                contad = 500;
                                efecto = -1;
                                break;
                            case 3:
                                for (int z = 0; z < totalEnem; z++)
                                    if (enemigos[z] != null)
                                    {
                                        animaciones[z] = new anim(g_explo, 21, enemigos[z].get_pos());
                                        record += 5;
                                        enemigos[z] = null;
                                    }
                                ind = 0;
                                efecto = -1;
                                break;
                        }

                    }
                    if (contad == 10)
                    {
                        View = Matrix.CreateLookAt(cameraPosition, Vector3.Zero, Vector3.Down);
                    }
                    if (contad > 0)
                        contad--;

                    //si el prota esta vivo, animar todo
                    if (ener > 0)
                    {
                        naveP.update(keyboardState);
                        if (rnd.Next(500) > 290)
                            for (int z = 0; z < totalEnem && ind < (nivel * 2 + 5); z++)
                            {
                                if (enemigos[z] == null)
                                {
                                    switch (rnd.Next(5))
                                    {
                                        case 0:
                                            enemigos[z] = new NaveBsl(g_naanch, g_disp);
                                            break;
                                        case 1:
                                            enemigos[z] = new NaveC(g_nab, g_disp);
                                            break;
                                        case 2:
                                            enemigos[z] = new NaveSC(g_npics, g_disp);
                                            break;
                                        case 3:
                                            enemigos[z] = new misil(g_enems[1], g_disp);
                                            break;
                                        case 4:
                                            enemigos[z] = new bomba(g_enems[2], g_disp);
                                            break;
                                    }

                                    ind++;
                                    break;
                                }
                            }

                        for (int z = 0; z < totalEnem; z++)
                            if (enemigos[z] != null)
                                if (enemigos[z].muerto)
                                {
                                    if (enemigos[z].get_pos().X > -440)
                                    {
                                        animaciones[z] = new anim(g_explo, 21, enemigos[z].get_pos());
                                        disps aux2 = d_lis;
                                        while (aux2.sig != null)
                                        {
                                            aux2 = aux2.sig;
                                        }
                                        aux2.sig = enemigos[z].lista.sig;
                                        if (aux2.sig != null)
                                            (aux2.sig).ant = aux2;
                                    }
                                    enemigos[z] = null;

                                    ind--;
                                }
                                else
                                {
                                    enemigos[z].update();
                                    disps aux2 = enemigos[z].lista.sig;
                                    while (aux2 != null)
                                    {
                                        if (aux2.elem.muerto)
                                        {
                                            disps auxA = aux2.ant;
                                            auxA.sig = aux2.sig;
                                            auxA = aux2.sig;
                                            if (auxA != null)
                                                auxA.ant = aux2.ant;
                                        }
                                        else
                                            aux2.elem.update();
                                        aux2 = aux2.sig;

                                    }
                                }

                        disps aux = naveP.lista.sig;
                        while (aux != null)
                        {
                            if (aux.elem.muerto)
                            {
                                disps auxA = aux.ant;
                                auxA.sig = aux.sig;
                                auxA = aux.sig;
                                if (auxA != null)
                                    auxA.ant = aux.ant;
                            }
                            else
                                aux.elem.update();
                            aux = aux.sig;

                        }

                        disps aux3 = d_lis.sig;

                        while (aux3 != null)
                        {
                            if (aux3.elem.muerto)
                            {
                                //   aux3.elem = null;
                                disps auxA = aux3.ant;
                                auxA.sig = aux3.sig;
                                auxA = aux3.sig;
                                if (auxA != null)
                                    auxA.ant = aux3.ant;
                            }
                            else
                                aux3.elem.update();
                            aux3 = aux3.sig;
                        }
                        if (objeto == null)
                        {
                            if (rnd.Next(nivel * 50 + 10) == nivel)
                                objeto = new item(rnd.Next(4));
                        }
                        else
                            if (objeto.muerto)
                                objeto = null;
                            else
                                objeto.update();
                    }
                    else
                    //si no esta vivo el prota
                    {
                        if (!salvado && record > max_record)
                        {
                            EO.save(StorageContainer.TitleLocation + "/Content/datos/datos.txt", record);
                            salvado = true;
                        }
                    }
                    #endregion
                    break;
                case 0:
                    naveP.Selec(keyboardState);
                    if (pantalla == 2)
                    {
                        init();
                        time = lastTime();
                    }
                    else
                    {
                        View = Matrix.CreateLookAt(cameraPosition, Vector3.Zero, Vector3.Down);
                    }
                    break;
                case 1:
                    naveP.opc(keyboardState);
                    if (pantalla==0)
                    {
                        musicCategory.SetVolume(musicVolume);
                        sonidos.PlayCue("disparo");
                        MediaPlayer.Volume = fondoVolume;
                    }
                    break;

            }
            audio.Update();
            base.Update(gameTime);
        }