private void ResetGrabbedObject()
 {
     state                 = Mode.EMPTY;
     currentCell           = null;
     currentTower          = null;
     currentTowerRenderer  = null;
     currentTowerArchetype = null;
 }
Example #2
0
 // Update is called once per frame
 void SetupView()
 {
     starNumberText.text = PersistentDataManager.Instance.totalStar.ToString();
     foreach (StageInfo stageInfo in LevelManager.Instance.stageInfoList)
     {
         GameObject stageObject = Instantiate(stagePrefab, stageTable);
         StageCell  stageCell   = stageObject.GetComponent <StageCell>();
         stageCell.InitWithStageInfo(stageInfo);
     }
 }
    private void Update()
    {
        if (state == Mode.HOLDING)
        {
            var currentPos = MousePositionToGameWorldPosition();
            currentTower.transform.position = currentPos;

            foreach (var cell in stage.Layout)
            {
                if (currentPos.x >= cell.BottomLeft.x && currentPos.x <= cell.TopRight.x && currentPos.y >= cell.BottomLeft.y && currentPos.y <= cell.TopRight.y)
                {
                    if (currentCell != null)
                    {
                        currentCell.UnHighlight();
                    }

                    currentTowerRenderer.color = originalColor * legalPlacementTint;
                    currentCell       = cell;
                    hoveringValidCell = true;
                    break;
                }

                hoveringValidCell = false;
            }

            if (hoveringValidCell)
            {
                currentCell.Highlight(Color.yellow);

                if (Input.GetMouseButtonDown(0) && TowerCurrency.Instance.Currency >= currentTowerArchetype.cost)
                {
                    currentTower.transform.position = currentCell.Center;
                    currentTowerRenderer.color      = originalColor;
                    currentCell.UnHighlight();

                    TowerCurrency.Instance.ConsumeCurrency(currentTowerArchetype.cost);

                    OnTowerPlaced?.Invoke(currentTowerArchetype.type, currentTower);

                    ResetGrabbedObject();
                }
                else
                {
                    currentTowerRenderer.color = originalColor * legalPlacementTint;
                }
            }
            else
            {
                currentTowerRenderer.color = originalColor * illegalPlacementTint;
            }
        }
    }
Example #4
0
    public void CreateNewStage()
    {
        for (int x = 0; x < stageSize; x++)
        {
            for (int y = 0; y < stageSize; y++)
            {
                StageCell cell = new StageCell(x, y, StageCellType.None);

                GameObject editTile = instantiate(editTilePrefab, transform);
                editTile.name = "tile(" + x + "," + y + ")";
                SetTilePosition(editTile, x, y);

                stageTiles.Add(editTile.GetComponent <StageEditTile>());
            }
        }
    }
Example #5
0
    void CreateTile(int x, int y, StageCellType type)
    {
        StageCell cell = new StageCell(x, y, type);

        GameObject editTile = Instantiate(editTilePrefab, transform);

        editTile.name = "tile(" + x + "," + y + ")";
        SetTilePosition(editTile, x, y);

        StageEditTile tile = editTile.GetComponent <StageEditTile>();

        tile.SetCell(cell);
        stageTiles.Add(tile);

        GameObject child = GetTileTypePrefab(type);

        if (child != null)
        {
            tile.EditType(type, child);
        }
    }
Example #6
0
    public void AddRoute(StageCell cell)
    {
        if (IsUsedForRoute(cell))
        {
            RemoveLastRouteIfCan(cell);
        }
        else
        {
            StageCell lastCell = route.Last();
            Vector2 diffPosition = cell.Position() - lastCell.Position();
            if (Mathf.Abs(diffPosition.x) <= 1 && Mathf.Abs(diffPosition.y) <= 1)
            {
                route.Add(cell);
                cell.SetSelectColor();

                if (routeCount != 1)
                {
                    lastCell.SetArrow(diffPosition);
                }
            }
        }
    }
Example #7
0
    public bool playStage(Stage stage)
    {
        cleanBoard();

        int length = stage.boardLength;

        float         boardSize  = length;
        float         size       = 1;
        CameraHandler mainCamera = Camera.main.GetComponent <CameraHandler>();

        mainCamera.setCameraDistance(boardSize);

        for (int cellId = 0; cellId < stage.board.Length; cellId++)
        {
            StageCell cell = stage.board[cellId];
            InstantiateEntity(cell.type, cell.position, size);
        }
        player     = InstantiateEntity(stage.playerType, stage.playerPosition, size);
        player.tag = "Player";

        buildBoundries(stage);

        return(true);
    }
Example #8
0
 public void CreateRoute(StageCell startCell)
 {
     route = new List<StageCell>();
     route.Add(startCell);
 }
Example #9
0
 private bool IsUsedForRoute(StageCell cell)
 {
     return route.Contains(cell);
 }
Example #10
0
    public void RemoveLastRouteIfCan(StageCell cell)
    {
        StageCell lastCell = route.Last();
        if (lastCell != cell) {return;}

        route.Remove(cell);
        cell.UnsetSelectColor();
    }
Example #11
0
    public void MoveTo(StageCell stageCell, System.Func<Vector3, Vector2> convertToCanvasPosition, bool movePosition = true)
    {
        this.cell = stageCell;

        hpLabel.MoveTo(convertToCanvasPosition(cell.PositionInWorld()));

        if (movePosition)
        {
            transform.position = cell.PositionInWorld();
        }
    }
Example #12
0
    bool CheckCellConnection(StageCell fromCell, StageCell toCell)
    {
        Vector3 origin = fromCell.Position;
        Vector3 destination = toCell.Position;

        Vector3 diff = destination - origin;
        Vector3 direction = diff.normalized;
        float distance = diff.magnitude;

        RaycastHit hit;
        if (Physics.Raycast(origin, direction, out hit, distance)) {
            return false;
        }
        else {
            return true;
        }
    }
Example #13
0
    void Awake()
    {
        int bottomLeftCell_x = Mathf.FloorToInt(BottomLeftCellPosition.x);
        int bottomLeftCell_z = Mathf.FloorToInt(BottomLeftCellPosition.z);

        int topRightCell_x = Mathf.FloorToInt(TopRightCellPosition.x);
        int topRightCell_z = Mathf.FloorToInt(TopRightCellPosition.z);

        mNumberOfColumns = ((topRightCell_x - bottomLeftCell_x) / CellSize) + 1;
        mNumberOfRows = ((topRightCell_z - bottomLeftCell_z) / CellSize) + 1;

        // Create all cells
        mCells = new StageCell[mNumberOfColumns, mNumberOfRows];
        for (int c=0; c<mNumberOfColumns; c++) {
            for (int r=0;r<mNumberOfRows; r++) {
                StageCell cell = new StageCell();
                cell.Position = new Vector3(bottomLeftCell_x + (c * CellSize), 0, bottomLeftCell_z + (r * CellSize));
                cell.North = null;
                cell.South = null;
                cell.West = null;
                cell.East = null;

                mCells[c, r] = cell;
            }
        }
        // Link cells
        for (int c=0; c<mNumberOfColumns; c++) {
            for (int r=0; r<mNumberOfRows; r++) {
                StageCell cell = mCells[c, r];

                // link north cell
                if (r + 1 < mNumberOfRows) {
                    StageCell northCell = mCells[c, r + 1];
                    bool canConnect = CheckCellConnection(cell, northCell);
                    if (canConnect) {
                        cell.North = northCell;
                    }
                }

                // link south cell
                if (r - 1 >= 0) {
                    StageCell southCell = mCells[c, r - 1];
                    bool canConnect =CheckCellConnection(cell, southCell);
                    if (canConnect) {
                        cell.South = southCell;
                    }
                }

                // link west cell
                if (c - 1 >= 0) {
                    StageCell westCell = mCells[c - 1, r];
                    bool canConnect = CheckCellConnection(cell, westCell);
                    if (canConnect) {
                        cell.West = westCell;
                    }
                }

                // link east cell
                if (c + 1 < mNumberOfColumns) {
                    StageCell eastCell = mCells[c + 1, r];
                    bool canConnect = CheckCellConnection(cell, eastCell);
                    if (canConnect) {
                        cell.East = eastCell;
                    }
                }
            }
        }
    }
Example #14
0
    private void OnCellPointerEnter(StageCell cell)
    {
        if (!isStandby) {return;}
        if (!characterManager.IsCellAvilable(cell)) {return;}

        if (stageManager.routeCount >= characterManager.GetUserCharacterMove())
        {
            stageManager.RemoveLastRouteIfCan(cell);
        }
        else
        {
            stageManager.AddRoute(cell);
        }
    }