Beispiel #1
0
        public void UpdateAsteroid(Asteroid a, float elapsed, Nave jugador)
        {
            //Aqui se le asigna el movimiento a los asteroides

            a.boundingBox = new Rectangle((int)a.Position.X, (int)a.Position.Y, (int)(textura.Width * a.Escala), (int)(textura.Height * a.Escala));
            if (a.tePersigue)
            {
                if (a.Position.X > jugador.posicion.X)
                {
                    a.Position.X -= ((a.Position.X - jugador.posicion.X) * 0.001f);
                }
                if (a.Position.Y > jugador.posicion.Y)
                {
                    a.Position.Y -= (a.Position.Y - jugador.posicion.Y) * 0.001f;
                }
                if (a.Position.X < jugador.posicion.X)
                {
                    a.Position.X += (a.Position.X + jugador.posicion.X) * 0.001f;
                }
                if (a.Position.Y < jugador.posicion.Y)
                {
                    a.Position.Y += ((a.Position.Y + jugador.posicion.Y) * 0.001f);
                }
            }
            else
            {
                a.Position.Y += a.Velocityy * elapsed;
                a.Position.X += a.Velocityx * elapsed;
            }
        }
Beispiel #2
0
        public void Update(GameTime gt, Nave jugador)
        {
            score = jugador.score.ScoreJugador;
            KeyboardState kb = Keyboard.GetState();

            fps += gt.ElapsedGameTime.Milliseconds;

            if (mensaje)
            {
                duracionMensaje += gt.ElapsedGameTime.Milliseconds;
            }
            if (duracionMensaje >= 900)
            {
                duracionMensaje = 0;
                mensaje         = false;
            }
            if (fps > maxfps)
            {
                fps = 0;
                if (kb.IsKeyDown(Keys.Up) && y > -1)
                {
                    y--;
                }
                if (kb.IsKeyDown(Keys.Down) && y < 3)
                {
                    y++;
                }
                if (kb.IsKeyDown(Keys.Right) && x < 2)
                {
                    x++;
                }
                if (kb.IsKeyDown(Keys.Left) && x > 0)
                {
                    x--;
                }

                if (x >= 0 && x < 3 && y >= 0 && y < 3)
                {
                    if (kb.IsKeyDown(Keys.Enter) && jugador.score.ScoreJugador >= precios[x, y])
                    {
                        if (jugador.score.ScoreJugador < 0)
                        {
                            jugador.score.ScoreJugador = 0;
                        }

                        if (x == 0 && y == 0 && !jugador.SuperBalas1)
                        {
                            jugador.SuperBalas1         = true;
                            jugador.score.ScoreJugador -= precios[x, y];
                        }

                        else if (x == 1 && y == 0 && !jugador.SuperBalas2)
                        {
                            jugador.SuperBalas2         = true;
                            jugador.score.ScoreJugador -= precios[x, y];
                        }
                        else if (x == 2 && y == 0 && !jugador.SuperBalas3)
                        {
                            jugador.SuperBalas3         = true;
                            jugador.score.ScoreJugador -= precios[x, y];
                        }

                        else if (x == 0 && y == 1 && !jugador.SuperEscudo1)
                        {
                            jugador.SuperEscudo1        = true;
                            jugador.score.ScoreJugador -= precios[x, y];
                        }
                        else if (x == 1 && y == 1 && jugador.SuperEscudo2)
                        {
                            jugador.SuperEscudo2        = true;
                            jugador.score.ScoreJugador -= precios[x, y];
                        }
                        else if (x == 2 && y == 1 && !jugador.SuperEscudo3)
                        {
                            jugador.SuperEscudo3        = true;
                            jugador.score.ScoreJugador -= precios[x, y];
                        }
                        else if (x == 0 && y == 2 && !jugador.DirBalas1)
                        {
                            jugador.DirBalas1           = true;
                            jugador.score.ScoreJugador -= precios[x, y];
                        }
                        else if (x == 1 && y == 2 && !jugador.DirBalas2)
                        {
                            jugador.DirBalas2           = true;
                            jugador.score.ScoreJugador -= precios[x, y];
                        }
                        else if (x == 2 && y == 2 && !jugador.DirBalas3)
                        {
                            jugador.DirBalas3           = true;
                            jugador.score.ScoreJugador -= precios[x, y];
                        }

                        else
                        {
                            mensaje = true;
                        }
                    }
                }
                else if (y == 3)
                {
                    if (kb.IsKeyDown(Keys.Enter))
                    {
                        if (!jugador.bombaActiva && jugador.score.ScoreJugador >= 2500)
                        {
                            jugador.bombaActiva         = true;
                            jugador.score.ScoreJugador -= 2500;
                        }
                        else
                        {
                            mensaje = true;
                        }
                    }
                }
                else
                {
                    if (kb.IsKeyDown(Keys.Enter))
                    {
                        salir = true;
                    }
                }
            }
        }
Beispiel #3
0
 public void update(GameTime gameTime, Nave jugador)
 {
     RecLaser = new Rectangle(-30, 500, textLaser.Width, textLaser.Height);
 }
Beispiel #4
0
        public void Update(GameTime gameTime, Nave jugador)
        {
            laser.update(gameTime, jugador);

            if (once)
            {
                maxScore += jugador.score.Destruidos + jugador.score.Destruidos2 + jugador.score.Destruidos3 + jugador.score.Destruidos4;
                //no se volvera a hacer
                once = false;
            }
            if (jugador.score.Destruidos + jugador.score.Destruidos2 + jugador.score.Destruidos3 + jugador.score.Destruidos4 <= maxScore)
            {
                //Esto activa las explosiones cuando estan activas

                foreach (Explosion exe in ExplosionList)
                {
                    exe.Update(gameTime);
                }


                KeyboardState kb = Keyboard.GetState();
                if (kb.IsKeyDown(Keys.D) && jugador.bombaActiva)
                {
                    foreach (Asteroid aster in ListaAster)
                    {
                        ExplosionList.Add(new Explosion(texturaExplosion, new Vector2(aster.Position.X, aster.Position.Y), aster.Escala));
                        jugador.sn.explosion.Play();
                        aster.esVisible = false;
                    }
                    foreach (Balas balitas in listaBalas)
                    {
                        balitas.esVisible = false;
                    }
                    jugador.bombaActiva = false;
                }


                //Este timer se usa para generar los asteroides, cada X tiempo
                float elapsed = (float)gameTime.ElapsedGameTime.TotalSeconds;
                spawnTimer  += elapsed;
                spawnTimer2 += elapsed;
                spawnTimer3 += elapsed;
                spawnTimer4 += elapsed;



                float elapsed2 = (float)gameTime.ElapsedGameTime.TotalSeconds;
                timer -= elapsed2;
                if (timer <= 0)
                {
                    if (jugador.recNave.Intersects(laser.RecLaser) && laser.LaserVisible)
                    {
                        if (!laser.LaserVisible)
                        {
                            laser.LaserVisible = true;
                        }
                    }
                    //else
                    //  laser.LaserVisible = false;
                    //Timer expired, execute action
                    timer = TIMER;   //Reset Timer
                }



                if (spawnTimer >= spawnRate)
                {
                    do
                    {
                        posX = rand.Next(-100, 1300);
                    } while (posX > 0 && posX < 1200);

                    do
                    {
                        posY = rand.Next(-100, 820);
                    } while (posY > 0 && posY < 720);
                    Asteroid yolo = new Asteroid(rand.Next(-60, 60), rand.Next(-40, 40), new Vector2(posX, posY),
                                                 rand.Next(30, 200));
                    //yolo.tePersigue = true;

                    ListaAster.Add(yolo);

                    spawnTimer = 0;
                }

                if (spawnTimer2 >= spawnRate2)
                {
                    do
                    {
                        posX = rand.Next(-100, 1300);
                    } while (posX > 0 && posX < 1200);

                    do
                    {
                        posY = rand.Next(-100, 820);
                    } while (posY > 0 && posY < 720);
                    Asteroid yolo = new Asteroid(rand.Next(-60, 60), rand.Next(-40, 40), new Vector2(posX, posY),
                                                 rand.Next(30, 200));
                    yolo.teDispara = true;
                    yolo.Escala    = 1;
                    ListaAster.Add(yolo);

                    spawnTimer2 = 0;
                }



                if (spawnTimer3 >= spawnRate3)
                {
                    do
                    {
                        posX = rand.Next(-100, 1300);
                    } while (posX > 0 && posX < 1200);

                    do
                    {
                        posY = rand.Next(-100, 820);
                    } while (posY > 0 && posY < 720);
                    Asteroid yolo = new Asteroid(rand.Next(-60, 60), rand.Next(-40, 40), new Vector2(posX, posY),
                                                 rand.Next(30, 200));
                    yolo.esFuerte = true;
                    yolo.vida     = 21;
                    yolo.Escala   = 1;
                    ListaAster.Add(yolo);

                    spawnTimer3 = 0;
                }



                if (spawnTimer4 >= spawnRate4)
                {
                    do
                    {
                        posX = rand.Next(-100, 1300);
                    } while (posX > 0 && posX < 1200);

                    do
                    {
                        posY = rand.Next(-100, 820);
                    } while (posY > 0 && posY < 720);
                    Asteroid yolo = new Asteroid(rand.Next(-60, 60), rand.Next(-40, 40), new Vector2(posX, posY),
                                                 rand.Next(30, 200));
                    yolo.tePersigue = true;
                    yolo.Escala     = 1;
                    ListaAster.Add(yolo);

                    spawnTimer4 = 0;
                }



                foreach (Balas listaBala in listaBalas)
                {
                    if (listaBala.boundingBox.Intersects(jugador.EscudoRect[0]) && jugador.SuperEscudo1)
                    {
                        jugador.SuperEscudo1 = false;
                        listaBala.esVisible  = false;
                        continue;
                    }

                    if (listaBala.boundingBox.Intersects(jugador.EscudoRect[1]) && jugador.SuperEscudo2)
                    {
                        listaBala.esVisible  = false;
                        jugador.SuperEscudo2 = false;
                        continue;
                    }
                    if (listaBala.boundingBox.Intersects(jugador.EscudoRect[2]) && jugador.SuperEscudo3)
                    {
                        listaBala.esVisible  = false;
                        jugador.SuperEscudo3 = false;
                        continue;
                    }

                    if (listaBala.boundingBox.Intersects(jugador.recNave))
                    {
                        Murio = true;
                    }
                }


                for (int i = 0; i < ListaAster.Count; i++)//Actualizar cada asteroide
                {
                    if (ListaAster[i].teDispara && ListaAster[i].Position.X > 0 && ListaAster[i].Position.Y > 0 && ListaAster[i].Position.X < 1200 && ListaAster[i].Position.Y < 720)
                    {
                        float rad;
                        rad = (float)Math.Atan(
                            (jugador.posicion.Y - ListaAster[i].Position.Y)
                            / (jugador.posicion.X - ListaAster[i].Position.X));
                        //rad *= ((2f*3.14159265359f)/360);
                        Shoot(rad, gameTime, ListaAster[i]);
                    }

                    UpdateBullets(gameTime);
                    if (jugador.SuperEscudo1)
                    {
                        if (jugador.EscudoRect[0].Intersects(ListaAster[i].boundingBox))
                        {
                            ListaAster[i].esVisible = false;
                            jugador.SuperEscudo1    = false;
                            ExplosionList.Add(new Explosion(texturaExplosion, new Vector2(ListaAster[i].Position.X, ListaAster[i].Position.Y), ListaAster[i].Escala));
                            jugador.sn.explosion.Play();
                        }
                    }
                    if (jugador.SuperEscudo2)
                    {
                        if (jugador.EscudoRect[1].Intersects(ListaAster[i].boundingBox))
                        {
                            ListaAster[i].esVisible = false;
                            jugador.SuperEscudo2    = false;
                            ExplosionList.Add(new Explosion(texturaExplosion, new Vector2(ListaAster[i].Position.X, ListaAster[i].Position.Y), ListaAster[i].Escala));
                            jugador.sn.explosion.Play();
                        }
                    }
                    if (jugador.SuperEscudo3)
                    {
                        if (jugador.EscudoRect[2].Intersects(ListaAster[i].boundingBox))
                        {
                            ListaAster[i].esVisible = false;
                            jugador.SuperEscudo3    = false;
                            ExplosionList.Add(new Explosion(texturaExplosion, new Vector2(ListaAster[i].Position.X, ListaAster[i].Position.Y), ListaAster[i].Escala));
                            jugador.sn.explosion.Play();
                        }
                    }

                    if (jugador.recNave.Intersects(
                            new Rectangle(ListaAster[i].boundingBox.X + 5, ListaAster[i].boundingBox.Y + 5, ListaAster[i].boundingBox.Width - 5, ListaAster[i].boundingBox.Height - 5)))
                    {
                        Murio = true;
                    }

                    UpdateAsteroid(ListaAster[i], elapsed, jugador);
                    foreach (Balas balitas in jugador.listaBalas)
                    {
                        if (ListaAster[i].boundingBox.Intersects(balitas.boundingBox) && ListaAster[i].esFuerte)
                        {
                            if (ListaAster[i].vida <= 0)
                            {
                                ExplosionList.Add(new Explosion(texturaExplosion, new Vector2(ListaAster[i].Position.X, ListaAster[i].Position.Y), 5));
                                ListaAster[i].esVisible     = false;
                                jugador.score.Destruidos4  += 1;
                                jugador.score.ScoreJugador += 50;
                            }
                            else
                            {
                                ListaAster[i].vida--;
                                balitas.esVisible = false;
                                ExplosionList.Add(new Explosion(texturaExplosion, new Vector2(ListaAster[i].Position.X, ListaAster[i].Position.Y), ListaAster[i].Escala));
                                jugador.sn.explosion.Play();
                            }
                        }
                    }

                    for (int j = 0; j < jugador.listaBalas.Count; j++)
                    {
                        if (ListaAster[i].boundingBox.Intersects(jugador.listaBalas[j].boundingBox) && ListaAster[i].Escala >= 1 && jugador.listaBalas[j].esVisible && ListaAster[i].esVisible && !ListaAster[i].esFuerte)
                        {
                            if (jugador.listaBalas[j].boundingBox.X > 0 && jugador.listaBalas[j].boundingBox.Y > 0 && jugador.listaBalas[j].boundingBox.Y < 720 && jugador.listaBalas[j].boundingBox.X < 1200)
                            {
                                jugador.score.ScoreJugador += 100;

                                if (!ListaAster[i].esFuerte && !ListaAster[i].teDispara && !ListaAster[i].tePersigue)
                                {
                                    jugador.score.Destruidos3  += 1;
                                    jugador.score.ScoreJugador += 10;
                                }
                                if (ListaAster[i].tePersigue)
                                {
                                    jugador.score.Destruidos2  += 1;
                                    jugador.score.ScoreJugador += 25;
                                }
                                if (ListaAster[i].teDispara)
                                {
                                    jugador.score.Destruidos   += 1;
                                    jugador.score.ScoreJugador += 100;
                                }
                            }
                            ExplosionList.Add(new Explosion(texturaExplosion, new Vector2(ListaAster[i].Position.X, ListaAster[i].Position.Y), ListaAster[i].Escala));
                            Asteroid asterito = new Asteroid(rand.Next(-60, 60), rand.Next(-40, 40),
                                                             new Vector2(ListaAster[i].Position.X + 2,
                                                                         ListaAster[i].Position.Y + 2),
                                                             (float)rand.Next(30, 100));
                            if (ListaAster[i].tePersigue)
                            {
                                asterito.tePersigue = true;
                            }
                            ListaAster.Add(asterito);
                            Asteroid asterito2 = new Asteroid(rand.Next(-60, 60), rand.Next(-40, 40),
                                                              new Vector2(ListaAster[i].Position.X + 2,
                                                                          ListaAster[i].Position.Y + 2),
                                                              (float)rand.Next(30, 100));
                            if (ListaAster[i].tePersigue)
                            {
                                asterito2.tePersigue = true;
                            }
                            ListaAster.Add(asterito2);
                            ListaAster.RemoveAt(i);
                            jugador.listaBalas[j].esVisible = false;
                            jugador.sn.explosion.Play();
                        }
                        if (ListaAster[i].boundingBox.Intersects(jugador.listaBalas[j].boundingBox) && ListaAster[i].Escala < 1 && jugador.listaBalas[j].esVisible && ListaAster[i].esVisible)
                        {
                            if (jugador.listaBalas[j].boundingBox.X > 0 && jugador.listaBalas[j].boundingBox.Y > 0 && jugador.listaBalas[j].boundingBox.Y < 720 && jugador.listaBalas[j].boundingBox.X < 1200)
                            {
                                jugador.score.ScoreJugador += 10;

                                if (!ListaAster[i].esFuerte && !ListaAster[i].teDispara && !ListaAster[i].tePersigue)
                                {
                                    jugador.score.Destruidos3  += 1;
                                    jugador.score.ScoreJugador += 5;
                                }
                                if (ListaAster[i].tePersigue)
                                {
                                    jugador.score.Destruidos2  += 1;
                                    jugador.score.ScoreJugador += 20;
                                }
                                if (ListaAster[i].teDispara)
                                {
                                    jugador.score.Destruidos   += 1;
                                    jugador.score.ScoreJugador += 50;
                                }
                            }
                            ExplosionList.Add(new Explosion(texturaExplosion, new Vector2(ListaAster[i].Position.X, ListaAster[i].Position.Y), ListaAster[i].Escala));
                            ListaAster[i].esVisible         = false;
                            jugador.listaBalas[j].esVisible = false;
                            jugador.sn.explosion.Play();
                        }
                    }
                    //al los asteroides colisionar, se hacen invisibles y al hacerse invisibles se eliminan
                    //de la lista, esto ayuda a la eficiencia del juego
                    if (!ListaAster[i].esVisible)
                    {
                        ListaAster.RemoveAt(i);
                    }
                }
            }
            else
            {
                if (!level_up)
                {
                    level_up = true;
                    jugador.score.Licencia++;
                }
                level_passed = true;
                once         = true;
            }
        }