예제 #1
0
        /// <summary>
        /// Métudo Update
        /// Atualiza constantemente a posiçao do "boss" assim como a sua velocidade
        /// Verifica a quantidade de vida e caso seja igual ou inferior a zero desencadeia uma serie de explosões e em seguida destoi-se
        /// O delay entre as explosões e a dua destruição é controlado atravez de um timer.
        /// </summary>
        /// <param name="gameTime"></param>
        public override void Update(GameTime gameTime)
        {
            posY += Camera.velocidadegeral * 2.5f;
            //this.shootTime = 25f / Camera.velocidadegeral;

            base.position.Y = ((float)Math.Cos(posY) * 0.5f) + 0.1f;
            base.position.X = Camera.target.X + 1.7f;

            //Verificar vida
            if (this.Vida <= 0 && this.scene.bossKilled == false)
            {
                this.scene.bossKilled = true;

                this.scene.AddExplosao(new AnimatedSprite(cManager, "explosao", 9, 9, false, position, 0.9f));

                this.scene.AddExplosao(new AnimatedSprite(cManager, "explosao", 9, 9, false, new Vector2(position.X, position.Y + 0.6f), 0.78f, 1000f));

                this.scene.AddExplosao(new AnimatedSprite(cManager, "explosao", 9, 9, false, new Vector2(position.X, position.Y - 0.6f), 0.78f));

                this.scene.AddExplosao(new AnimatedSprite(cManager, "explosao", 9, 9, false, new Vector2(position.X + 0.4f, position.Y + 0.6f), 0.78f, 500f));

                this.scene.AddExplosao(new AnimatedSprite(cManager, "explosao", 9, 9, false, new Vector2(position.X + 0.4f, position.Y - 0.8f), 0.78f, 200f));

                this.scene.AddExplosao(new AnimatedSprite(cManager, "explosao", 9, 9, false, new Vector2(position.X + 0.6f, position.Y - 0.8f), 0.5f, 50f));
                this.scene.AddExplosao(new AnimatedSprite(cManager, "explosao", 9, 9, false, new Vector2(position.X + 0.6f, position.Y - 0.7f), 0.9f, 150f));
                this.scene.AddExplosao(new AnimatedSprite(cManager, "explosao", 9, 9, false, new Vector2(position.X + 0.6f, position.Y + 0.9f), 1f, 600f));
                this.scene.AddExplosao(new AnimatedSprite(cManager, "explosao", 9, 9, false, new Vector2(position.X + 0.6f, position.Y + 0.7f), 0.5f, 800f));
                som.playExplosao();
                Camera.addShake(50);
            }
            if (this.scene.bossKilled == true)
            {
                timeAfterKilled        += (float)gameTime.ElapsedGameTime.Milliseconds;
                this.scene.player.speed = 0.9f;
            }
            if (timeAfterKilled >= 1400f)
            {
                this.Destroy();
                this.scene.bossLevelClear = true;
            }


            animationTimer +=
                (float)gameTime.ElapsedGameTime.Milliseconds;
            if (animationTimer > animationInterval)
            {
                animationTimer = 0f;
                nextFrame();
            }

            if (contador >= shootTime && missil1Lancado == false && this.scene.bossKilled == false)
            {
                if (this.scene.player != null)
                {
                    scene.AddInimigo(WeaponsManager.addMissil("missil", TipoMissil.Teleguiado, -1, OrigemBala.inimigo, this.scene.player).Scl(0.15f).
                                     At(new Vector2(this.position.X - 1f, this.position.Y - 0.5f)));
                }


                scene.AddSprite(WeaponsManager.addBala("balainimigo", -1, OrigemBala.inimigo, DireccaoBala.EmFrente).Scl(0.09f).
                                At(new Vector2(position.X - 0.4f, position.Y)));
                missil1Lancado = true;
            }
            else if (contador >= shootTime * 2 && this.scene.bossKilled == false)
            {
                if (this.scene.player != null)
                {
                    scene.AddInimigo(WeaponsManager.addMissil("missil", TipoMissil.Teleguiado, -1, OrigemBala.inimigo, this.scene.player).Scl(0.15f).
                                     At(new Vector2(this.position.X - 1f, this.position.Y + 0.5f)));
                    missil1Lancado = false;
                }

                scene.AddSprite(WeaponsManager.addBala("balainimigo", -1, OrigemBala.inimigo, DireccaoBala.EmFrente).Scl(0.09f).
                                At(new Vector2(position.X - 0.4f, position.Y)));
                contador = 0;
            }

            contador  += gameTime.ElapsedGameTime.Milliseconds;
            contador2 += gameTime.ElapsedGameTime.Milliseconds;


            base.Update(gameTime);
        }
예제 #2
0
        /// <summary>
        /// Atualiza uma defesa
        /// </summary>
        /// <param name="gameTime">Instância de gameTime</param>
        public override void Update(GameTime gameTime)
        {
            switch (this.tipodefesa)
            {
            case TipoDefesa.Metrelhadora:
                contadordisparo = 0.009f / Camera.velocidadegeral;
                posBala         = this.position + direction;


                Vector2 futurepoint = Vector2.Zero;
                if (this.scene.player != null)
                {
                    Vector2 deltaP = this.scene.player.position - this.position;
                    Vector2 deltaV = this.scene.player.getVectorVelocity();
                    float   t      = AimAhead(deltaP, deltaV, Camera.velocidadegeral / 0.5f);

                    if (t > 0)
                    {
                        futurepoint = this.scene.player.position + t * (deltaV);
                    }
                }



                Vector2 tpos = this.position;
                float   a    = (float)futurepoint.Y - tpos.Y;
                float   l    = (float)futurepoint.X - tpos.X;
                rot = -(float)Math.Atan2(a, l);

                rot += (float)Math.PI / 2f;
                SetRotation(rot);

                shootTimeM += (float)gameTime.ElapsedGameTime.TotalSeconds;

                if (shootTimeM >= contadordisparo && futurepoint != Vector2.Zero)
                {
                    Vector2 pos = this.position
                                  + new Vector2((float)Math.Sin(rot) * size.Y / 2,
                                                (float)Math.Cos(rot) * size.Y / 2);



                    scene.AddSprite(WeaponsManager.addBala("baladefesas", 2, OrigemBala.defesa, DireccaoBala.EmFrente, this).Scl(0.03f).At(new Vector2(pos.X, pos.Y)));

                    shootTimeM = 0f;
                }
                break;

            case TipoDefesa.Laser:
                shootTimeL     += (float)gameTime.ElapsedGameTime.TotalSeconds;
                contadordisparo = 0.009f / Camera.velocidadegeral;

                this.rotation = 3.15f;
                if (scene.player != null && shootTimeL >= contadordisparo && scene.player.position.X <= this.position.X + 1.5f)
                {
                    scene.AddSprite(WeaponsManager.addBala("baladefesas", 1, OrigemBala.defesa, DireccaoBala.EmFrente, this)
                                    .Scl(0.03f).At(new Vector2(this.position.X, this.position.Y - 0.2f)));

                    if (shootTimeL >= contadordisparo + shootTimeLaser)
                    {
                        shootTimeL = 0f;
                    }
                }
                break;
            }

            base.Update(gameTime);
        }
예제 #3
0
        /// <summary>
        /// Atualiza o estado do NPC
        /// </summary>
        /// <param name="gameTime">Instância de gameTime</param>
        public override void Update(GameTime gameTime)
        {
            // variavel usada pelo coseno
            // Contradominio de cos(x)=[-1,1]
            posY += Camera.velocidadegeral * 1.5f;

            switch (tipoNave)
            {
            case TipoNave.Hunter:
                this.shootTime = 25f / Camera.velocidadegeral;
                break;

            case TipoNave.Interceptor:
                this.shootTime = 25f / Camera.velocidadegeral;
                break;

            case TipoNave.Bomber:
                this.shootTime = random.Next(50, 100) / Camera.velocidadegeral;
                break;

            //case TipoNave.Mothership:
            //    this.shootTime = 25f / Camera.velocidadegeral;
            //    break;
            default:
                this.Vida = 1;
                break;
            }

            switch (this.tipoNave)
            {
            case TipoNave.Hunter:
                base.position.X -= Camera.velocidadegeral;
                // algoritmo para criar o efeito de onda nos NPC'S
                // coseno(x)+posição do npc

                base.position.Y = (float)Math.Sin(posY);
                break;

            case TipoNave.Interceptor:
                base.position.X -= Camera.velocidadegeral;
                // algoritmo para criar o efeito de onda nos NPC'S
                // coseno(x)+posição do npc

                base.position.Y = (float)Math.Sin(posY);
                break;

            case TipoNave.Bomber:
                base.position.X -= Camera.velocidadegeral / 3;

                break;

            //case TipoNave.Mothership:
            //    base.position.Y = (float)Math.Cos(posY) + 0.1f;
            //    base.position.X = Camera.target.X + 1f;
            //    break;
            default:
                base.position.X -= Camera.velocidadegeral;
                break;
            }


            //Verificar vida
            if (this.Vida <= 0)
            {
                this.scene.AddExplosao(new AnimatedSprite(cManager, "explosao", 9, 9, false, position, 0.9f));
                som.playExplosao();
                Camera.addShake(100);
                this.Destroy();
            }

            if (contador >= shootTime)
            {
                if (this.tipoNave == TipoNave.Hunter /*|| this.tipoNave == TipoNave.Mothership*/ || this.tipoNave == TipoNave.Interceptor)
                {
                    //if (this.tipoNave == TipoNave.Mothership)
                    //{
                    //    //scene.AddSprite(new Bala(this.cManager, "balainimigo", 1, OrigemBala.boss, DireccaoBala.EmFrente).Scl(0.09f).
                    //      //  At(new Vector2(position.X - 0.4f, position.Y - 0.05f)));
                    //    scene.AddInimigo(WeaponsManager.addMissil("missil", TipoMissil.Teleguiado, -1, OrigemBala.inimigo, this.scene.player).Scl(0.15f).
                    //        At(new Vector2(this.position.X-1f,this.position.Y+0.5f)));
                    //    scene.AddInimigo(WeaponsManager.addMissil("missil", TipoMissil.Teleguiado, -1, OrigemBala.inimigo, this.scene.player).Scl(0.15f).
                    //        At(new Vector2(this.position.X-1f, this.position.Y - 0.5f)));
                    //    scene.AddSprite(WeaponsManager.addBala("balainimigo", -1, OrigemBala.inimigo, DireccaoBala.EmFrente).Scl(0.09f).
                    //        At(new Vector2(position.X - 0.4f, position.Y)));
                    //}
                    //else
                    //{
                    //Caças e Nave Mãe disparam balas
                    scene.AddSprite(WeaponsManager.addBala("balainimigo", -1, OrigemBala.inimigo, DireccaoBala.EmFrente).Scl(0.09f).
                                    At(new Vector2(position.X - 0.4f, position.Y - 0.05f)));
                    //}
                }
                else
                {
                    if (this.scene.player != null && this.scene.player.position.X < this.position.X)
                    {
                        //Bombardeiros disparam misseis teleguidados
                        scene.AddInimigo(WeaponsManager.addMissil("missil", TipoMissil.Teleguiado, -1, OrigemBala.inimigo, this.scene.player).Scl(0.15f).
                                         At(this.position));
                    }
                }
                contador = 0;
            }
            contador += gameTime.ElapsedGameTime.Milliseconds;

            //enimgos sao destruidos se passarem o limite esquerdo da camara
            if (this.position.X < (Camera.target.X - (Camera.worldWidth / 2)))
            {
                this.Destroy();
            }

            base.Update(gameTime);
        }
예제 #4
0
        /// <summary>
        /// Atualiza o estado do jogador
        /// </summary>
        /// <param name="gameTime">Instância de gametime</param>
        public override void Update(GameTime gameTime)
        {
            this.shootTime = 1.5f / Camera.velocidadegeral;
            this.speed     = Camera.velocidadegeral * 3;

            //Movimento da nave atraves do teclado

            //Guarda o estado do teclado
            currentKeyboardState = Keyboard.GetState();
            //Se pressionado esquerda
            if (currentKeyboardState.IsKeyDown(Keys.Left))
            {
                if (this.position.X - this.size.X / 2 > Camera.GetTarget().X - Camera.worldWidth / 2)
                {
                    this.position.X -= speed;
                }
            }
            //Se pressionado cima
            if (currentKeyboardState.IsKeyDown(Keys.Up))

            {
                if (this.position.Y + this.size.Y / 2 < Camera.GetTarget().Y + Camera.GetWorldHeight() / 2)
                {
                    this.position.Y += speed;
                }
            }
            //Se pressionado baixo
            if (currentKeyboardState.IsKeyDown(Keys.Down))
            {
                if (-this.position.Y + this.size.Y / 2 < Camera.GetTarget().Y + Camera.GetWorldHeight() / 2)
                {
                    this.position.Y -= speed;
                }
            }
            //Se pressioando direita
            if (currentKeyboardState.IsKeyDown(Keys.Right))
            {
                if (this.position.X + this.size.X / 2 < Camera.GetTarget().X + Camera.worldWidth / 2)
                {
                    this.position.X += speed;
                }
            }
            lastposition = this.position;
            if (currentKeyboardState.IsKeyDown(Keys.W))
            {
                Camera.velocidadegeral += 0.00005f;
            }
            if (currentKeyboardState.IsKeyDown(Keys.S))
            {
                if (Camera.velocidadegeral > 0f)
                {
                    Camera.velocidadegeral -= 0.00005f;
                }
                else
                {
                    Camera.velocidadegeral = 0f;
                }
            }
            if (currentKeyboardState.IsKeyDown(Keys.Space))
            {
                if (contador >= shootTime)
                {
                    som.playTiro();
                    switch (tipobala)
                    {
                    case TipoBala.Simples:
                        scene.AddSprite(WeaponsManager.addBala("balaplayer", 1, OrigemBala.player, DireccaoBala.EmFrente).Scl(0.09f).
                                        At(new Vector2(position.X + 0.4f, position.Y)));

                        break;

                    case TipoBala.Duplo:

                        scene.AddSprite(WeaponsManager.addBala("balaplayer", 1, OrigemBala.player, DireccaoBala.EmFrente).Scl(0.09f).
                                        At(new Vector2(position.X + 0.4f, position.Y + 0.05f)));
                        scene.AddSprite(WeaponsManager.addBala("balaplayer", 1, OrigemBala.player, DireccaoBala.EmFrente).Scl(0.09f).
                                        At(new Vector2(position.X + 0.4f, position.Y - 0.05f)));

                        if (contadorMisseis > 3000)
                        {
                            scene.AddSprite(WeaponsManager.addMissil("missilPlayer", TipoMissil.EmFrente, 1, OrigemBala.player).Scl(0.15f).
                                            At(new Vector2(position.X + 0.4f, position.Y)));
                            contadorMisseis = 0;
                        }


                        break;

                    case TipoBala.Triplo:
                        scene.AddSprite(WeaponsManager.addBala("balaplayer", 1, OrigemBala.player, DireccaoBala.Cima).Scl(0.09f).
                                        At(new Vector2(position.X + 0.4f, position.Y - 0.03f)));

                        //scene.AddSprite(new Bala(this.cManager, "balaplayer", 1, OrigemBala.player, DireccaoBala.EmFrente).Scl(0.09f).
                        //At(new Vector2(position.X + 0.4f, position.Y - 0.05f )));

                        scene.AddSprite(WeaponsManager.addBala("balaplayer", 1, OrigemBala.player, DireccaoBala.EmFrente).Scl(0.09f).
                                        At(new Vector2(position.X + 0.4f, position.Y)));

                        scene.AddSprite(WeaponsManager.addBala("balaplayer", 1, OrigemBala.player, DireccaoBala.Baixo).Scl(0.09f).
                                        At(new Vector2(position.X + 0.4f, position.Y + 0.03f)));



                        if (contadorMisseis > 3000)
                        {
                            List <Sprite> listaAlvos = this.scene.inimigos.FindAll(x => (x is NPC || x is Missil));
                            if (listaAlvos.Count > 0)
                            {
                                FlyingEntity alvo = (FlyingEntity)listaAlvos[Game1.random.Next(listaAlvos.Count)];
                                scene.AddSprite(WeaponsManager.addMissil("missilPlayer", TipoMissil.Teleguiado, 1, OrigemBala.player, alvo).Scl(0.15f).
                                                At(new Vector2(position.X + 0.4f, position.Y)));
                                contadorMisseis = 0;
                            }
                        }
                        break;

                    case TipoBala.Quadruplo:
                        scene.AddSprite(WeaponsManager.addBala("balaplayer", 1, OrigemBala.player, DireccaoBala.Cima).Scl(0.09f).
                                        At(new Vector2(position.X + 0.4f, position.Y - 0.03f)));

                        scene.AddSprite(WeaponsManager.addBala("balaplayer", 1, OrigemBala.player, DireccaoBala.EmFrente).Scl(0.09f).
                                        At(new Vector2(position.X + 0.4f, position.Y - 0.03f)));

                        scene.AddSprite(WeaponsManager.addBala("balaplayer", 1, OrigemBala.player, DireccaoBala.EmFrente).Scl(0.09f).
                                        At(new Vector2(position.X + 0.4f, position.Y + 0.03f)));

                        scene.AddSprite(WeaponsManager.addBala("balaplayer", 1, OrigemBala.player, DireccaoBala.Baixo).Scl(0.09f).
                                        At(new Vector2(position.X + 0.4f, position.Y + 0.03f)));



                        if (contadorMisseis > 3000)
                        {
                            List <Sprite> listaAlvos = this.scene.inimigos.FindAll(x => (x is NPC || x is Missil));
                            if (listaAlvos.Count > 0)
                            {
                                FlyingEntity alvo = (FlyingEntity)listaAlvos[Game1.random.Next(listaAlvos.Count)];
                                scene.AddSprite(WeaponsManager.addMissil("missilPlayer", TipoMissil.Teleguiado, 1, OrigemBala.player, alvo).Scl(0.15f).
                                                At(new Vector2(position.X + 0.4f, position.Y)));
                                contadorMisseis = 0;
                            }
                        }
                        break;

                    default:
                        break;
                    }
                    contador = 0;
                }
            }
            //colisao com power ups
            if (this.scene.Collides(this, out this.collided, out this.collisionPoint, this.scene.powerUps))
            {
                if (this.collided is PowerUp)
                {
                    PowerUp powerUp = (PowerUp)collided;
                    if (powerUp.tipoPowerUp == TipoPowerUp.Vida)
                    {
                        if (this.Vida < 5)
                        {
                            this.Vida++;
                        }
                    }
                    else
                    if (this.tipobala != TipoBala.Quadruplo)
                    {
                        this.tipobala++;
                    }
                }
                this.collided.Destroy();
            }

            //colisao con cenario
            if (this.scene.Collides(this, out this.collided, out this.collisionPoint, this.scene.sprites))
            {
                if (collided is Cenario || collided is Defence)
                {
                    this.Destroy();
                    this.scene.AddExplosao(new AnimatedSprite(cManager, "explosao", 9, 9, false, position + new Vector2(0.2f, 0f), 1.5f));
                    Camera.addShake(500);
                }
            }

            //colisao com inimigos
            if (this.scene.Collides(this, out this.collided, out this.collisionPoint, this.scene.inimigos))
            {
                if (collided is Missil)
                {
                    Missil missil = (Missil)collided;
                    missil.thrust.Destroy();
                }
                this.collided.Destroy();
                this.scene.AddExplosao(new AnimatedSprite(cManager, "explosao", 9, 9, false, position + new Vector2(0.2f, 0f), 1.5f));
                Camera.addShake(500);
                if (!(collided is Missil))
                {
                    this.Destroy();
                }
            }

            if (this.Vida <= 0)
            {
                this.scene.AddExplosao(new AnimatedSprite(cManager, "explosao", 9, 9, false, this.position, 1.5f));
                som.playExplosao();
                Camera.addShake(500);
                this.scene.playerKilled = true;
                this.scene.ClearUI();

                this.Destroy();
            }

            this.position.X += Camera.speed;


            contador        += gameTime.ElapsedGameTime.Milliseconds;
            contadorMisseis += gameTime.ElapsedGameTime.Milliseconds;


            base.Update(gameTime);
        }