Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void checkBulletCollision(List<Bullet> bullets)
- {
- foreach (Bullet b in bullets)
- {
- if (BoundingBox.Intersects(b.BoundingBox))
- {
- isAlive = false;
- b.isVisible = false;
- bullets.Remove(b);
- break;
- }
- }
- }
- public void UpdateBullets()
- {
- foreach (Bullet b in bullets)
- {
- b.position.X += 10;
- if (b.position.X > 1020)
- b.isVisible = false;
- }
- for (int i = 0; i < bullets.Count; i++)
- {
- if (!bullets[i].isVisible)
- {
- bullets.RemoveAt(i);
- i--;
- }
- }
- }
- public void Shoot()
- {
- Bullet newB = new Bullet(this);
- newB.LoadContent();
- newB.position = player1.position;
- newB.position.Y -= 10;
- newB.position.X += 10;
- newB.isVisible = true;
- if (bullets.Count < 1000)
- bullets.Add(newB);
- }
- protected override void Update(GameTime gameTime)
- {
- if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
- Exit();
- // TODO: Add your update logic here
- float deltaTime = (float)gameTime.ElapsedGameTime.TotalSeconds;
- controls.Update();
- if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
- Exit();
- //update all blocks in array
- for (int i = 0; i < blocks.Length; i++)
- {
- blocks[i].Update();
- }
- //block1.Update();
- //block2.Update();
- //block3.Update();
- //CheckCollisions();
- player1.Update(controls, gameTime, blocks);
- foreach (Zombie z in zombies)
- {
- if (z.isAlive)
- {
- z.Update(gameTime, blocks);
- z.getPlayerPosition(player1);
- z.checkBulletCollision(bullets);
- }
- }
- if (Keyboard.GetState().IsKeyDown(Keys.Space) && pastKey.IsKeyUp(Keys.Space))
- {
- Shoot();
- }
- UpdateBullets();
- pastKey = Keyboard.GetState();
- base.Update(gameTime);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement