Ejemplo n.º 1
0
    // dir
    //  7  6  5
    //    \|/
    //  0--+--4
    //    /|\
    //  1  2  3

    public static Vector2Int DirToOffset(GameVertex.Direction dir)
    {
        Vector2Int offset = Vector2Int.zero;

        if ((int)dir % 2 == 1)
        {
            // right or left
            // pos = 3 or 5
            // neg = 1 or 7
            offset.x = -Mathf.Abs(((int)dir - 4) / 3) + Mathf.Abs((int)dir - 4) % 3;

            // up or down
            // pos = 5 or 7
            // neg = 1 or 3
            offset.y = ((int)dir - 4) % 2;
        }
        else
        {
            // right or left
            // pos = 4
            // neg = 0
            offset.x = (((int)dir - 2) / 2) % 2;

            // up or down
            // pos = 6
            // neg = 2
            offset.y = (((int)dir - 4) / 2) % 2;
        }
        return(offset);
    }
Ejemplo n.º 2
0
 public static float DirToDist(GameVertex.Direction dir)
 {
     if ((int)dir % 2 == 1)
     {
         return(Level.diagonalOffsetDist);
     }
     else
     {
         return(Level.cardinalOffsetDist);
     }
 }
Ejemplo n.º 3
0
    public static Slot DirMirrorSlot(GameVertex.Direction dir, Slot s)
    {
        switch (dir)
        {
        case GameVertex.Direction.W:
        case GameVertex.Direction.E: s.pos.y -= 1; break;

        case GameVertex.Direction.S:
        case GameVertex.Direction.N: s.pos.x -= 1; break;

        default: break;
        }

        s.space = s.space ^ Slot.Space.full;
        return(s);
    }
Ejemplo n.º 4
0
    // dir
    //  7  6  5
    //    \|/
    //  0--+--4
    //    /|\
    //  1  2  3
    public static Vector2Int DirAffectPos(GameVertex.Direction dir, Vector2Int in0)
    {
        switch (dir)
        {
        case GameVertex.Direction.W: in0.x -= 1;            break;

        case GameVertex.Direction.S: in0.x -= 1; in0.y -= 1; break;

        case GameVertex.Direction.E: in0.x -= 1; break;

        case GameVertex.Direction.N: in0.x -= 1; break;

        default: break;
        }
        return(in0);
    }
Ejemplo n.º 5
0
    public static GameVertex.Edge.Type SnapToType(GameVertex.Direction snappedDir, ref GameVertex.Edge vert)
    {
        switch (snappedDir)
        {
        case GameVertex.Direction.W: return(vert.edgeW);

        case GameVertex.Direction.SW: return(vert.edgeSW);

        case GameVertex.Direction.S: return(vert.edgeS);

        case GameVertex.Direction.SE: return(vert.edgeSE);

        case GameVertex.Direction.E: return(vert.edgeE);

        case GameVertex.Direction.NE: return(vert.edgeNE);

        case GameVertex.Direction.N: return(vert.edgeN);

        case GameVertex.Direction.NW: return(vert.edgeNW);

        default: Debug.LogWarning("Warning! Unexpected snappedDir given to SnapToType"); return(GameVertex.Edge.Type.None);
        }
    }
Ejemplo n.º 6
0
    internal void Setup(Level level, GameVertex.Direction givenSnappedDir, int givenY, int givenX)
    {
        var lvlInstance = level.levelInstance;

        lvlInstance.grid[givenY, givenX].gos[(int)givenSnappedDir] = gameObject;

        var   rend  = GetComponent <LineRenderer>();
        float angle = Mathf.Deg2Rad * ((int)givenSnappedDir * 45.0f);

        Vector3 pt0 = rend.GetPosition(0);
        Vector3 pt1 = rend.GetPosition(1);

        pt0 = new Vector3(givenX - level.width / 2, 0, givenY - level.height / 2);
        pt1 = new Vector3(-Mathf.Cos(angle), 0, -Mathf.Sin(angle));
        pt1 = pt1.normalized;

        // Is diagonal line?
        if ((int)givenSnappedDir % 2 == 1)
        {
            pt1 = pt0 + pt1 * Level.diagonalOffsetDist;
        }
        else
        {
            pt1 = pt0 + pt1 * Level.cardinalOffsetDist;
        }

        rend.SetPosition(0, pt0);
        rend.SetPosition(1, pt1);

        // Set Parent
        transform.SetParent(level.setupRoot.transform);

        // record data about setline
        pos.x      = givenX;
        pos.y      = givenY;
        snappedDir = givenSnappedDir;
    }
Ejemplo n.º 7
0
    /// NEEED TO WORK ON THIS!!!

    // assumes input is not mirrored AND is aligned to point West
    static Slot.Space DirAffectSpace(GameVertex.Direction dir, Slot.Space space)
    {
    }
Ejemplo n.º 8
0
    internal LineCommand Set(Level level, LineCommand.Command cmd)
    {
        var lvlInstance = level.levelInstance;
        var rend        = GetComponent <LineRenderer>();

        Vector3 pt0         = rend.GetPosition(0);
        Vector3 pt1         = rend.GetPosition(1);
        Vector3 lineVec     = pt1 - pt0;
        Vector3 lineVecNorm = lineVec.normalized;

        float angle = Mathf.Rad2Deg * Mathf.Atan2(lineVecNorm.z, lineVecNorm.x) + 180.0f;

        // range: (0,7) even = W,S,E,N odd = SW, SE, NE, NW
        GameVertex.Direction snappedDir = (GameVertex.Direction)(Mathf.FloorToInt((angle / 45.0f) + 0.5f) % 8);

        float      offsetDist = ARUtil.DirToDist(snappedDir);
        Vector2Int offset     = ARUtil.DirToOffset(snappedDir);

        int lineCountToAdd = Mathf.FloorToInt((lineVec.magnitude + (0.5f * offsetDist)) / offsetDist);
        int startX         = Mathf.FloorToInt(pt0.x + 0.5f) + Mathf.FloorToInt(level.width / 2);
        int startY         = Mathf.FloorToInt(pt0.z + 0.5f) + Mathf.FloorToInt(level.height / 2);

        int maxX = level.width / 2;
        int maxY = level.height / 2;


        // directional flags
        GameVertex.DirectionFlags directionFlags = (GameVertex.DirectionFlags)(1 << (int)snappedDir);

        // make line command to run and record
        LineCommand lc;

        lc.gos       = new GameObject[lineCountToAdd];
        lc.cmd       = cmd;
        lc.moveDelta = Vector2Int.zero;
        lc.flags     = GameVertex.Edge.none;

        // @TEMP @TODO @REPLACE
        lc.flags.Set(directionFlags, GameVertex.Edge.Type.solid);

        for (int i = 0; i < lineCountToAdd; ++i)
        {
            int y = startY + (i * offset.y);
            int x = startX + (i * offset.x);

            if ((x < 0 || x >= level.width) ||
                (y < 0 || y >= level.height))
            {
                Debug.LogWarning("Unset line tried to play a line outside the bounds. This may be expected");
                break;
            }


            // Add array if not already added
            if (lvlInstance.grid[y, x].gos == null)
            {
                lvlInstance.grid[y, x].gos = new GameObject[8];
            }


            GameObject go = lvlInstance.grid[y, x].gos[(int)snappedDir];
            if (go == null)
            {
                go = Instantiate(level.settings.prefabs.setLine);
                lvlInstance.grid[y, x].gos[(int)snappedDir] = go;
                go.GetComponent <SetLine>().Setup(level, snappedDir, y, x);
            }
            lc.gos[i] = go;

            SetLine setLine = go.GetComponent <SetLine>();
            setLine.RunCommand(level, lc);
        }


        return(lc);
    }