Example #1
0
    private void initializePlayers()
    {
        currentPlayers = new List<GameObject>();
        GameObject[] players = GameObject.FindGameObjectsWithTag("Player");

        GameObject ghostPlayer = null;

        for (int i = 0; i < players.Length; ++i)
        {
            int playerReadyArrayIndex = players[i].GetComponent<Human>().playerNum - 1;

            if (!isPlayerReadyArray[playerReadyArrayIndex])
            {
                players[i].SetActive(false);
                Camera.main.GetComponent<NewCameraBehavior>().targets.Remove(players[i]);
            }
            else
            {
                if (playerReadyArrayIndex == ghostPlayerIndex)
                {
                    if (!isGhostAI)
                    {
                        ghostPlayer = (GameObject)GameObject.Instantiate(ghostPrefab, players[i].transform.position, players[i].transform.rotation);
                        ghostPlayer.GetComponent<Ghost>().playerNum = players[i].GetComponent<Human>().playerNum;
                        ghostPlayer.gameObject.tag = "Ghost";

                        if (!CatMode)
                        {
                            ghostPlayer.GetComponentInChildren<Text>().text = "P" + (ghostPlayerIndex + 1);
                        }
                        else
                        {
                            ghostPlayer.GetComponentInChildren<Text>().text = "MEOW";
                        }

                        ghostPlayer.GetComponentInChildren<FadeOnTimeScale1>().timeScale = .45f;
                        Camera.main.gameObject.GetComponent<NewCameraBehavior>().targets.Remove(players[i]);
                        Destroy(players[i]);
                    }
                    else
                    {
                        ghostPlayer = (GameObject)GameObject.Instantiate(ghostAIPrefab, players[i].transform.position, players[i].transform.rotation);
                        Camera.main.gameObject.GetComponent<NewCameraBehavior>().targets.Remove(players[i]);
                        Destroy(players[i]);
                    }
                }
                else
                {
                    currentPlayers.Add(players[i]);
                }
            }
        }

        if (_SpriteSorter != null)
        {
            GameObject[]sortedPlayerList = new GameObject[4];

            foreach (GameObject playerObject in currentPlayers)
            {
                _SpriteSorter.AddToAllLists(playerObject.GetComponent<SpriteRenderer>());

                //sorts player list
                if (playerObject.name.Contains("1"))
                    sortedPlayerList[0] =  playerObject;
                else if (playerObject.name.Contains("2"))
                    sortedPlayerList[1] = playerObject;
                else if (playerObject.name.Contains("3"))
                    sortedPlayerList[2] = playerObject;
                else if (playerObject.name.Contains("4"))
                    sortedPlayerList[3] = playerObject;
            }

            currentPlayers = sortedPlayerList.ToList();

        }

        currentPlayers[ghostPlayerIndex] = ghostPlayer;

        for (int i = 0; i < currentPlayers.Count; i++)
        {
            if(currentPlayers[i] != null && currentPlayers[i].gameObject.tag != "Ghost")
            {
                Human playerHuman = currentPlayers[i].GetComponent<Human>();

                if(!SceneStartedInEditor)
                    playerHuman.IsFemaleWizard = isFemaleCharacter[i];

                if (playerColorPalettes[i] == null)
                {
                    if (playerHuman.IsFemaleWizard)
                        playerColorPalettes[i] = womanColorPalettes[i];
                    else
                        playerColorPalettes[i] = oldieColorPalettes[i];
                }

                VerifyCorrectAnimController(i);

                PaletteSwapper currentPlayer_PS = currentPlayers[i].GetComponent<PaletteSwapper>();
                currentPlayer_PS.currentPalette = playerColorPalettes[i];
                currentPlayer_PS.SwapColors_Custom(currentPlayer_PS.currentPalette);

                int targetPaletteIndex = (int)char.GetNumericValue(currentPlayer_PS.currentPalette.name[0]);
                playerHuman.MainColor = currentPlayer_PS.currentPalette.newPalette[targetPaletteIndex];
                playerNumText[i].color = playerHuman.MainColor;

                currentPlayers[i].GetComponent<SpriteRenderer>().material.SetColor("_OColor", playerNumText[i].color);

                playerHeartUIManagers[i].OccludeMat = currentPlayers[i].GetComponent<SpriteRenderer>().material;
                playerHeartUIManagers[i].SetHeartMaterial();
            }
        }

        currentGhostPlayer = ghostPlayer;
        currentPlayers.RemoveAll(item => item == null);
        Camera.main.gameObject.GetComponent<NewCameraBehavior>().targets.Add(ghostPlayer);
    }
Example #2
0
	// You can choose to have random items be created or pass in a chosen list.
	// If no list is provided, then random items are chosen.
	// This gets called from ItemSpawner after it spawns this itemStorer
	// gameObject.
	public void ItemSetup(bool large, int areaNumber, GameObject[] manualItemsChosen = null)
	{
		myAreaNumber = areaNumber;
		if(manualItemsChosen == null || manualItemsChosen.Count() == 0)
		{
			if(!large) // A small itemStorer was created.
			{
				// Half values.
				transform.localScale = Vector3.one * 0.5f;
				_totalItemsToCarry = Random.Range(1, 3); // Hold up to 2 when small.
				health = Mathf.RoundToInt(health * 0.5f);
			}
			else _totalItemsToCarry = Random.Range(3, 5); // Hold up to 4 when large.
			// More random choices with a higher appear rate. Very_High = 5 and
			// Very_Low = 1
			_maxRandomToChooseFrom = (int)Manager_Game.ItemAppearRate;
			itemsCanDrop = new List<GameObject>();
			for(int i = 0; i < _maxRandomToChooseFrom || itemsCanDrop.Count == _totalItemsToCarry; i++)
			{
				if(Random.value > 0.6f)
				{
					itemsCanDrop.Add(Manager_Game.instance.ICPrefabs[Random.Range(0, Manager_Game.instance.ICPrefabs.Count)]);
					continue;
				}
				if(Random.value > 0.5f)
				{
					itemsCanDrop.Add(Manager_Game.instance.ITPrefabs[Random.Range(0, Manager_Game.instance.ITPrefabs.Count)]);
					continue;
				}
				itemsCanDrop.Add(Manager_Game.instance.IWPrefabs[Random.Range(0, Manager_Game.instance.IWPrefabs.Count)]);
			}
		}
		else // Manually items chosen to choose from
		{
			List<GameObject> itemsToCreate = manualItemsChosen.ToList();

			if(!large)
			{
				// If small we will remove half of the amount of items we have.
				transform.localScale = Vector3.one * 0.5f;
				if(itemsToCreate.Count > 1)
				{
					_totalItemsToCarry = Mathf.RoundToInt(itemsToCreate.Count / 2);
					for(int i = 0; i < _totalItemsToCarry; i++)
					{
						if(i != _totalItemsToCarry - 1)
						{
							// Random chance of removing this one if we aren't at the
							// end.
							if(Random.value > 0.5f)
								itemsToCreate.RemoveAt(i);
						}
						else itemsToCreate.RemoveAt(i);
					}
				}
			}
			// Large so keep all items chosen.
			else _totalItemsToCarry = itemsToCreate.Count;
			itemsCanDrop = itemsToCreate;
		}
		GetComponent<Rigidbody>().drag = large ? 20 : 10;
	}
    void BuildPlatform(bool buildMidSections)
    {
        //Set Art
        switch (selectedPlatformArt)
        {
            case 0:
            platformEndSprite = Resources.Load<Sprite>("Blue Metal Platform_H_End");
            break;
            default:
            break;
        }

        //Create Parent Object
        GameObject platformParent = new GameObject();
        platformParent.name = "Platform";

        //Build Platform Ends
        GameObject endLeft = null, endRight = null, endTop = null, endBottom = null;

		//For horizontal platforms.
        if (orientation == 0)
        {
            Object platformHPrefab = Resources.Load("PlatformH");

            if (platformEndLeft)
            {
                endLeft = (GameObject)PrefabUtility.InstantiatePrefab(platformHPrefab);
                endLeft.name = "Platform End Left";
                endLeft.transform.SetParent(platformParent.transform);
                endLeft.transform.localPosition = new Vector2((-platformWidth / 2) + 0.5f, 0);
                endLeft.transform.FindChild("Platform").GetComponent<SpriteRenderer>().sprite = platformEndSprite;
                endLeft.transform.FindChild("Platform Lit").GetComponent<SpriteRenderer>().sprite = platformEndSprite;
                endLeft.transform.FindChild("Platform Lit").GetComponent<SpriteRenderer>().sprite = platformEndSprite;
            }

            else
            {
                endLeft = new GameObject();
                endLeft.name = "Platform End Left";
                endLeft.tag = "Platform";
                endLeft.transform.SetParent(platformParent.transform);
                endLeft.transform.localPosition = new Vector2((-platformWidth / 2), 0);
            }

            if (platformEndRight)
            {
                endRight = (GameObject)PrefabUtility.InstantiatePrefab(platformHPrefab);
                endRight.name = "Platform End Right";
                endRight.transform.SetParent(platformParent.transform);
                endRight.transform.localPosition = new Vector2((platformWidth / 2) - 0.5f, 0);
                endRight.transform.localScale = new Vector3(-1, 1, 1);
                endRight.transform.FindChild("Platform").GetComponent<SpriteRenderer>().sprite = platformEndSprite;
                endRight.transform.FindChild("Platform Lit").GetComponent<SpriteRenderer>().sprite = platformEndSprite;
            }

            else
            {
                endRight = new GameObject();
                endRight.name = "Platform End Right";
                endRight.tag = "Platform";
                endRight.transform.SetParent(platformParent.transform);
                endRight.transform.localPosition = new Vector2((platformWidth / 2), 0);
            }
        }

        // For vertical platforms.
        else
        {
            endTop = new GameObject();
            endTop.name = "Platform End Top";
            endTop.tag = "Platform";
            endTop.transform.SetParent(platformParent.transform);
            endTop.transform.localPosition = new Vector2((-platformWidth / 2), 0);

            endBottom = new GameObject();
            endBottom.name = "Platform End Bottom";
            endBottom.tag = "Platform";
            endBottom.transform.SetParent(platformParent.transform);
            endBottom.transform.localPosition = new Vector2((platformWidth / 2), 0);
        }

        //Build Doors
        if (doorCount > 0)
        {
            // For horizontal doors.
            if (orientation == 0)
            {
                Object interiorDoorHPrefab = Resources.Load("InteriorDoorH");

                //Create Parent Object
                GameObject doorsParent = new GameObject("Doors");
                doorsParent.transform.SetParent(platformParent.transform);

                for (int i = 0; i < doorCount; i++)
                {
                    GameObject d = (GameObject)PrefabUtility.InstantiatePrefab(interiorDoorHPrefab);
                    d.name = "InteriorDoorH" + (i + 1);
                    d.transform.SetParent(doorsParent.transform);
                    d.transform.localPosition = new Vector3(0, 0, -1);
                }
            }

			// For vertical doors.
            else
            {
                Object interiorDoorVPrefab = Resources.Load("InteriorDoorV");

                //Create Parent Object
                GameObject doorsParent = new GameObject("Doors");
                doorsParent.transform.SetParent(platformParent.transform);

                for (int i = 0; i < doorCount; i++)
                {
                    GameObject d = (GameObject)PrefabUtility.InstantiatePrefab(interiorDoorVPrefab);
                    d.name = "InteriorDoorV" + (i + 1);
                    d.transform.SetParent(doorsParent.transform);
                    d.transform.localPosition = new Vector3(0, 0, -1);
                    d.transform.Rotate(0, 0, 90);
                }
            }
        }

        List<GameObject> doors = new List<GameObject>();

        if (platformParent.transform.FindChild("Doors"))
        {
            foreach (Transform child in platformParent.transform.FindChild("Doors"))
                doors.Add(child.gameObject);
        }

        // Order doors and platform ends
        GameObject[] orderedObjects = new GameObject[0];
        int objArrayPos = 0;

        //Add Platform Ends to ordered array

        if (orientation == 0)
        {
            System.Array.Resize(ref orderedObjects, orderedObjects.Length + 1);
            orderedObjects[objArrayPos] = endLeft;
            objArrayPos++;

            System.Array.Resize(ref orderedObjects, orderedObjects.Length + 1);
            orderedObjects[objArrayPos] = endRight;
            objArrayPos++;
        }

        else
        {
            System.Array.Resize(ref orderedObjects, orderedObjects.Length + 1);
            orderedObjects[objArrayPos] = endTop;
            objArrayPos++;

            System.Array.Resize(ref orderedObjects, orderedObjects.Length + 1);
            orderedObjects[objArrayPos] = endBottom;
            objArrayPos++;
        }

        //Add doors to ordered array
        if (doors.Count > 0)
        {
            foreach (GameObject door in doors)
            {
                System.Array.Resize(ref orderedObjects, orderedObjects.Length + 1);
                orderedObjects[objArrayPos] = door;
                objArrayPos++;
            }
        }

        //Order array from left to right
        orderedObjects = orderedObjects.OrderBy(go => go.transform.position.x).ToArray();

        //Get leftmost and rightmost objects
        GameObject objectLeft = orderedObjects[0];
        GameObject objectRight = orderedObjects[orderedObjects.Length - 1];

        float start, end;

        if (objectLeft.GetComponent<Collider2D>())
            start = objectLeft.GetComponent<Collider2D>().bounds.max.x;

        else
            start = objectLeft.transform.position.x;

        if (objectRight.GetComponent<Collider2D>())
            end = objectRight.GetComponent<Collider2D>().bounds.min.x;

        else
            end = objectRight.transform.position.x;

        float difference = end - start;

        //Remove End objects from array
        List<GameObject> o = orderedObjects.ToList();
        o.RemoveAt(0);
        o.RemoveAt(o.Count - 1);

        orderedObjects = o.ToArray();

        ////Position Doors and Ends
        foreach (GameObject orderedObject in orderedObjects)
        {
            float objectSizeX = orderedObject.GetComponent<Collider2D>().bounds.size.x;
            float objectExtentsX = orderedObject.GetComponent<Collider2D>().bounds.extents.x;
            float totalObjectLength = objectSizeX * orderedObjects.Length;
            float leftOverSpace = difference - totalObjectLength;

            if (orientation == 0)
            {
                orderedObject.transform.position = new Vector3(start + objectExtentsX + (leftOverSpace / (orderedObjects.Length + 1)), orderedObject.transform.position.y, orderedObject.transform.position.z);
                start = orderedObject.GetComponent<Collider2D>().bounds.max.x;
            }

            else
            {
                orderedObject.transform.position = new Vector3(start + objectExtentsX + 0.15f + (leftOverSpace / (orderedObjects.Length + 1)), orderedObject.transform.position.y, orderedObject.transform.position.z);
                start = orderedObject.GetComponent<Collider2D>().bounds.max.x;
            }
        }

        if (orientation == 1)
            platformParent.transform.Rotate(0, 0, -90);

        if (buildMidSections)
            BuildPlatformMidSections(platformParent);

        //Parent to room
        if (selectedRoom)
        {
            platformParent.transform.SetParent(selectedRoom.transform);
            platformParent.transform.localPosition = new Vector3(0, 0, 0);
        }


        Selection.activeGameObject = platformParent;
    }