Exemple #1
0
    private bool CheckBlockers(Vector3 position, Vector3 direction)
    {
        // Check if the tile we're sitting on has any blockers pointing in the specified direction that
        // prevent us from moving that way

        List <GameObject> bucket = GetLinkBucket(ToVector3Int(position));

        foreach (GameObject tile in bucket)
        {
            TileBlocker blocker = tile.GetComponent <TileBlocker>();
            if (blocker && blocker.CheckBlock(position, position + direction) != TileBlocker.BlockType.None)
            {
                // We're sitting on a blocker that won't let us move in that direction.
                return(false);
            }
        }

        return(true);
    }
Exemple #2
0
    private int RunMoveTile(GameObject tile, Vector3 position, Vector3 target, List <TileMover> movers)
    {
        // Priorities ->
        // 1 - If there's a blocker that stops us before this tile, then stop there and don't move
        // onto the tile
        // 2 - If we're able to move onto the tile

        // there's something in our way, but we may be able to move onto / over it
        TileTrigger trigger = tile.GetComponent <TileTrigger>();

        if (trigger)
        {
            if (trigger.ResponseType == TileTrigger.TriggerResponseType.StopOn)
            {
                // This is a trigger we should stop on
                return(MoveStopOn);
            }
            else
            {
                // Trigger does not stop movement
                return(MoveNone);
            }
        }

        // Not a trigger, maybe it's a blocker?
        TileBlocker blocker = tile.GetComponent <TileBlocker>();

        if (blocker)
        {
            switch (blocker.CheckBlock(position, target))
            {
            case TileBlocker.BlockType.MoveOn:
                // Move onto the blocker, but stop there
                return(MoveStopOn);

            case TileBlocker.BlockType.None:
                return(MoveNone);

            case TileBlocker.BlockType.StopInfront:
                return(MoveBlocked);
            }
        }

        // A tile mover can be moved by us, but we need to calculate the move appropriately
        TileMover mover = tile.GetComponent <TileMover>();

        if (mover)
        {
            switch (mover.MoveType)
            {
            case TileMover.TileMoveType.MoveThrough:
                return(MoveNone);    // Can just move through the mover

            case TileMover.TileMoveType.Block:
                return(MoveBlocked);    // Mover is set to not move, so we're blocked

            case TileMover.TileMoveType.Push:
                // Process this later. If nothing else is blocking us, we might be able to push this mover.
                movers.Add(mover);
                return(MoveNone);
            }
        }

        return(MoveBlocked); // A wall
    }