Exemple #1
0
        public void Update(GameTime gameTime, Tank playerTank, List <Tank> listTanksInimigos)
        {
            if (!tankDestroyed)
            {
                findNormal();
                boundingSphere.Center = this.position;

                if (playerControl)
                {
                    HandleTankInput(0.02f, gameTime);
                    UpdateTankRotation();
                    //sistemaParticulas.Update(gameTime, posicaoSistemaParticulas());
                }
                else
                {
                    IAControl(playerTank.position, listTanksInimigos);
                }


                if (bala != null)
                {
                    bala.Update(gameTime, this);
                }
            }

            //particulas

            sistemaParticulasTraseira.Update(gameTime, position, Vector3.Cross(newNormal, newRigth), this);
        }
Exemple #2
0
        /// </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 (CurrentGameState == GameState.MainMenu)
            {
                if (Keyboard.GetState().IsKeyDown(Keys.Enter))
                {
                    CurrentGameState = GameState.PlayingLvl1;
                }
            }

            else if (CurrentGameState == GameState.PlayingLvl1)
            {
                #region update_lvl1
                _hero.Update(gameTime);
                fire.Update(gameTime);
                foreach (MovingTiles tile in movingTiles)
                {
                    tile.Update(gameTime);
                }

                foreach (Enemy enemy in _Enemys)
                {
                    enemy.Update(gameTime);
                }

                foreach (coin coin in coins)
                {
                    coin.Update(gameTime);
                }

                if (Keyboard.GetState().IsKeyDown(Keys.Space) && pastkey.IsKeyUp(Keys.Space))
                {
                    if (_hero.direction)
                    {
                        BulletRight b = new BulletRight(bullet_afbeeldingRechts, (int)_hero.Positie.X + 50, (int)_hero.Positie.Y + 35);
                        bulletsright.Add(b);
                    }

                    else
                    {
                        BulletLeft b = new BulletLeft(bullet_afbeeldingLinks, (int)_hero.Positie.X - 50, (int)_hero.Positie.Y + 35);
                        bulletsleft.Add(b);
                    }
                }
                pastkey = Keyboard.GetState();


                foreach (BulletRight Bullet in bulletsright)
                {
                    Bullet.Update(gameTime);
                }

                foreach (BulletLeft Bullet in bulletsleft)
                {
                    Bullet.Update(gameTime);
                }

                CollisionsLvl1();

                for (int i = 0; i < bulletsright.Count; i++)
                {
                    //float oldstate = bulletsright[i].Positie.X;
                    if (bulletsright[i].Positie.X > (_hero.Positie.X + 400))
                    {
                        bulletsright.Remove(bulletsright[i]);
                    }
                }
                for (int i = 0; i < bulletsleft.Count; i++)
                {
                    //float oldstate = bulletsright[i].Positie.X;
                    if (bulletsleft[i].Positie.X < (_hero.Positie.X - 400))
                    {
                        bulletsleft.Remove(bulletsleft[i]);
                    }
                }


                if (_hero.IsMoving)
                {
                    camPos.X += _hero.VelocityX.X;
                }
                if (_hero.IsDead)
                {
                    camPos.X = 0;
                }
                #endregion
            }

            else if (CurrentGameState == GameState.PlayingSecretLvl)
            {
                _hero.Update(gameTime);

                CollisionsSecret();

                foreach (coin coin in coins_SecretLvl)
                {
                    coin.Update(gameTime);
                }
            }

            else if (CurrentGameState == GameState.PlayingLvl2)
            {
                _hero.Update(gameTime);
                foreach (MovingTiles tile in movingTiles_Lvl2)
                {
                    tile.Update(gameTime);
                }

                foreach (Enemy enemy in _EnemysLvl2)
                {
                    enemy.Update(gameTime);
                }

                if (Keyboard.GetState().IsKeyDown(Keys.Space) && pastkey.IsKeyUp(Keys.Space))
                {
                    if (_hero.direction)
                    {
                        BulletRight b = new BulletRight(bullet_afbeeldingRechts, (int)_hero.Positie.X + 50, (int)_hero.Positie.Y + 35);
                        bulletsright.Add(b);
                    }

                    else
                    {
                        BulletLeft b = new BulletLeft(bullet_afbeeldingLinks, (int)_hero.Positie.X - 50, (int)_hero.Positie.Y + 35);
                        bulletsleft.Add(b);
                    }
                }
                pastkey = Keyboard.GetState();

                foreach (BulletRight Bullet in bulletsright)
                {
                    Bullet.Update(gameTime);
                }

                foreach (BulletLeft Bullet in bulletsleft)
                {
                    Bullet.Update(gameTime);
                }

                foreach (coin coin in coins_Lvl2)
                {
                    coin.Update(gameTime);
                }

                endBoss.Update(gameTime);
                foreach (BulletEnemy Bullet in bulletEnemy)
                {
                    Bullet.Update(gameTime);
                }

                CollisionLvl2();

                for (int i = 0; i < bulletsright.Count; i++)
                {
                    if (bulletsright[i].Positie.X > (_hero.Positie.X + 400))
                    {
                        bulletsright.Remove(bulletsright[i]);
                    }
                }
                for (int i = 0; i < bulletsleft.Count; i++)
                {
                    if (bulletsleft[i].Positie.X < (_hero.Positie.X - 400))
                    {
                        bulletsleft.Remove(bulletsleft[i]);
                    }
                }

                for (int i = 0; i < bulletEnemy.Count; i++)
                {
                    if (bulletEnemy[i].Positie.X < 3500)
                    {
                        bulletEnemy.Remove(bulletEnemy[i]);
                    }
                }



                if (_hero.IsMoving)
                {
                    camPos.X += _hero.VelocityX.X;
                }
                if (_hero.IsDead)
                {
                    camPos.X = 0;
                }
            }


            base.Update(gameTime);
        }