Advertisement
Guest User

Untitled

a guest
Jul 31st, 2014
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.33 KB | None | 0 0
  1. public void checkBulletCollision(List<Bullet> bullets)
  2. {
  3.  
  4. foreach (Bullet b in bullets)
  5. {
  6. if (BoundingBox.Intersects(b.BoundingBox))
  7. {
  8. isAlive = false;
  9. b.isVisible = false;
  10. bullets.Remove(b);
  11. break;
  12. }
  13.  
  14. }
  15.  
  16.  
  17.  
  18.  
  19. }
  20.  
  21. public void UpdateBullets()
  22. {
  23.  
  24. foreach (Bullet b in bullets)
  25. {
  26. b.position.X += 10;
  27. if (b.position.X > 1020)
  28. b.isVisible = false;
  29. }
  30. for (int i = 0; i < bullets.Count; i++)
  31. {
  32. if (!bullets[i].isVisible)
  33. {
  34. bullets.RemoveAt(i);
  35. i--;
  36. }
  37. }
  38.  
  39.  
  40.  
  41.  
  42. }
  43.  
  44. public void Shoot()
  45. {
  46.  
  47. Bullet newB = new Bullet(this);
  48. newB.LoadContent();
  49. newB.position = player1.position;
  50. newB.position.Y -= 10;
  51. newB.position.X += 10;
  52. newB.isVisible = true;
  53.  
  54. if (bullets.Count < 1000)
  55. bullets.Add(newB);
  56. }
  57.  
  58. protected override void Update(GameTime gameTime)
  59. {
  60. if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
  61. Exit();
  62.  
  63. // TODO: Add your update logic here
  64. float deltaTime = (float)gameTime.ElapsedGameTime.TotalSeconds;
  65. controls.Update();
  66. if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
  67. Exit();
  68.  
  69.  
  70.  
  71. //update all blocks in array
  72. for (int i = 0; i < blocks.Length; i++)
  73. {
  74. blocks[i].Update();
  75. }
  76.  
  77. //block1.Update();
  78. //block2.Update();
  79. //block3.Update();
  80. //CheckCollisions();
  81. player1.Update(controls, gameTime, blocks);
  82.  
  83. foreach (Zombie z in zombies)
  84. {
  85. if (z.isAlive)
  86. {
  87.  
  88. z.Update(gameTime, blocks);
  89.  
  90. z.getPlayerPosition(player1);
  91. z.checkBulletCollision(bullets);
  92. }
  93.  
  94. }
  95. if (Keyboard.GetState().IsKeyDown(Keys.Space) && pastKey.IsKeyUp(Keys.Space))
  96. {
  97. Shoot();
  98.  
  99. }
  100.  
  101. UpdateBullets();
  102.  
  103. pastKey = Keyboard.GetState();
  104.  
  105.  
  106.  
  107.  
  108. base.Update(gameTime);
  109. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement