Advertisement
Guest User

Untitled

a guest
Nov 24th, 2014
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.60 KB | None | 0 0
  1.         protected override void Update(GameTime gameTime)
  2.         {
  3.             player.Update(gameTime);
  4.  
  5.             spawn += (float)gameTime.ElapsedGameTime.TotalSeconds;
  6.  
  7.             foreach(Zombies zombie in zombies)
  8.                 zombie.Update(graphics.GraphicsDevice);
  9.             SpawnZombies();
  10.  
  11.  
  12.             if (Keyboard.GetState().IsKeyDown(Keys.Space))
  13.                 Shoot();
  14.  
  15.             UpdateBullets();
  16.             base.Update(gameTime);
  17.         }
  18.  
  19.         // Bullet Update Method
  20.         public void UpdateBullets()
  21.         {
  22.             foreach (Bullets bullet in bullets)
  23.             {
  24.                 bullet.position += bullet.velocity;
  25.                 if (Vector2.Distance(bullet.position, player.playerLocation) > 500)
  26.                     bullet.isVisible = false;
  27.             }
  28.             for (int b = 0; b < bullets.Count; b++)
  29.             {
  30.                 if (!bullets[b].isVisible)
  31.                 {
  32.                     bullets.RemoveAt(b);
  33.                     b--;
  34.                 }
  35.             }
  36.         }
  37.  
  38.  
  39.  
  40.  
  41. ----- BULLETS CLASS -----
  42.  
  43.     class Bullets
  44.     {
  45.         public Texture2D texture;
  46.         public Vector2 position;
  47.         public Vector2 velocity;
  48.         public Vector2 origin;
  49.  
  50.         public bool isVisible;
  51.  
  52.         public Bullets(Texture2D newTexture)
  53.         {
  54.             texture = newTexture;
  55.             isVisible = false;
  56.         }
  57.  
  58.  
  59.  
  60.         public void Draw(SpriteBatch spriteBatch)
  61.         {
  62.             spriteBatch.Draw(texture, position,null, Color.White, 0f, origin, 1f, SpriteEffects.None, 0);
  63.         }
  64.     }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement