/// <summary>
        /// Places the player and all NPCs on the map randomly.
        /// </summary>
        private void CreateHumans()
        {
            Vector3 coords3D = new Vector3(PlayerSpawnCoordinates[0], PlayerSpawnCoordinates[1], 0);

            //  Place the player
            Player = Instantiate(playerPrefab.GetComponent <Player>(),
                                 coords3D,
                                 Quaternion.identity);
            // give the player a unique id
            Player.myID = 0;
            // Set player status to inactive. Will get avtivated when we leave the house
            Player.gameObject.SetActive(false);
            PlayerHouse playerHouseScript = playerHouse.GetComponent <PlayerHouse>();

            // Set the player inside the house
            playerHouseScript.NotifyPlayerIsClose(true);
            playerHouseScript.NotifyPlayerInside(true);
            // Set the player var of the house
            playerHouseScript.setPlayer(Player.gameObject);

            //  Place the NPCs in the grid
            for (int i = 1; i <= npcNumber; i++)
            {
                NPCs.Add(Instantiate(npcPrefab.GetComponent <NPC>(),
                                     randomGridForHumans.RandomCoords[i],
                                     Quaternion.identity));
                // give all npcs a unique id
                NPCs[i - 1].myID = i + 1;
            }

            //  Infect one
            NPCs[Mathf.RoundToInt(npcNumber / 2f)].SetInitialCondition(NPC.EXPOSED);
        }
示例#2
0
        /// <summary>
        /// Places the player and all NPCs on the map
        /// </summary>
        private void CreateHumans()
        {
            // place player near their house
            Vector3 coords = new Vector2(-3.43f, -2.34f);

            //  Place the player
            Player = Instantiate(playerPrefab.GetComponent <Player>(),
                                 coords,
                                 Quaternion.identity);
            // give the player a unique id
            Player.myID = 0;
            // Set player status to inactive. Will get avtivated when we leave the house
            Player.gameObject.SetActive(false);

            PlayerHouse playerHouseScript = PlayerHouse.GetComponent <PlayerHouse>();

            // Set the player inside the house
            playerHouseScript.NotifyPlayerIsClose(true);
            playerHouseScript.NotifyPlayerInside(true);
            // Set the player var of the house
            playerHouseScript.setPlayer(Player.gameObject);


            //  Place the NPCs in the grid
            for (int i = 0; i < npcNumber; i++)
            {
                NPCs.Add(Instantiate(npcPrefab.GetComponent <NPC>(),
                                     randomGridForHumans.RandomCoords[i],
                                     Quaternion.identity));
                // give all npcs a unique id
                NPCs[i].myID = i + 1;
            }

            //  Infect one them.
            NPCs[Mathf.RoundToInt(npcNumber / 2f)].SetInitialCondition(NPC.EXPOSED);

            //  Place the NPC_AIs in the grid
            for (int i = 0; i < npcAINumber; i++)
            {
                NPC_AIs.Add(Instantiate(npcAIPrefab.GetComponent <NPC_AI>(),
                                        randomGridForHumans.RandomCoords[i],
                                        Quaternion.identity));
                // give all npcs with ai a unique id
                NPC_AIs[i].myID = npcNumber + 1 + i;
                // give them a unique layer so that they are allowed on bridges
                NPC_AIs[i].gameObject.layer = LayerMask.NameToLayer("NPC_AI");
            }
            //  Infect one them.
            NPC_AIs[Mathf.RoundToInt(npcAINumber / 2f)].SetInitialCondition(NPC.EXPOSED);
        }
示例#3
0
        /// <summary>
        /// Places the player and all NPCs on the map randomly.
        /// </summary>
        private void CreateHumans()
        {
            Vector3 coords3D = new Vector3(PlayerSpawnCoordinates[0], PlayerSpawnCoordinates[1], 0);

            //  Place the player
            Player = Instantiate(playerPrefab.GetComponent <Player>(),
                                 coords3D,
                                 Quaternion.identity);
            // Activate player. Otherwise it does not show (i done really know why. Probably has smth todo with the house)
            Player.gameObject.SetActive(true);

            PlayerHouse playerHouseScript = playerHouse.GetComponent <PlayerHouse>();

            // Set the player var of the house
            playerHouseScript.setPlayer(Player.gameObject);
            // The player is not close and not at home
            // NOTE: Setting these explicitely is not really necessary, since they are already set for the house.
            playerHouseScript.NotifyPlayerIsClose(false);
            playerHouseScript.NotifyPlayerInside(false);

            // give the player a unique id
            Player.myID = npcNumber;

            //  Place the NPCs in the grid
            for (int i = 1; i <= npcNumber; i++)
            {
                NPCs.Add(Instantiate(npcPrefab.GetComponent <NPC>(),
                                     randomGridForHumans.RandomCoords[i],
                                     Quaternion.identity));
                // give all npcs a unique id
                NPCs[i - 1].myID = i - 1;
            }

            //  Infect one
            NPCs[Mathf.RoundToInt(npcNumber / 2f)].SetInitialCondition(NPC.EXPOSED);
        }
示例#4
0
        /// <summary>
        /// Places the player and all NPCs on the map.
        /// </summary>
        private void CreateHumans()
        {
            // place player near top left edge of the screen
            Vector2 coords   = new Vector2(-randomGridForHumans.screenBounds.x + 0.2f, randomGridForHumans.screenBounds.y - 0.2f);
            Vector3 coords3D = new Vector3(coords[0], coords[1], 0);

            //  Place the player
            Player = Instantiate(playerPrefab.GetComponent <Player>(),
                                 coords3D,
                                 Quaternion.identity);
            // give the player a unique id
            Player.myID = npcNumber;

            // player has no hand and no sign at the beginning
            Player.transform.GetChild(1).GetComponent <SpriteRenderer>().enabled = false;
            Player.transform.GetChild(2).GetComponent <SpriteRenderer>().enabled = false;

            // Set the player var of the house
            PlayerHouse playerHouseScript = playerHouse.GetComponent <PlayerHouse>();

            playerHouseScript.setPlayer(Player.gameObject);


            //  Place the NPCs in the grid
            for (int i = 1; i <= npcNumber; i++)
            {
                NPCs.Add(Instantiate(npcPrefab.GetComponent <NPC>(),
                                     randomGridForHumans.RandomCoords[i],
                                     Quaternion.identity));
                // we want to place the npcs in the middle of the screen
                float sby  = randomGridForHumans.screenBounds.y;
                float posy = NPCs[i - 1].transform.position.y;
                // if npcs are too low or to high
                if (Mathf.Abs(NPCs[i - 1].transform.position.y) > 0.33 * sby)
                {
                    // we randomly transform their positition to be more in the middle
                    // we don't care that they touch each other since this is a demo anyway
                    posy = UnityEngine.Random.Range(-sby * 0.5f, sby * 0.45f);
                    NPCs[i - 1].transform.position = new Vector2(NPCs[i - 1].transform.position.x, posy);
                }
                // assign velocity to npcs
                NPCs[i - 1].MinVelocity        = 1.0f;
                NPCs[i - 1].MaxVelocity        = 2.0f;
                NPCs[i - 1].AccelerationFactor = 0.3f;

                // give all npcs a unique id
                NPCs[i - 1].myID = i - 1;

                // these NPCs have a sign
                if (i < 20)
                {
                    // all of them have a hand
                    // we also assign them their own sorting order in the layer
                    // normal NPCs live in sorting order 1
                    // those with a sign live in 2 .. 22
                    // otherwise weird overlaps with the signs happen
                    NPCs[i - 1].transform.GetChild(1).GetComponent <SpriteRenderer>().enabled      = true;
                    NPCs[i - 1].transform.GetChild(1).GetComponent <SpriteRenderer>().sortingOrder = 1 + i;
                    NPCs[i - 1].transform.GetComponent <SpriteRenderer>().sortingOrder             = 1 + i;
                    // we have 7 different signs, one of them is the default one
                    // the other 6 are loaded here since they are called sign1, sign2, etc.
                    string whichSign = (i % 7).ToString();
                    // default sign is the 0th which is already loaded
                    if (i != 0)
                    {
                        string Loader = string.Concat("SmileyPictures/symbols/sign", whichSign);
                        Sprite sign   = Resources.Load <Sprite>(Loader);
                        NPCs[i - 1].transform.GetChild(2).GetComponent <SpriteRenderer>().enabled      = true;
                        NPCs[i - 1].transform.GetChild(2).GetComponent <SpriteRenderer>().sprite       = sign;
                        NPCs[i - 1].transform.GetChild(2).GetComponent <SpriteRenderer>().sortingOrder = 1 + i;
                    }
                }
                else
                {
                    // the other have no hand and no sign
                    NPCs[i - 1].transform.GetChild(1).GetComponent <SpriteRenderer>().enabled = false;
                    NPCs[i - 1].transform.GetChild(2).GetComponent <SpriteRenderer>().enabled = false;
                }
            }

            // infect 20
            for (int i = 0; i < 12; i++)
            {
                NPCs[UnityEngine.Random.Range(0, npcNumber)].SetInitialCondition(NPC.EXPOSED);
            }
        }