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--;
- }
- }
- }
- // Shoot Bullets
- public void Shoot()
- {
- Bullets newBullet = new Bullets(Content.Load<Texture2D>("Assets/bullet"));
- newBullet.velocity = new Vector2(0, -1);
- newBullet.position = player.playerLocation + newBullet.velocity;
- if (bullets.Count() < 5)
- bullets.Add(newBullet);
- }
- ----- 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