Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- protected override void Update(GameTime gameTime)
- {
- player.Update(gameTime);
- spawn += (float)gameTime.ElapsedGameTime.TotalSeconds;
- foreach(Zombies zombie in zombies)
- zombie.Update(graphics.GraphicsDevice);
- SpawnZombies();
- if (Keyboard.GetState().IsKeyDown(Keys.Space))
- Shoot();
- UpdateBullets();
- base.Update(gameTime);
- }
- // Bullet Update Method
- public void UpdateBullets()
- {
- foreach (Bullets bullet in bullets)
- {
- bullet.position += bullet.velocity;
- if (Vector2.Distance(bullet.position, player.playerLocation) > 500)
- bullet.isVisible = false;
- }
- for (int b = 0; b < bullets.Count; b++)
- {
- if (!bullets[b].isVisible)
- {
- bullets.RemoveAt(b);
- b--;
- }
- }
- }
- ----- BULLETS CLASS -----
- class Bullets
- {
- public Texture2D texture;
- public Vector2 position;
- public Vector2 velocity;
- public Vector2 origin;
- public bool isVisible;
- public Bullets(Texture2D newTexture)
- {
- texture = newTexture;
- isVisible = false;
- }
- public void Draw(SpriteBatch spriteBatch)
- {
- spriteBatch.Draw(texture, position,null, Color.White, 0f, origin, 1f, SpriteEffects.None, 0);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement