Ejemplo n.º 1
0
    void Start()
    {
        MapGenerator = gameObject.GetComponent <MapGenerator>();
        // transform.position = new Vector3(0.84252352941176470588235294117647f * (MapGenerator.xSize / 2), 0.72023225806451612903225806451613f * (MapGenerator.ySize / 2), -3);
        factory.Add(new Vector2Int((int)((float)MapGenerator.xSize / 2), (int)((float)MapGenerator.ySize / 2)), 1);
        ScoreCore.mainSpawner = GameObject.FindGameObjectWithTag("MainSpawner");
        Vector2 pos = Cell.getGlobalCoords(new Vector2Int((int)((float)MapGenerator.xSize / 2), (int)((float)MapGenerator.ySize / 2)), 55f / 64f);

        transform.position = new Vector3(pos.x, pos.y, -3);
    }
Ejemplo n.º 2
0
    private void Start()
    {
        grassFactory.generateGrid(new Vector2Int(xSize, ySize));
        //CreateShape();

        //genPatch(new Vector2Int(20, 20), 7,50, 0);

        genRocks(5);

        //genRocks();

        int        size;
        Vector2Int pos   = new Vector2Int(0, 0);
        Vector2Int delta = new Vector2Int(1, -4);
        Vector2Int gPos  = new Vector2Int(xSize / 2, ySize / 2);

        for (int i = 0; i < 5 + Random.Range(0, 2); i++)
        {
            size  = 1 + Random.Range(0, 3);
            pos.x = Random.Range(0, xSize);
            pos.y = Random.Range(0, ySize);
            genLooseSpot(pos, new Vector2Int(1, size), 9);
            genLooseSpot(pos, new Vector2Int(1, size), 9);
        }
        for (int i = 0; i < 3 + Random.Range(0, 2); i++)
        {
            do
            {
                size  = 2 + Random.Range(0, 4);
                pos.x = Random.Range(0, xSize);
                pos.y = Random.Range(0, ySize);
            } while (Mathf.Abs(pos.x - gPos.x) < (size - 2) || Mathf.Abs(pos.y - gPos.y) < 3);

            genSpot(pos + delta, new Vector2Int(1, size + 4), 8);

            genSpot(pos, new Vector2Int(2, size), 7);
            if (Random.Range(0, 2) == 1)
            {
                // do poprwaienia
                //genPatch(pos, 7, xSize + ySize, Random.Range(0, 7));
            }
        }

        for (int i = 0; i < 5; i++)
        {
            for (int j = 0; j < 5; j++)
            {
                if (Mathf.Pow(i, 2) + Mathf.Pow(j, 2) < 25)
                {
                    // Water condition
                    pos = new Vector2Int(i, j);
                    grassFactory.DestroyCell(grassFactory.Find(gPos + pos));
                    grassFactory.Add(gPos + pos, Random.Range(0, 2)).transform.localRotation = Quaternion.Euler(0, 0, 60 * Random.Range(1, 7));

                    pos.x = -pos.x;
                    grassFactory.DestroyCell(grassFactory.Find(gPos + pos));
                    grassFactory.Add(gPos + pos, Random.Range(0, 2)).transform.localRotation = Quaternion.Euler(0, 0, 60 * Random.Range(1, 7));

                    pos.y = -pos.y;
                    grassFactory.DestroyCell(grassFactory.Find(gPos + pos));
                    grassFactory.Add(gPos + pos, Random.Range(0, 2)).transform.localRotation = Quaternion.Euler(0, 0, 60 * Random.Range(1, 7));

                    pos.x = -pos.x;
                    grassFactory.DestroyCell(grassFactory.Find(gPos + pos));
                    grassFactory.Add(gPos + pos, Random.Range(0, 2)).transform.localRotation = Quaternion.Euler(0, 0, 60 * Random.Range(1, 7));
                }
            }
        }
        //CellFactory.cellCount = 0;
        //genSpot(new Vector2Int(10, 9), new Vector2Int(1, 6), 8);//genRocks(5);
    }
Ejemplo n.º 3
0
    void Update()
    {
        if (switch1)
        {
            switch1 = false;
            CellFactory.cellCount  = 0;
            ScoreCore.cellCount    = new int[5];
            ScoreCore.cellCount[0] = 0;
            ScoreCore.Prices[0]    = 8 * ScoreCore.cellCount[0];
            ScoreCore.Prices[2]    = 6 * ScoreCore.cellCount[2];
            ScoreCore.Prices[3]    = 3 * ScoreCore.cellCount[3];
            ScoreCore.Prices[4]    = 8 * ScoreCore.cellCount[4];
            Camera.main.GetComponent <ScoreCore>().PriceDisplayers[0].text = ScoreCore.Prices[0].ToString() + "$";
            Camera.main.GetComponent <ScoreCore>().PriceDisplayers[2].text = ScoreCore.Prices[2].ToString() + "$";
            Camera.main.GetComponent <ScoreCore>().PriceDisplayers[3].text = ScoreCore.Prices[3].ToString() + "$";
            Camera.main.GetComponent <ScoreCore>().PriceDisplayers[4].text = ScoreCore.Prices[4].ToString() + "$";
        }

        //While holding LMB, object follows the mouse position
        if (IsSelected)
        {
            ObjectFollowsMouse(gameObject);
        }

        //When LMB is relesed, (drag ends)  do the following
        if (IsSelected && Input.GetMouseButtonUp(0))
        {
            IsSelected = false;
            Vector2 WorldPos = Camera.main.ScreenToWorldPoint(new Vector2(Input.mousePosition.x, Input.mousePosition.y));

            Vector2Int hPos = Cell.getHexCoords(WorldPos, 55f / 64f);



            //Checking if position is occupied and if player has enough cash to build the cell
            if ((Factory.Find(hPos) == null && ScoreCore.Cash >= ScoreCore.Prices[SpawnedIdentifier] && grassFactory.Find(hPos).buildable) && Input.mousePosition.y > Camera.main.pixelWidth / 7 && Silos.getAvailableBuildings() > CellFactory.cellCount) // > (Camera.main.pixelHeight/10)
            {
                CellFactory.cellCount++;

                ScoreCore.cellCount[SpawnedIdentifier]++;

                Factory.Add(hPos, SpawnedIdentifier);
                GameObject.Instantiate(Resources.Load <GameObject>("BuildParticles") as GameObject, Cell.getGlobalCoords(Cell.getHexCoords(WorldPos, 55f / 64f), 55f / 64f), Quaternion.identity);

                //Charging for purchase
                ScoreCore.Cash -= ScoreCore.Prices[SpawnedIdentifier];

                //Debug.Log(ScoreCore.cellCount[0]);

                //Increase Price of thebuilding built
                ScoreCore.Prices[0] = 8 * ScoreCore.cellCount[0];
                ScoreCore.Prices[2] = 6 * ScoreCore.cellCount[2];
                ScoreCore.Prices[3] = 3 * ScoreCore.cellCount[3];
                ScoreCore.Prices[4] = 8 * ScoreCore.cellCount[4];

                Camera.main.GetComponent <ScoreCore>().PriceDisplayers[0].text = ScoreCore.Prices[0].ToString() + "$";
                Camera.main.GetComponent <ScoreCore>().PriceDisplayers[2].text = ScoreCore.Prices[2].ToString() + "$";
                Camera.main.GetComponent <ScoreCore>().PriceDisplayers[3].text = ScoreCore.Prices[3].ToString() + "$";
                Camera.main.GetComponent <ScoreCore>().PriceDisplayers[4].text = ScoreCore.Prices[4].ToString() + "$";

                Debug.Log($"Info cell: {CellFactory.cellCount}");
            }



            //Returning the draggable to origin position
            gameObject.transform.localPosition = ReturnPosition;
        }
    }