示例#1
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() && !LevelSettings.GetActiveEndLevelController().levelHasFinished)
     {
         ProcessMovementInput();
     }
 }
示例#2
0
        /// <summary>
        /// Set stage of infection and update smiley's image
        /// </summary>
        public virtual void SetCondition(int condition)
        {
            _mycondition = condition;
            EndLevelControllerBase egc = LevelSettings.GetActiveEndLevelController();

            // Update the stats
            switch (condition)
            {
            case EXPOSED:
            {
                egc.NotifyHumanExposed();
                GetComponent <AbstractInfection>().Expose();
                levelStats.aHumanGotExposed();
                LevelSettings.GetActiveEndLevelController().infectionIsInitialized = true;
                break;
            }

            case INFECTIOUS:
            {
                levelStats.aHumanGotInfected();
                break;
            }

            case DEAD:
            {
                //  Removes this human's Rigidbody from the physics simulation,
                //  which disables movement and collision detection.
                myRigidbody.simulated = false;

                //  Set the simulated velocity to zero.
                myRigidbody.velocity = Vector3.zero;

                //  Put this human's sprite on the 'Dead' sorting layer.
                //  This layer is below the others, causing Dead humans to be rendered
                //  below the living.
                GetComponent <SpriteRenderer>().sortingLayerName = "Dead";

                egc.NotifyHumanRemoved();
                levelStats.aHumanDied(myID);
                break;
            }

            case RECOVERED:
            {
                egc.NotifyHumanRemoved();
                levelStats.aHumanRecovered();
                break;
            }
            }

            // we want all the smileys to stay the same except for the player
            if (LevelSettings.GetActiveLevelSettings().ShowInfectionStatus == true || this.tag == "Player")
            {
                // Update the sprite image
                UpdateSpriteImage();
            }
        }
        void OnTriggerEnter2D(Collider2D other)
        {
            // Something entered the trigger zone!
            HumanBase otherHuman = other.GetComponentInParent <HumanBase>();

            //  If a human came into infection radius, try to infect it by virus or proganda.
            if (otherHuman != null)
            {
                HumanBase myHuman = GetComponentInParent <HumanBase>();

                // the player is infected by propaganda not neccessarily by the virus, only those with a sign are 100% dangerous, the other only 40%
                if (otherHuman.tag == "Player" && (myHuman.transform.GetChild(1).GetComponent <SpriteRenderer>().enabled == true || UnityEngine.Random.value < 0.4))
                {
                    float dist = Vector3.Distance(myHuman.transform.position, otherHuman.transform.position);
                    float r    = 2f * InfectionRadius * transform.parent.localScale.x;
                    // maybe this is the right infection distance?
                    if (dist < r)
                    {
                        Player player = otherHuman.GetComponentInParent <Player>();
                        // now the player also shows their sign
                        player.transform.GetChild(1).GetComponent <SpriteRenderer>().enabled = true;
                        player.transform.GetChild(2).GetComponent <SpriteRenderer>().enabled = true;
                        player.infectedByPropaganda = true;
                        // notify end level controller
                        LevelSettings.GetActiveEndLevelController().NotifyPlayerInfectedByPropaganda();
                    }
                }

                // maybe also infect with virus
                if (myHuman.IsInfectious())
                {
                    // check if myHuman is infectious and if they are in my infection radius
                    float dist    = Vector3.Distance(myHuman.transform.position, otherHuman.transform.position);
                    float r       = 2f * InfectionRadius * transform.parent.localScale.x;
                    float myWidth = myHuman.GetComponent <SpriteRenderer>().bounds.extents.x; //extents = size of width / 2
                    // maybe this is the right infection distance?
                    if (dist < r)
                    {
                        // if I am the player and infected an NPC
                        // this NPC is previously well
                        // I give notice to the level stats
                        if ((myHuman.tag == "Player" || myHuman.wasInfectedByPlayer == true) && otherHuman.IsSusceptible())
                        {
                            // this also adds other human to the list of infected
                            // to count if other human dies later on
                            otherHuman.wasInfectedByPlayer = true;
                            myHuman.levelStats.PlayerInfectedNPC(otherHuman.myID);
                        }

                        otherHuman.Infect();
                    }
                }
            }
        }
示例#4
0
        public override void SetCondition(int condition)
        {
            base.SetCondition(condition);

            if (condition == EXPOSED)
            {
                LevelSettings.GetActiveEndLevelController().NotifyPlayerExposed();
            }
            if (condition == DEAD)
            {
                LevelSettings.GetActiveEndLevelController().NotifyPlayerDied();
            }
        }
示例#5
0
 void OnTriggerEnter2D(Collider2D other)
 {
     if (other.gameObject.tag == "Player")
     {
         // The player is here. We check how many masks he has and
         // give this option to the end level controller.
         // The controller then decides to end the level or not.
         Debug.Log("Player entered hospital.");
         // Get number of masks from player
         int numberOfMasks = other.GetComponent <Player>().getNumMasks();
         // Get end level controller and notify him about the number of masks
         EndLevelControllerBase elc = LevelSettings.GetActiveEndLevelController();
         elc.NotifyInt(numberOfMasks);
     }
 }
示例#6
0
 void Update()
 {
     // if the player has not found us
     if (friendFound == false)
     {
         // we move like the drunken bastard we are
         RandomMovement();
     }
     else if (!LevelSettings.GetActiveEndLevelController().levelHasFinished)
     {
         // otherwise we follow the player
         FollowPlayer();
     }
     if (GetCondition() != WELL)
     {
         LevelSettings.GetActiveEndLevelController().GetComponent <EndLevelControllerLeveldisco>().NotifyFriendExposed();
     }
 }
 protected override void Update()
 {
     // Check if we collected all masks and returned them to the hospital.
     // If so, pause the game and show a screen telling us to get home.
     if (!LevelSettings.GetActiveEndLevelController().levelHasFinished&& ShowCanvasAllCollectedGetHome())
     {
         // The player has collected all masks and brought them to the hospital.
         // Get a reference to the player.
         Components.Player player = GameObject.FindWithTag("Player").GetComponent <Components.Player>();
         // Set the number of masks of the player to 0,
         // since he gave his masks to the hospital.
         player.addMasks(-player.getNumMasks());
         // Pause the game
         PauseGame.Pause();
         // Show the pause message that tells him to get home.
         // This canvas has a "space-to-continue"-script attached
         CanvasAllCollectedGetHome.SetActive(true);
         // Set internal bool that the player is now on its way home
         onWayHome = true;
     }
     base.Update();
 }
    private void Start()
    {
        // activate end level controller
        endlevel = LevelSettings.GetActiveEndLevelController();
        // Get player (this may return null if the player is inactive)
        player = GameObject.FindGameObjectWithTag("Player");
        // Get player renderer
        playerRend = PlayerInside.GetComponent <SpriteRenderer>();
        // Per default, we do not show the player in the window
        UnshowPlayer();
        // Initialize the player spawn position
        playerAppearPosition = gameObject.transform.position + new Vector3(0, -0.5f, 0);

        // The player is allowed to exit the house if he starts in it
        // or if he can enter and exit at will.
        // If he starts in the house and is not allowed to enter and exit at will,
        // then we will set playerCanExit to false as soon as he left the house for the first time.
        playerCanExit = EnterAndExitAtWill || playerStartsInside;

        // Set this point in time as the last execution time of update.
        // This means, update is first performed at time Time.time + timeBetweenUpdates
        lastTime = Time.time;
    }