Advertisement
Guest User

Untitled

a guest
Nov 24th, 2014
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.97 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.         // Shoot Bullets
  40.         public void Shoot()
  41.         {
  42.             Bullets newBullet = new Bullets(Content.Load<Texture2D>("Assets/bullet"));
  43.             newBullet.velocity = new Vector2(0, -1);
  44.             newBullet.position = player.playerLocation + newBullet.velocity;
  45.  
  46.             if (bullets.Count() < 5)
  47.                 bullets.Add(newBullet);
  48.         }
  49.  
  50.  
  51.  
  52. ----- BULLETS CLASS -----
  53.  
  54.     class Bullets
  55.     {
  56.         public Texture2D texture;
  57.         public Vector2 position;
  58.         public Vector2 velocity;
  59.         public Vector2 origin;
  60.  
  61.         public bool isVisible;
  62.  
  63.         public Bullets(Texture2D newTexture)
  64.         {
  65.             texture = newTexture;
  66.             isVisible = false;
  67.         }
  68.  
  69.  
  70.  
  71.         public void Draw(SpriteBatch spriteBatch)
  72.         {
  73.             spriteBatch.Draw(texture, position,null, Color.White, 0f, origin, 1f, SpriteEffects.None, 0);
  74.         }
  75.     }
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement