Exemplo n.º 1
0
    // Note this creates pretty lame tunnels. Could try to make it do a zigzag pattern or something
    public List<DungeonArea> DigTunnel( DungeonArea roomb )
    {
        DungeonArea[] rooms = new DungeonArea[]
        {
            this,
            roomb,
        };

        var roomsColor = SUtil.SRandom.SRandom.GetRandomColor();

        foreach (var r in rooms)
            r.color_ = roomsColor;

        IntRect[] areas = rooms.Select(r => r.area_).ToArray();

        IntVector2[] points = areas.Select(a => a.GetRandomPoint()).ToArray();

        for (int i = 0; i < 2; ++i)
        {
            points[i] = areas[i].PushPointToTargetEdge(points[i], points[1 - i]);

        }

        var bl = IntVector2.Min( points[0], points[1] );
        var tr = IntVector2.Max( points[0] + IntVector2.one, points[1] + IntVector2.one );

        var diffArea = new IntRect( bl.x, bl.y, tr.x - bl.x, tr.y - bl.y );
        diffArea.w_ = diffArea.w_ <= 0 ? 1 : diffArea.w_;
        diffArea.h_ = diffArea.w_ <= 0 ? 1 : diffArea.h_;

        DungeonArea[] halls = new DungeonArea[]
        {
            new DungeonArea( diffArea ),
            new DungeonArea( points[0]),
            new DungeonArea( points[1]),
        };
        halls[0].color_ = Color.green;
        halls[1].color_ = Color.red;
        halls[2].color_ = Color.red;

        /*
        // The two possible points where our hallways  connect
        IntVector2[] possibleConnections = new IntVector2[]
        {
            new IntVector2(points[0].x, points[1].y),
            new IntVector2(points[1].x, points[0].y),
        };

        var connectionPoint = SUtil.SRandom.SRandom.GetRandomItemFromList( possibleConnections );
        for (int i = 0; i < 2; ++i)
            if (areas[i].Contains(connectionPoint))
                connectionPoint = points[i];

        DungeonArea[] halls = new DungeonArea[]
        {
            new DungeonArea( points[0] ),
            new DungeonArea( points[1] ),
            new DungeonArea( connectionPoint ),
        };

        var color = SUtil.SRandom.SRandom.GetRandomColor();

        for( int i = 0; i < 2; ++i )
        {
            halls[i].area_.position_ = points[i];
            halls[i].area_.Encapsulate(connectionPoint);
            halls[i].color_ = color;
        }

        halls[2].color_ = Color.magenta;
        */

        return halls.ToList();
    }