Esempio n. 1
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
                Exit();

            if (Keyboard.GetState().IsKeyDown(Keys.P) && !kbAnterior.IsKeyDown(Keys.P))
            {
                tankPlayer1.desativarTanque();
                tankPlayer1 = listaTanques[random.Next(0, listaTanques.Count)];
                tankPlayer1.ativarTanque(listaTanques);
            }

            if (Keyboard.GetState().IsKeyDown(Keys.Y) && !kbAnterior.IsKeyDown(Keys.Y))
            {
                desenharTanques = !desenharTanques;
            }

            if (Keyboard.GetState().IsKeyDown(Keys.T) && !kbAnterior.IsKeyDown(Keys.T))
            {
                desenharTerreno = !desenharTerreno;
            }

            kbAnterior = Keyboard.GetState();

            efeitoTerrain.DirectionalLight0.Direction = new Vector3((float)Math.Cos(anguloLuz),
                                                        -(float)Math.Sin(anguloLuz), 0);
            efeitoWater.DirectionalLight0.Direction = new Vector3((float)Math.Cos(anguloLuz),
                                                        -(float)Math.Sin(anguloLuz), 0);
            anguloLuz += stepAnguloLuz;
            if (anguloLuz > MathHelper.ToRadians(245)) anguloLuz = MathHelper.ToRadians(-65);

            foreach (Tank tank in listaTanques)
            {
                tank.Update(gameTime, listaTanques, listaTanques.Find(x => x.isAtivo()), Content, random, listaPalmeiras);
            }

            Camera.Update(gameTime, GraphicsDevice, listaTanques.Find(x => x.isAtivo()));

            particulasChuva.Update(random, gameTime);
            SistemaParticulasExplosao.Update(random, gameTime);

            //Colisões entre balas e tanques
            CollisionDetector.CollisionBalaTank(listaTanques, BalaManager.getListaBalas(), random);
            //Colisões entre balas e terreno
            CollisionDetector.CollisionBalaTerrain(BalaManager.getListaBalas(), random);
            //Remover coisas mortas
            removeDeadStuff(gameTime);

            base.Update(gameTime);
        }