예제 #1
0
    IEnumerator GenerateSeedAfterSeconds(float s, int a, int b)
    {
        yield return(new WaitForSeconds(s));

        GameObject seed = (GameObject)Instantiate(matrixFloorSeedPrefab, seedT.position, seedT.rotation);

        seed.transform.parent = seedT;
        MatrixFloorSeed mfs = seed.GetComponentInChildren <MatrixFloorSeed>();

        mfs.SetSizeX(a);
        mfs.SetSizeZ(b);
        mfs.flowerPrefabIndex = Random.Range(0, FlowerManager.inst.flowerPrefabs.Length - 1);
        Color randColor = Utils.RandomColor();

        mfs.SetColor(randColor);
        AudioManager.inst.PlayTimerDing();
        canAcceptNumbers = true;
    }
예제 #2
0
    float colorTransitionSpeed = 5.5f;               // how fast do panels change
//	float getPanelsTimer = 0;
    public List <MatrixFloorSquare> GetPanels(MatrixFloorSeed seed)
    {
//		getPanelsTimer -= Time.deltaTime;
//		if (getPanelsTimer > 0) return new List<MatrixFloorSquare>();
//		getPanelsTimer = 0;
        // Which of the 4 corners is the player closest to?
        // How far (x,z) is the player away from that corner?
        //


        hiSquares.Clear();

        hiTimer = 0.1f;
        // first, player should be on top of a panel.

        MatrixFloorSquare playerPanel = PlayerOverPanel();

        // Note that getpanels is only called if PlayerActivePanel
        // and PlayerActivePanel only checks if MatrixFloorSeed is equipped.
        if (playerPanel)
        {
            if ((seed.sizeX > sizeX && seed.sizeX > sizeZ) || (seed.sizeZ > sizeX && seed.sizeZ > sizeZ))
            {
                // seed was too big for any orientation
                PlayerNowMessage.inst.Display("That seed (" + seed.sizeX + "," + seed.sizeZ + ") is too big for this farm (" + sizeX + "," + sizeZ + ").", Player.inst.transform.position);
                for (int i = 0; i < sizeX; i++)
                {
                    for (int j = 0; j < sizeZ; j++)
                    {
                        squares[i, j].blinking = true;
                    }
                }
//				getPanelsTimer = 5f;
                return(new List <MatrixFloorSquare>());
            }

            seedSizeMatchesFloorSquares = true;
            // which way was player facing?
            Vector3 xDir            = squares[1, 0].transform.position - squares[0, 0].transform.position;
            Vector3 zDir            = squares[0, 1].transform.position - squares[0, 0].transform.position;
            float   playerRotationY = Player.inst.transform.rotation.eulerAngles.y;
//			Debug.Log("roty:"+playerRotationY+", A xdir:"+Vector3.Angle(Player.inst.transform.forward,xDir)+",AzDir:"+Vector3.Angle(Player.inst.transform.forward, zDir));
            PlayerGridDirection playerDir = PlayerGridDirection.X;
            if (Vector3.Angle(Player.inst.transform.forward, xDir) < 45)
            {
                playerDir = PlayerGridDirection.X;
            }
            else if (Vector3.Angle(Player.inst.transform.forward, zDir) < 45)
            {
                playerDir = PlayerGridDirection.Z;
            }
            else if (Vector3.Angle(Player.inst.transform.forward, -xDir) < 45)
            {
                playerDir = PlayerGridDirection.x;
            }
            else if (Vector3.Angle(Player.inst.transform.forward, -zDir) < 45)
            {
                playerDir = PlayerGridDirection.z;
            }


            int startX   = 0;           // should be beteween 0 and sizeX - seedSizeX or seedSizeZ, depending on where player is.
            int startZ   = 0;
            int curSizeX = 0;
            int curSizeZ = 0;

            switch (playerDir)
            {
            case PlayerGridDirection.X:
//				Debug.Log("pos X");
                // Player forward (Z) was parallel with X axis, so flip x and z for the seed.
                // starting X should be playerPanel.x (closest panel to player)
                // starting Z should be playerpanel.z MINUS half of the seed X.
                startX   = Mathf.Min(sizeX - seed.sizeZ, playerPanel.positionX);
                startZ   = Mathf.Min(sizeZ - seed.sizeX, Mathf.Max(0, playerPanel.positionZ - Mathf.RoundToInt(seed.sizeX / 2)));
                curSizeX = seed.sizeZ;
                curSizeZ = seed.sizeX;
                break;

            case PlayerGridDirection.Z:
//				Debug.Log("pos Z");
                // Player forward (Z) was parallel with Z axis, the "normal" case.
                // starting X should be playerpanel.x MINUS half of the seed X.
                // starting Z should be playerPanel.z (closest panel to player)
                startX   = Mathf.Min(sizeX - seed.sizeX, Mathf.Max(0, playerPanel.positionX - Mathf.RoundToInt(seed.sizeX / 2)));
                startZ   = Mathf.Min(sizeZ - seed.sizeZ, playerPanel.positionZ);
                curSizeX = seed.sizeX;
                curSizeZ = seed.sizeZ;
                break;

            case PlayerGridDirection.x:
//				Debug.Log("neg x");
                // Player forward (Z) was parallel with negative X axis.
                // starting X should be sizeX - seedsizeX.
                // starting Z should be playerpanel.z MINUS half of the seed X.
                startX   = Mathf.Min(sizeX - seed.sizeZ, Mathf.Max(0, sizeX - seed.sizeZ + 1 - (sizeX - playerPanel.positionX)));
                startZ   = Mathf.Min(sizeZ - seed.sizeX, Mathf.Max(0, playerPanel.positionZ - Mathf.RoundToInt(seed.sizeX / 2)));
                curSizeX = seed.sizeZ;
                curSizeZ = seed.sizeX;
                break;

            case PlayerGridDirection.z:
//				Debug.Log("neg z");
                // Player forward (Z) was parallel with negative Z axis.
                // starting X should be sizeX - seedsizeX.
                // starting Z should be playerpanel.z MINUS half of the seed X.
                startX   = Mathf.Min(sizeX - seed.sizeX, Mathf.Max(0, playerPanel.positionX - Mathf.RoundToInt(seed.sizeX / 2)));
                startZ   = Mathf.Max(0, sizeZ - seed.sizeZ + 1 - (sizeZ - playerPanel.positionZ));
                curSizeX = seed.sizeX;
                curSizeZ = seed.sizeZ;
                break;

            default:
                break;
            }
//			Debug.Log("player dir;"+playerDir.ToString());

//			int playerY = Mathf.RoundToInt((Player.inst.transform.rotation.eulerAngles.y%360)/90f)*90; // 0, 90


            // Given that player is closest to X axis of grid
            // playersquare will be z = 0, x = [0,sizex]
            // so, we want the seed to start with X = playersquare.x - (int)seedsizex/2, and Z = 0

            // Given that player is closest to Z axis of grid
            // playersquare will be x = 0, z = [0,sizeZ]
            // so, we want the seed to start with X = 0, Z = playersquare.z - int(seedsizex/2), and flip x and z

            // Given that player is closest to TOP x axis of grid
            // playersquare will be x = sizeX, z = [0,sizeZ]
            // so, we want the seed to start with X = 0, Z = playersquare.z - int(seedsizex/2), and flip x and z

//			Debug.Log("startx:"+ startX +",startz:"+startZ+", xz;"+curSizeX+","+curSizeZ);
            for (int i = 0; i < curSizeX; i++)
            {
                for (int j = 0; j < curSizeZ; j++)
                {
                    int x = startX + i;
                    int z = startZ + j;
                    if (x < sizeX && z < sizeZ)                      // inside my bounds?
                    {
                        squares[x, z].blinking = false;

                        hiSquares.Add(squares[x, z]);
                        if (squares[x, z].planted == true)                         // fail because one plot is already planted
                        {
                            seedSizeMatchesFloorSquares = false;
                        }
                    }
                    else                         // fail out of range
//						Debug.Log("out of range;"+x+","+z);
                    {
                        seedSizeMatchesFloorSquares = false;
                    }
                }
            }
        }
        foreach (MatrixFloorSquare sq in squares)
        {
            if (!sq.planted && !hiSquares.Contains(sq))
            {
                sq.targetColor = floorColor;
                sq.blinking    = false;
            }
        }
        foreach (MatrixFloorSquare mf in hiSquares)
        {
            if (!seedSizeMatchesFloorSquares)
            {
                if (!mf.planted)
                {
                    mf.blinking = true;
                }
            }
            else
            {
                mf.targetColor = seed.seedColor;
            }
        }
        if (hiSquares.Count == 0)
        {
            seedSizeMatchesFloorSquares = false;
        }
        if (seedSizeMatchesFloorSquares)
        {
            PlayerNowMessage.inst.Display("Click to plant the seed here.", Player.inst.transform.position);
        }
        return(hiSquares);
    }