Example #1
0
        /// <summary>
        /// Checks for collision between trash and animal
        /// </summary>
        private void CheckForCollision(GameTime gameTime)
        {
            AnimalsDead  animalsDead = Game.Services.GetService <AnimalsDead>();
            TrashManager trashManger = Game.Services.GetService <TrashManager>();

            foreach (Trash trash in trashManger.TrashList)
            {
                if (AnimalBounds.Intersects(trash.trashBoundry))
                {
                    hit = true;
                    secondsSinceLastHit += gameTime.ElapsedGameTime.TotalSeconds;
                    if (secondsSinceLastHit >= 2.5)
                    {
                        health--;
                        secondsSinceLastHit = 0.0;
                    }
                    if (health == 0)
                    {
                        Game.Components.Remove(this);
                        animalsDead.AddDeadAnimal();
                        if (animalsDead.Dead >= 10)
                        {
                            animalsDead.GameOver = true;
                            ((Game1)Game).HideAllScenes();
                            Game.Services.GetService <GameOver>().Show();
                        }
                    }
                }
            }
        }
Example #2
0
 public override void Update(GameTime gameTime)
 {
     if (Enabled)
     {
         if (Keyboard.GetState().IsKeyDown(Keys.Escape))
         {
             Score       score = Game.Services.GetService <Score>();
             AnimalsDead dead  = Game.Services.GetService <AnimalsDead>();
             score.score = 0;
             dead.Dead   = 0;
             ((Game1)Game).HideAllScenes();
             Game.Services.GetService <StartScene>().Show();
         }
     }
     base.Update(gameTime);
 }
Example #3
0
        public override void Update(GameTime gameTime)
        {
            trashPosition  += Speed;
            trashPosition.Y = MathHelper.Clamp(trashPosition.Y, 0, GraphicsDevice.Viewport.Height - YCLAMP);

            if (trashPosition.Y == GraphicsDevice.Viewport.Height - 40 && playEffect == true)
            {
                soundEffects.Play();
                playEffect = false;
            }
            AnimalsDead animalsDead = Game.Services.GetService <AnimalsDead>();

            if (animalsDead.Dead > 9)
            {
                TrashManager trashManger = Game.Services.GetService <TrashManager>();
                trashManger.SpawnTimer = 5;
                Game.Components.Remove(this);
                trashManger.TrashList.Remove(this);
                animalsDead.GameOver = false;
            }
            CheckForCollision();

            base.Update(gameTime);
        }