/// <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) { // Allows the game to exit if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed) { this.Exit(); } int count = 0; foreach (bacon tira in listaBacon) { if (tira.comido) { count++; } } gameOver = count >= 3; if (!gameOver) { KeyboardState keyboard = Keyboard.GetState(); scoreString = "Pontos: " + scoreNumber; if ((gameTime.TotalGameTime - ultimoTempo) > intervaloCoolDown) { coolDownArma = false; } player.AtualizaPosicao(keyboard); if (keyboard.IsKeyDown(Keys.Space) && !coolDownArma) // so vou disparar novamente quando o cool down acabar { coolDownArma = true; ultimoTempo = gameTime.TotalGameTime; bullet minhaBala = new bullet(Content.Load <Texture2D>("bullet-" + player.direcaoCarteseana), player.position, new Vector2(graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight), player.direcaoCarteseana ); listaBalas.Add(minhaBala); } //primeiro desenha a porra toda foreach (zombie sprite in listaZumbis) { sprite.AtualizaPosicao(); } foreach (bullet bala in listaBalas) { bala.AtualizaPosicao(); } bullet pointer = null; // agora testa colisao com as balas foreach (zombie sprite in listaZumbis) { foreach (bullet bala in listaBalas) { if (bala.BoundingBox.Intersects(sprite.BoundingBox)) { bala.colidiuZumbi = true; pointer = bala; Vector2 newLocation = this.GetRandomInitialLocation(zombie.larguraTextura, zombie.alturaTextura); //Vector2 newLocation = new Vector2(400,250); sprite.MorreDiabo(Content.Load <Texture2D>(zombie.GetSprite(newLocation, matrixHigh)), newLocation); scoreNumber = scoreNumber + 10; } } } if (pointer != null) { pointer.position = new Vector2(-50f, -50f); } if ((gameTime.TotalGameTime - ultimoTempo) > intervaloCoolDown) { coolDownSFX = false; } // agora testa colisao com os bacon! foreach (zombie sprite in listaZumbis) { if (numberBacons > 0) { foreach (bacon tira in listaBacon) { if (tira.BoundingBox.Intersects(sprite.BoundingBox)) { sprite.colidiuBacon = true; tira.MorreDiabo(); if (!coolDownSFX) { coolDownSFX = true; sf.Play(); } sprite.MorreDiabo(sprite.texture, sprite.InitialPosition); //sprite.jaComeu = true; } } } else { gameOver = true; } } base.Update(gameTime); } else { scoreString = "GAME OVER!"; } }
/// <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) { // Allows the game to exit if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed) this.Exit(); int count = 0; foreach (bacon tira in listaBacon) { if (tira.comido) count++; } gameOver = count >= 3; if (!gameOver) { KeyboardState keyboard = Keyboard.GetState(); scoreString = "Pontos: " + scoreNumber; if ((gameTime.TotalGameTime - ultimoTempo) > intervaloCoolDown) coolDownArma = false; player.AtualizaPosicao(keyboard); if (keyboard.IsKeyDown(Keys.Space) && !coolDownArma) // so vou disparar novamente quando o cool down acabar { coolDownArma = true; ultimoTempo = gameTime.TotalGameTime; bullet minhaBala = new bullet(Content.Load<Texture2D>("bullet-" + player.direcaoCarteseana), player.position, new Vector2(graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight), player.direcaoCarteseana ); listaBalas.Add(minhaBala); } //primeiro desenha a porra toda foreach (zombie sprite in listaZumbis) { sprite.AtualizaPosicao(); } foreach (bullet bala in listaBalas) { bala.AtualizaPosicao(); } bullet pointer = null; // agora testa colisao com as balas foreach (zombie sprite in listaZumbis) { foreach (bullet bala in listaBalas) { if (bala.BoundingBox.Intersects(sprite.BoundingBox)) { bala.colidiuZumbi = true; pointer = bala; Vector2 newLocation = this.GetRandomInitialLocation(zombie.larguraTextura, zombie.alturaTextura); //Vector2 newLocation = new Vector2(400,250); sprite.MorreDiabo(Content.Load<Texture2D>(zombie.GetSprite(newLocation, matrixHigh)), newLocation); scoreNumber = scoreNumber + 10; } } } if (pointer != null) { pointer.position = new Vector2(-50f, -50f); } if ((gameTime.TotalGameTime - ultimoTempo) > intervaloCoolDown) coolDownSFX = false; // agora testa colisao com os bacon! foreach (zombie sprite in listaZumbis) { if (numberBacons > 0) { foreach (bacon tira in listaBacon) { if (tira.BoundingBox.Intersects(sprite.BoundingBox)) { sprite.colidiuBacon = true; tira.MorreDiabo(); if (!coolDownSFX) { coolDownSFX = true; sf.Play(); } sprite.MorreDiabo(sprite.texture, sprite.InitialPosition); //sprite.jaComeu = true; } } } else { gameOver = true; } } base.Update(gameTime); } else { scoreString = "GAME OVER!"; } }