Example #1
0
        protected override void Update(GameTime gameTime)
        {
            //Gira o meteoro ao redor de si
            //girarMeteoro += 0.04f;

            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                this.Exit();

            vidaNave = new BarraEnergia(naveMae.vidaNave, Content.Load<Texture2D>("Sprites\\HealthBar2"),
                new Vector2(5, 400));

            Rectangle Naveretangulo =
               new Rectangle((int)naveMae.posicaoNave.X, (int)naveMae.posicaoNave.Y,
               naveMae.texturaNave.Width, naveMae.texturaNave.Height);

            // Update each block
            naveMae.hitNave = false;

            #region Gerador de posicoes meteoros

            time += gameTime.ElapsedGameTime.TotalSeconds;

            if (random.NextDouble() < BlockSpawnProbability)
            {
                float x = (float)random.NextDouble() *
                    (Window.ClientBounds.Width - meteorTexture.Width);

                if (time > timeProbability)
                {
                    meteorPositions.Add(new Vector2(x, -meteorTexture.Height));

                    time = 0;
                }
            }
            #endregion

            KeyboardState keyboradState = Keyboard.GetState();

            GameTime += gameTime.ElapsedGameTime.TotalSeconds;

            if (keyboradState.IsKeyDown(Keys.Escape))
            {
                this.Exit();
            }

            if (mudarDificuldade % 20 == 0 && mudarDificuldade > 0)
            {
                this.timeProbability -= 0.2f;
                mudarDificuldade = 0;
                nivel = 2;
            }

            /*if (Score > 20)
            {
                this.timeProbability = 0.8f;
                nivel = 2;
            }

            if (Score > 40)
            {
                this.timeProbability = 0.6f;
                nivel = 2;
            }

            if (Score > 60)
            {
                this.timeProbability = 0.4f;
                nivel = 2;
            }

            if (Score > 80)
            {
                this.timeProbability = 0.2f;
                nivel = 2;
            }*/

            #region MovimentoFundo
            if (fundopos.Y >= tamanhoTela.Y)
                fundopos.Y = 0;

            fundopos.Y += velocidadeFundo;

            #endregion

            if (naveMae.vidaNave <= 0)
                this.Exit();

            #region Inputs

            if (keyboradState.IsKeyDown(Keys.Left))
            {
                if (nivel == 2)
                    shipCannon2.rotation = shipCannon.rotation;

                shipCannon.rotation -= 0.05f;
            }

            if (keyboradState.IsKeyDown(Keys.Right))
            {
                if (nivel == 2)
                    shipCannon2.rotation = shipCannon.rotation;

                shipCannon.rotation += 0.05f;
            }

            shipCannon.rotation = MathHelper.Clamp(shipCannon.rotation, -MathHelper.PiOver2 + 0.3f, MathHelper.PiOver2 - 0.3f);

            if (keyboradState.IsKeyDown(Keys.Space) && previousKeyboradState.IsKeyUp(Keys.Space))
            {
                FireCannonMissiles();
            }
            previousKeyboradState = keyboradState;

            #endregion

            // Chamando a funcao que atualiza os misseis
            UpdadeCannonMissiles();

            // Chamando a funcao que atualiza os meteoros
            Updatmeteor();

            // Chamando o update da nave mae
            naveMae.Update(gameTime);

            elementoBen.Update2(gameTime);

            MouseState ms = Mouse.GetState();
            // Check if mouse left button was presed
            if (ms.LeftButton == ButtonState.Pressed)
            {
                // Add new particle effect to mouse coordinates
                myEffect.Trigger(new Vector2(ms.X, ms.Y));
            }
            // "Deltatime" ie, time since last update call
            float SecondsPassed = (float)gameTime.ElapsedGameTime.TotalSeconds;
            myEffect.Update(SecondsPassed);

            base.Update(gameTime);
        }
Example #2
0
        protected override void Update(GameTime gameTime)
        {
            vidaNave = new BarraEnergia(naveMae.vidaNave, Content.Load<Texture2D>("Sprites\\HealthBar2"),
                new Vector2(255, 785));

            Rectangle Naveretangulo =
               new Rectangle((int)naveMae.posicaoNave.X, (int)naveMae.posicaoNave.Y,
               naveMae.texturaNave.Width, naveMae.texturaNave.Height);

            // Update each block
            naveMae.hitNave = false;

            KeyboardState keyboradState = Keyboard.GetState();

            GameTime += gameTime.ElapsedGameTime.TotalSeconds;

            if (keyboradState.IsKeyDown(Keys.W))
                Camera.Zoom += 0.1f;

            if (keyboradState.IsKeyDown(Keys.S))
                Camera.Zoom -= 0.1f;

            if (keyboradState.IsKeyDown(Keys.D))
                Camera.Move(new Vector2(10, 0));

            if (keyboradState.IsKeyDown(Keys.A))
                Camera.Move(new Vector2(-10, 0));

            if (keyboradState.IsKeyDown(Keys.Escape))
            {
                this.Exit();
            }

            if (Score == 20 && mudarNivel == true)
            {
                meteoros.timeProbability -= 0.05f;
                nivel = 2;
                mudarNivel = false;
            }

            if (keyboradState.IsKeyDown(Keys.Space) && previousKeyboradState.IsKeyUp(Keys.Space))
            {
                FireCannonMissiles();
            }
            previousKeyboradState = keyboradState;

            #region MovimentoFundo
            if (fundopos.Y >= tamanhoTela.Y)
                fundopos.Y = 0;

            fundopos.Y += velocidadeFundo;

            #endregion

            if (naveMae.vidaNave <= 0)
            {
                this.Exit();
            }

            if (nivel >= 2)
            {
                shipCannon2.Update();
                shipCannon2.rotation = shipCannon.rotation;
            }

            shipCannon.Update();

            // Chamando a funcao que atualiza os misseis
            UpdadeCannonMissiles();

            // Chamando a funcao que atualiza os meteoros
            meteoros.Updatmeteor(gameTime);

            // Chamando o update da nave mae
            naveMae.Update(gameTime);

            //if (NaveFilho_1.Rect.Intersects(NaveFilho_2.Rect))
            //{
            //    NaveFilho_1.Velocidade *= -1;
            //    NaveFilho_2.Velocidade *= -1;

            //}

            NaveFilho_1.Update(gameTime);

            NaveFilho_2.Update(gameTime);

            elementoBen.Update2(gameTime);

            MouseState ms = Mouse.GetState();
            // Check if mouse left button was presed
            if (ms.LeftButton == ButtonState.Pressed)
            {
                // Add new particle effect to mouse coordinates
                myEffect.Trigger(new Vector2(ms.X, ms.Y));
            }
            // "Deltatime" ie, time since last update call
            float SecondsPassed = (float)gameTime.ElapsedGameTime.TotalSeconds;
            myEffect.Update(SecondsPassed);

            base.Update(gameTime);
        }