Ejemplo n.º 1
0
    Vector3 GetLineIntersection(ExitConfig direction, CustomRect room, Vector3 connectionStart, Vector3 connectionEnd)
    {
        //just a crack, not a proper approach
        float slope1 = GetSlope(connectionStart, connectionEnd);
        float b1     = connectionStart.z - (slope1 * connectionStart.x);
        float b2     = 0;
        float slope2 = 0;

        if (direction == ExitConfig.LEFT)
        {
            slope2 = (room.y - room.yMax) / (room.x - room.x + 1);
            b2     = room.y - (slope2 * room.x);
        }
        else if (direction == ExitConfig.RIGHT)
        {
            slope2 = (room.y - room.yMax) / (room.xMax - room.xMax + 1);
            b2     = room.y - (slope2 * room.xMax);
        }
        else if (direction == ExitConfig.TOP)
        {
            slope2 = (room.yMax - room.yMax + 1) / (room.x - room.xMax);
            b2     = room.yMax - (slope2 * room.xMax);
        }
        else if (direction == ExitConfig.BOTTOM)
        {
            slope2 = (room.y - room.y + 1) / (room.x - room.xMax);
            b2     = room.y - (slope2 * room.xMax);
        }
        return(GetInterceptPosition(b1, b2, slope1, slope2));
    }
Ejemplo n.º 2
0
    protected override void generateMap(int row, int col, int borderSize)
    {
        base.generateMap(row, col, borderSize);

        Debug.Assert(_roomData.exitConfig.Count == _roomData.exitPositions.Count, "Data mismatch - ExitConfig");

        for (int index = 0; index < _roomData.exitConfig.Count; index++)
        {
            ExitConfig config = _roomData.exitConfig[index];
            switch (config)
            {
            case ExitConfig.LEFT:
                CreateLeftExit(_roomData.exitPositions[index]);
                break;

            case ExitConfig.RIGHT:
                CreateRightExit(_roomData.exitPositions[index]);
                break;

            case ExitConfig.TOP:
                CreateTopExit(_roomData.exitPositions[index]);
                break;

            case ExitConfig.BOTTOM:
                CreateBottomExit(_roomData.exitPositions[index]);
                break;
            }
        }
    }
Ejemplo n.º 3
0
    Vector3 GetLineIntersection(ExitConfig direction, CustomRect connection, CustomRect room)
    {
        /*
         * slope (m) = change in y / change in x
         */
        float y      = (connection.center.y - room.center.y);
        float x      = (connection.center.x - room.center.x);
        float slope1 = ((y == 0) ? 1 : y) / ((x == 0) ? 1 : x);
        float slope2 = 0;

        /*
         *  y = mx + b
         *
         *  What is this 'b'? Well, the line must cross the y-axis at the point
         *  (0,b). To find b, we can substitute the values at some point on the
         *  line
         */
        float b1 = connection.center.y - (slope1 * connection.center.x);
        float b2 = 0;

        if (direction == ExitConfig.LEFT)
        {
            slope2 = (room.y - room.yMax) / (room.x - room.x + 1);
            b2     = room.y - (slope2 * room.x);
        }
        else if (direction == ExitConfig.RIGHT)
        {
            slope2 = (room.y - room.yMax) / (room.xMax - room.xMax + 1);
            b2     = room.y - (slope2 * room.xMax);
        }
        else if (direction == ExitConfig.TOP)
        {
            slope2 = (room.yMax - room.yMax + 1) / (room.x - room.xMax);
            b2     = room.yMax - (slope2 * room.xMax);
        }
        else if (direction == ExitConfig.BOTTOM)
        {
            slope2 = (room.y - room.y + 1) / (room.x - room.xMax);
            b2     = room.y - (slope2 * room.xMax);
        }

        /*
         * y - y = m1*x + b1  - m2*x - b2
         * x * (m1 - m2) + b1 - b2 = 0;
         *
         * To find X
         * x = b2 - b1 / m1 - m2
         *
         * To find Y
         * y = mx + b
         */

        float xPos = (b2 - b1) / (slope1 - slope2);
        float yPos = (slope1 * xPos) + b1;

        return(new Vector3(xPos, 5, yPos));
    }
Ejemplo n.º 4
0
 public override void Setup(Vector3 position, ExitConfig config)
 {
     base.Setup(position, config);
     if (config == ExitConfig.TOP || config == ExitConfig.LEFT)
     {
         transform.Rotate(Vector3.up, 180.0f);
     }
     SetLamp(true);
 }
Ejemplo n.º 5
0
    //may need to remove normal door inside this function
    public void AddExitDoor(int roomId)
    {
        Room room = GetRoomById(roomId);

        if (room.roomData.exitDoorPositions.Count > 1)
        {
            throw new UnityException("Wrong room selected for Exit - Room has more than one exit");
        }
        foreach (var door in room.roomData.dungeonElements.doors)
        {
            door.gameObject.SetActive(false);
        }
        Vector3    exitDoorPosition = room.roomData.exitDoorPositions[0];
        ExitConfig exitDoorConfig   = room.roomData.exitConfig[0];

        GameObject exitDoor = AssetReference.instance.GetGameObjectInstance("ExitDoor");

        room.roomData.dungeonElements.AddExitDoor(exitDoor.GetComponent <ExitDoor>());
        exitDoor.transform.SetParent(room.gameObject.transform);
        exitDoor.GetComponent <ExitDoor>().Setup(exitDoorPosition, exitDoorConfig);
    }
Ejemplo n.º 6
0
 bool IsWithin(ExitConfig direction, CustomRect connection, CustomRect room)
 {
     if (direction == ExitConfig.LEFT || direction == ExitConfig.RIGHT)
     {
         if (
             (room.y >= connection.y && room.yMax <= connection.yMax) ||
             (connection.y >= room.y && connection.yMax <= room.yMax))
         {
             return(true);
         }
     }
     else
     {
         if (
             (room.x >= connection.x && room.xMax <= connection.xMax) ||
             (connection.x >= room.x && connection.xMax <= room.xMax))
         {
             return(true);
         }
     }
     return(false);
 }
Ejemplo n.º 7
0
    void ConnectVertically(BSPNode connection, BSPNode room, ExitConfig config)
    {
        Vector3 vec1;
        Vector3 vec2;

        if (connection.rect.width < room.rect.width)
        {
            vec1 = (new Vector3(connection.rect.center.x, 5, connection.rect.center.y));
            vec2 = (new Vector3(connection.rect.center.x, 5, room.rect.center.y));
        }
        else
        {
            vec1 = (new Vector3(room.rect.center.x, 5, room.rect.center.y));
            vec2 = (new Vector3(room.rect.center.x, 5, connection.rect.center.y));
        }

        Vector3 intersectionPt = GetLineIntersection(config, room.rect, vec1, vec2);

        room.connectingPositions.Add(vec1);
        room.connectingPositions.Add(vec2);
        room.exitPositions.Add(intersectionPt);
        connection.exitPositions.Add(intersectionPt);
    }
Ejemplo n.º 8
0
    virtual public void Setup(Vector3 position, ExitConfig config)
    {
        foreach (var lamp in lamps)
        {
            lamp.SetActive(false);
            lamp.GetComponentInChildren <Light>().intensity = 0.0f;
        }

        float rotation = 0.0f;

        position.y         = door.transform.localScale.y * 0.5f;
        transform.position = position;
        _closePosition     = position;
        if (config != ExitConfig.TOP && config != ExitConfig.BOTTOM)
        {
            rotation      = 270.0f;
            _openPosition = _closePosition + Vector3.forward * door.transform.localScale.x * 0.95f;
        }
        else
        {
            _openPosition = _closePosition + Vector3.left * door.transform.localScale.x * 0.95f;
        }
        transform.rotation = Quaternion.Euler(0.0f, rotation, 0.0f);
    }