Ejemplo n.º 1
0
 /// <summary>
 /// Infects this human if it is susceptible.
 /// </summary>
 public void Infect()
 {
     // the standard non-party case
     if (LevelSettings.GetActiveSceneName() != "YouVsVirus_Leveldisco")
     {
         if (IsSusceptible())
         {
             SetCondition(EXPOSED);
         }
     }
     else // the party case
     {
         if (IsSusceptible())
         {
             // both friend and player have a 10% chance of getting exposed
             if (this.tag == "Player" || this.tag == "Friend")
             {
                 if (UnityEngine.Random.value < 0.2)
                 {
                     SetCondition(EXPOSED);
                 }
             }
             // rest of npcs have increasing chance of getting infected
             else if (UnityEngine.Random.value < num_inf * 0.028)
             {
                 num_inf++;
                 SetCondition(EXPOSED);
             }
         }
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// NPC random movement
        /// if the velocity decreases the npc has some chance of changing their direction
        /// then the velocity is gradually increased
        /// </summary>
        public void RandomMovement()
        {
            // checks if we need to increase the velocity
            bool increase_vel = false;
            // the velocity norm to check how fast we are going
            float vel_norm = myRigidbody.velocity.sqrMagnitude;

            // if we are getting too slow
            if (vel_norm < MinVelocity)
            {
                // increase velocity later on
                increase_vel = true;
                // we have a 20% chance of changing our direction or we are at a dancefloor (or drunk) :-)
                if (UnityEngine.Random.value < 0.2f || (LevelSettings.GetActiveSceneName() == "YouVsVirus_Leveldisco"))
                {
                    // Random.onUnitSphere returns  a random point on the surface of a sphere with radius 1
                    // so we do not change the velocity, just the direction
                    myRigidbody.velocity = UnityEngine.Random.onUnitSphere;
                }
            }

            //  Stop! This is too fast!
            if (vel_norm > MaxVelocity)
            {
                vel_norm     = MaxVelocity;
                increase_vel = false;
            }

            // we are slow at the moment but do not want to become too fast
            if (vel_norm < MaxVelocity && increase_vel == true)
            {
                // increase the velocity in every call to this function
                myRigidbody.velocity *= (1f + AccelerationFactor);
            }
        }
Ejemplo n.º 3
0
 void Update()
 {
     // let sprites reenter from right, frame count gives a smoother distribution of npcs
     if (LevelSettings.GetActiveSceneName() == "YouVsVirus_Leveldemo" && Time.frameCount % 10 == 0)
     {
         ReenterScreenFromRight();
     }
 }
Ejemplo n.º 4
0
 /// <summary>
 /// FixedUpdate: FixedUpdate is often called more frequently than Update.
 /// It can be called multiple times per frame, if the frame rate is low and
 /// it may not be called between frames at all if the frame rate is high.
 /// All physics calculations and updates occur immediately after FixedUpdate.
 /// When applying movement calculations inside FixedUpdate, you do not need
 /// to multiply your values by Time.deltaTime. This is because FixedUpdate
 /// is called on a reliable timer, independent of the frame rate.
 /// </summary>
 void FixedUpdate()
 {
     if (CanMove())
     {
         // in the demo level the NPCs move from right to left
         if (LevelSettings.GetActiveSceneName() == "YouVsVirus_Leveldemo")
         {
             myRigidbody.velocity = new Vector2(-0.5f, UnityEngine.Random.Range(-1.0f, 1.0f));
         }
         else
         {
             RandomMovement();
         }
     }
 }