Ejemplo n.º 1
0
        private bool IsCellEmptyLot(RaycastHit hit)
        {
            var index = new Vector2(hit.collider.transform.position.x, hit.collider.transform.position.z)
                        .GetAsIndex(new GridInfo {
                CellSize = Vector2.one, Width = this._width
            });

            return((BitBoardManager.GetFreeDirtCellMask() >> index & 1L) == 1L);
        }
Ejemplo n.º 2
0
        private void BuildBoard()
        {
            for (var i = 0; i < this._width * this._height; i++)
            {
                var tile = this.InstantiateTiles(i);
                this.SetTileName(tile, i);
                BitBoardManager.SetBitInBoard((BoardType)Enum.Parse(typeof(BoardType), tile.tag), i);
            }

            this.InvokeRepeating("PlantEnvironment", 1f, this._plantingSpeed);
        }
Ejemplo n.º 3
0
        private void PlantEnvironment()
        {
            var index = Random.Range(0, this._width * this._height);

            if (!this._environmentPrefabs.Any() ||
                (BitBoardManager.GetFreeDirtCellMask() & 1L << index) == 0)
            {
                return;
            }

            var position = index.GetAsVector2(new GridInfo {
                CellSize = Vector2.one, Width = this._width
            });
            var environment = Instantiate(this._environmentPrefabs[Random.Range(0, this._environmentPrefabs.Count)],
                                          new Vector3(position.x, 0, position.y), Quaternion.identity);

            BitBoardManager.SetBitInBoard(BoardType.Woods, index);
        }
Ejemplo n.º 4
0
        private void SpawnPlayerHouse()
        {
            var ray = Camera.main.ScreenPointToRay(Input.mousePosition);

            if (this._housePrefabs?.Any() != true || !Input.GetMouseButtonDown(0) ||
                !Physics.Raycast(ray, out var hit) || !this.IsCellEmptyLot(hit))
            {
                return;
            }

            this.InstantiateHouse(hit);

            BitBoardManager.SetBitInBoard(BoardType.PlayerBoard,
                                          new Vector2(hit.collider.transform.position.x, hit.collider.transform.position.z)
                                          .GetAsIndex(new GridInfo {
                CellSize = Vector2.one, Width = this._width
            }));
        }