private void SetCoordState(float x, float z, CoordState coordState)
    {
        int coordX = GetNearInt(x) + coordOffset;
        int coordY = GetNearInt(z) + coordOffset;

        if (coordY > -1 &&
            coordX > -1 &&
            coordY < _coordStates.GetLength(0) &&
            coordX < _coordStates.GetLength(1))
        {
            CoordState prevCoordState = _coordStates[coordY, coordX];
            _coordStates[coordY, coordX] = coordState;

            if (coordState == CoordState.kGoal && prevCoordState != CoordState.kGoal)
            {
                ++numClearedGoals;
            }
            else if (coordState != CoordState.kGoal && prevCoordState == CoordState.kGoal)
            {
                --numClearedGoals;
            }
        }
    }
Beispiel #2
0
    private void Update()
    {
        bool isMovable = true;

        if (lastPushable != null)
        {
            if (!lastPushable.isArrived)
            {
                isMovable = false;
            }
        }

        if (blockMover.isArrived && isMovable)
        {
            float horizontal = Input.GetAxisRaw("Horizontal");
            float vertical   = Input.GetAxisRaw("Vertical");

            if (IsPressed(horizontal + vertical))
            {
                Vector3 movement = GetMovement(horizontal, vertical);
                Vector3 target   = _transform.position + movement;

                bool        isMove      = false;
                GameManager gameManager = GameManager.instance;
                CoordState  coordState  = gameManager.GetCoordState(target);
                if (coordState == CoordState.kPushable ||
                    coordState == CoordState.kGoal)
                {
                    Vector3 targetForPushable = target + movement;
                    if (gameManager.GetCoordState(targetForPushable) == CoordState.kMovable)
                    {
                        lastPushable = gameManager.GetPushable(target);
                        lastPushable.MoveTo(targetForPushable, moveDamping);

                        BlockMover goal = gameManager.GetGoal(targetForPushable);
                        if (goal)
                        {
                            lastPushable.material = Orange;
                            gameManager.SetCoordState(targetForPushable, CoordState.kGoal);
                        }
                        else
                        {
                            gameManager.SetCoordState(targetForPushable, CoordState.kPushable);
                        }

                        isMove = true;
                    }
                }
                else if (coordState == CoordState.kMovable)
                {
                    isMove = true;
                }

                if (isMove)
                {
                    blockMover.MoveTo(target, moveDamping * 0.4f);
                    blockMover.isSmooth = false;
                    gameManager.SetCoordState(target, CoordState.kPlayer);
                    gameManager.SetCoordState(_transform.position, CoordState.kMovable);

                    const float degreesXFactor = 0.5f;
                    const float degreesZFactor = 0.5f;
                    Quaternion  destination    = Quaternion.Euler(new Vector3(-movement.z * degreesXFactor, 0f, movement.x * degreesZFactor));
                    cameraController.rotationDestination = cameraController.rotation * destination;
                    cameraController.rotationDamping     = 3.0f;
                    cameraController.isLookAt            = false;
                }
            }
        }
    }
 public void SetCoordState(Vector3 position, CoordState coordState)
 {
     SetCoordState(position.x, position.z, coordState);
 }
Beispiel #4
0
    public ClickableSpace[] LayTiles(int x, int y, int r, ClickableSpace.Type type)
    {
        ClearTiles();

        Board board = Game.Instance().board;
        List <ClickableSpace> createdSpaces = new List <ClickableSpace>();

        // TODO size?
        const int size = 64;

        CoordState[,] coords = new CoordState[size, size];

        List <Coord> results = new List <Coord>();

        List <Coord> q = new List <Coord>();

        // Algorithm #1
        //
        q.Add(new Coord(x, y));
        coords[x, y] = CoordState.Visited;

        for (int i = 0; i <= r; i++)
        {
            List <Coord> newQ = new List <Coord>();

            foreach (Coord p in q)
            {
                if (i != 0)
                {
                    bool shouldAdd = false;

                    if (type == ClickableSpace.Type.Move)
                    {
                        // Can we move to the tile?
                        //
                        bool canMove = false;

                        if (board.IsEmpty(p))
                        {
                            canMove = true;
                        }

                        shouldAdd = canMove;
                    }
                    else
                    {
                        // Can we attack the tile?
                        //
                        shouldAdd = true;
                    }

                    if (shouldAdd)
                    {
                        results.Add(p);
                    }
                }

                if (i != r)
                {
                    AddIfNotVisited(coords, newQ, p.x + 1, p.y);
                    AddIfNotVisited(coords, newQ, p.x, p.y + 1);
                    AddIfNotVisited(coords, newQ, p.x - 1, p.y);
                    AddIfNotVisited(coords, newQ, p.x, p.y - 1);
                }
            }

            q = newQ;
        }

        foreach (Coord p in results)
        {
            ClickableSpace space = ClickableSpace.Create(p.x, p.y, type);
            createdSpaces.Add(space);
        }

        ClickableSpace[] createdSpacesArray = createdSpaces.ToArray();
        currentTiles = createdSpacesArray;
        return(createdSpacesArray);
    }