コード例 #1
0
    public GridObjectBase SpawnObject(GridObjectBase newObjectPrefab, Vector2Int position, Color colorNormal, Color colorLinked)
    {
        bool canSpawn = IsFree(position, newObjectPrefab.size);

        if (canSpawn)
        {
            GridObjectBase newObject = Instantiate(newObjectPrefab, transform);
            newObject.UpdatePosition(position);
            if (newObject is Piece)
            {
                (newObject as Piece).Init(colorNormal, colorLinked);
                activePieces.Add((Piece)newObject);
            }

            ForGridRectDo(position, newObject.size, (x, y) =>
            {
                grid[x, y] = newObject;
            });
            return(newObject);
        }
        else
        {
            return(null);
        }
    }
コード例 #2
0
ファイル: IceCube.cs プロジェクト: shbli/Tower-Warriors
    // Use this for initialization
    void Start()
    {
        GridObjectBase targetObject = GetComponentInParent <GridObjectBase>();
        Freeze         freeze       = targetObject.gameObject.AddComponent <Freeze>();

        freeze.iceCubeAnimator = GetComponentInChildren <Animator>();
        freeze.iceCubeRoot     = this.gameObject;
    }
コード例 #3
0
    public GridObjectBase GetFirstObjectInLine(Vector2Int startOrigin, Vector2Int rect)
    {
        GridObjectBase foundObject = null;

        ForGridRectDo(startOrigin, rect, (x, y) =>
        {
            if (grid[x, y] != null && foundObject == null)
            {
                foundObject = grid[x, y];
            }
        });

        return(foundObject);
    }
コード例 #4
0
    /// <summary>
    /// Shows the attack cubes for an grid object attack.
    /// </summary>
    /// <param name="agent">Agent.</param>
    public void ShowCubesForAgentAttack(GridObjectBase gridObject)
    {
        enabled = true;

        if (gridObject.attackMovementType == MovementType.PlusShaped || gridObject.attackMovementType == MovementType.PlusAndXShaped)
        {
            ShowPlusCubesForObject(gridObject);
        }

        if (gridObject.attackMovementType == MovementType.XShaped || gridObject.attackMovementType == MovementType.PlusAndXShaped)
        {
            ShowXCubesForObject(gridObject);
        }
    }
コード例 #5
0
    public void MoveObjectYMax(GridObjectBase movedObject, Vector2Int maxPosition)
    {
        int objectX = movedObject.Position.x;

        for (int y = movedObject.Position.y + 1; y <= maxPosition.y; y++)
        {
            Vector2Int newPosition = new Vector2Int(objectX, y);
            bool       freeSpot    = IsFree(newPosition, movedObject.size);
            if (freeSpot)
            {
                MoveObject(movedObject, newPosition);
            }
            else
            {
                break;
            }
        }
    }
コード例 #6
0
    public void MoveObject(GridObjectBase movedObject, Vector2Int newPosition)
    {
        //Remove piece from prev location
        ForGridRectDo(movedObject.Position, movedObject.size, (x, y) =>
        {
            if (grid[x, y] == movedObject)
            {
                grid[x, y] = null;
            }
        });

        //Move piece to new position
        movedObject.UpdatePosition(newPosition);
        ForGridRectDo(movedObject.Position, movedObject.size, (x, y) =>
        {
            grid[x, y] = movedObject;
        });
    }
コード例 #7
0
 public void AttackTarget(GridObjectBase pTarget)
 {
     targetGridObject = pTarget;
     AttackTargetLocal();
 }
コード例 #8
0
 private void ForGridObjectRectDo(GridObjectBase gridObject, Action <int, int> action)
 {
     ForGridRectDo(gridObject.Position, gridObject.size, action);
 }
コード例 #9
0
    private void ShowPlusCubesForObject(GridObjectBase gridObject)
    {
        int cellXIndex = LevelArray.currentLevelArray.GetXIndex(gridObject.transform.position.x);
        int cellZIndex = LevelArray.currentLevelArray.GetZIndex(gridObject.transform.position.z);

        int newCellXIndex;
        int newCellZIndex;

        int steps = gridObject.attackSteps;

        while (steps > 0)
        {
            newCellXIndex = cellXIndex + steps;
            newCellZIndex = cellZIndex;

            if (LevelArray.currentLevelArray.isInIndexRange(newCellXIndex, newCellZIndex))
            {
                NavTileAgent agent = LevelArray.currentLevelArray.GetAgentInCell(newCellXIndex, newCellZIndex);
                if (agent != null)
                {
                    if (agent.isLocalAgent == false)
                    {
                        LevelArray.currentLevelArray.setLightCubeForCell(newCellXIndex, newCellZIndex, attackLightParent.GetChild(currentMoveIndex).gameObject);
                        currentAttackIndex++;
                    }
                }
            }

            newCellXIndex = cellXIndex - steps;
            newCellZIndex = cellZIndex;

            if (LevelArray.currentLevelArray.isInIndexRange(newCellXIndex, newCellZIndex))
            {
                NavTileAgent agent = LevelArray.currentLevelArray.GetAgentInCell(newCellXIndex, newCellZIndex);
                if (agent != null)
                {
                    if (agent.isLocalAgent == false)
                    {
                        LevelArray.currentLevelArray.setLightCubeForCell(newCellXIndex, newCellZIndex, attackLightParent.GetChild(currentMoveIndex).gameObject);
                        currentAttackIndex++;
                    }
                }
            }

            newCellXIndex = cellXIndex;
            newCellZIndex = cellZIndex + steps;

            if (LevelArray.currentLevelArray.isInIndexRange(newCellXIndex, newCellZIndex))
            {
                NavTileAgent agent = LevelArray.currentLevelArray.GetAgentInCell(newCellXIndex, newCellZIndex);
                if (agent != null)
                {
                    if (agent.isLocalAgent == false)
                    {
                        LevelArray.currentLevelArray.setLightCubeForCell(newCellXIndex, newCellZIndex, attackLightParent.GetChild(currentMoveIndex).gameObject);
                        currentAttackIndex++;
                    }
                }
            }

            newCellXIndex = cellXIndex;
            newCellZIndex = cellZIndex - steps;

            if (LevelArray.currentLevelArray.isInIndexRange(newCellXIndex, newCellZIndex))
            {
                NavTileAgent agent = LevelArray.currentLevelArray.GetAgentInCell(newCellXIndex, newCellZIndex);
                if (agent != null)
                {
                    if (agent.isLocalAgent == false)
                    {
                        LevelArray.currentLevelArray.setLightCubeForCell(newCellXIndex, newCellZIndex, attackLightParent.GetChild(currentMoveIndex).gameObject);
                        currentAttackIndex++;
                    }
                }
            }

            steps--;
        }
    }