Beispiel #1
0
        public TileScript GrabTile(int row, int col)
        {
            TileScript tile = null;

            if ((row < gridWidth && col < gridHeight) && (row >= 0 && col >= 0))
            {
                tile = grid[(gridWidth * col) + row];
            }

            return(tile);
        }
Beispiel #2
0
        public void SetTileSpace(TileScript tile)
        {
            tile.spaceInUse = true;
            for (int i = 0; i < listOfBlockedOffAreas.Count; i++)
            {
                int row = (int)listOfBlockedOffAreas[i].x + tile.GetRowNum();
                int col = (int)listOfBlockedOffAreas[i].y + tile.GetColNum();

                TileScript newTile = GrabTile(row, col);

                if (newTile != null)
                {
                    newTile.spaceInUse = true;
                }
            }
        }
Beispiel #3
0
        public void ExposeTileArea(TileScript tile)
        {
            tile.TurnOnTile();
            for (int i = 0; i < listOfBlockedOffAreas.Count; i++)
            {
                int row = (int)listOfBlockedOffAreas[i].x + tile.GetRowNum();
                int col = (int)listOfBlockedOffAreas[i].y + tile.GetColNum();

                TileScript newTile = GrabTile(row, col);

                if (newTile != null)
                {
                    newTile.TurnOffTile();
                }
            }
        }
Beispiel #4
0
        void PlaceStructure(TileScript tile)
        {
            if (currentMoney >= structureToPlace.cost)
            {
                structureToPlace.isActive = true;

                currentMoney  -= structureToPlace.cost;
                moneyText.text = "" + currentMoney;

                structureToPlace.ResetStructure();
                structureToPlace.Build();

                structureToPlace = null;

                groundManager.SetTileSpace(tile);
                groundManager.TurnOffTiles();
            }
            else
            {
                Debug.Log("Not Enough Money" + currentMoney + "/" + structureToPlace.cost);
            }
        }
Beispiel #5
0
        // Update is called once per frame
        void Update()
        {
            CameraPan();
            if (structureToPlace != null)
            {
                bool hitGround   = false;
                bool hasHitATile = false;

                TileScript tile = new TileScript();

                Vector3 correctDir = mousePosWorld - mainCam.transform.position;

                RaycastHit[] hit;
                hit = Physics.RaycastAll(mousePosWorld, correctDir, cam.farClipPlane);

                for (int i = 0; i < hit.Length; i++)
                {
                    if (hit[i].transform.gameObject == structureToPlace.gameObject)
                    {
                        continue;
                    }

                    if (hit[i].transform.CompareTag("Ground"))
                    {
                        pointOnGround = hit[i].point;
                        hitGround     = true;
                    }
                    else if (hit[i].transform.CompareTag("Structure"))
                    {
                        hitGround = false;
                        continue;
                    }
                    else if (hit[i].transform.CompareTag("Tile") && !hasHitATile)
                    {
                        hasHitATile = true;
                        tile        = hit[i].transform.GetComponent <TileScript>();
                        groundManager.ExposeTileArea(tile);

                        //if (!hitGround)
                        //{
                        //    tile.spaceInUse = true;
                        //}
                    }
                }

                if (hitGround && hasHitATile)
                {
                    structureToPlace.transform.position = tile.transform.position;
                }
                else
                {
                    structureToPlace.transform.position = new Vector3(10000, 0, 0);
                }

                if (Input.GetMouseButtonDown(0) && hitGround)
                {
                    if (hasHitATile && !tile.spaceInUse)
                    {
                        PlaceStructure(tile);
                    }
                }
            }
        }