Exemple #1
0
        protected override void Update(GameTime gameTime)
        {
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                Exit();
            }

            count += gameTime.ElapsedGameTime.TotalSeconds;
            if (count >= 1)
            {
                if (bananaCounter == 8)
                {
                    int     randomNum = (int)random.Next(0, vectors.Length);
                    Vector2 position  = vectors[randomNum];
                    bombs.Add(new Bomb(this, graphics, random.NextDouble(), random.NextDouble(), position.X, position.Y));
                    bananaCounter = 0;
                    count         = 0;
                }
                else
                {
                    int     randomNum = (int)random.Next(0, vectors.Length);
                    Vector2 position  = vectors[randomNum];
                    bananas.Add(new Banana(this, graphics, random.NextDouble(), random.NextDouble(), position.X, position.Y));
                    bananaCounter++;
                    count = 0;
                }
            }
            monkey.Update(gameTime);
            barrel.Update(gameTime);

            Banana bananaToRemove = null;
            bool   remove         = false;

            foreach (Banana b in bananas)
            {
                b.Update(gameTime);
                b.LoadContent(Content);
                if (Collisions.CollidesWith(b.bounds, monkey.bounds) && heldBananas < 5)
                {
                    bananaToRemove = b;
                    remove         = true;
                    heldBananas++;
                }
            }
            if (remove)
            {
                bananas.Remove(bananaToRemove);
            }
            foreach (Bomb b in bombs)
            {
                b.Update(gameTime);
                b.LoadContent(Content);
                if (Collisions.CollidesWith(b.bounds, monkey.bounds))
                {
                    end = true;
                }
            }
            base.Update(gameTime);
        }
Exemple #2
0
 public void Update(GameTime timeSpan)
 {
     if (Collisions.CollidesWith(game.monkey.bounds, bounds) && !game.end)
     {
         game.score      += game.heldBananas;
         game.heldBananas = 0;
     }
 }