// public MapArrayGenerator GeneratePathMapArrayGenerator(Side side, out Vector3 connectorLocalPosition)
    // {
    //     connector -- pathMapArray -- connector
    // }

    public void GeneratePathTo(Side side, MapArrayGenerator otherMapArrayGenerator,
                               out Vector3 connectorLocalPosition, out Vector3 otherConnectorLocalPosition)
    {
        //choose edge point for each mapArray
        Vector2 connectorCoords;
        Vector2 otherConnectorCoords;
        Vector2 plugCoords;
        Vector2 otherPlugCoords;

        //generate into each copy mapArray from point
        int pathSeed = random.Next();

        MapArrayTile[,] pathMapArray      = GeneratePathInto(pathSeed, side, this, out connectorCoords, out plugCoords);
        MapArrayTile[,] otherPathMapArray = GeneratePathInto(pathSeed, ConnectorScript.oppositeSide[side],
                                                             otherMapArrayGenerator, out otherConnectorCoords, out otherPlugCoords);

        Vector2 normalToOtherCoordConversion = otherConnectorCoords - connectorCoords;

        connectorLocalPosition      = this.MapCoordsToLocalPosition(otherPlugCoords - normalToOtherCoordConversion);
        otherConnectorLocalPosition = otherMapArrayGenerator.MapCoordsToLocalPosition(otherPlugCoords);
        // Debug.Log(connectorLocalPosition);
        // Debug.Log(otherConnectorLocalPosition);

        //clip other maparray room away from copy maparray
        // otherPathMapArray = MakeWalls(otherPathMapArray);
        // ClipWith(otherPathMapArray, otherMapArrayGenerator.mapArray);

        //extend this maparray by other maparray path
        // Debug.Log(connectorCoords);
        // Debug.Log(otherConnectorCoords);
        mapArray = Combine(mapArray, pathMapArray);
        ExtendWithAt(otherPathMapArray, normalToOtherCoordConversion);
    }
    public void FitTogetherWithAt(MapArrayGenerator otherMapArrayGenerator,
                                  Vector2 connectorPosition, Vector2 otherConnectorPosition)
    {
        Vector2 connectorCoords      = this.LocalPositionToMapCoords(connectorPosition);
        Vector2 otherConnectorCoords = otherMapArrayGenerator.LocalPositionToMapCoords(otherConnectorPosition);

        ClipWith(otherMapArrayGenerator.mapArray, mapArray, connectorCoords - otherConnectorCoords);
    }
    //public bool isCameraInBoundingRect = false;

    void Awake()
    {
        //Debug.Log("Map Awake " + GetInstanceID());
        chunk                = transform.root.gameObject;
        mapArrayGenerator    = GetComponent <MapArrayGenerator>();
        worldGeneratorScript = FindObjectOfType <WorldGeneratorScript>();
        sceneryGenerators    = GetComponents <SceneryGenerator>();
        tilemapGenerator     = GetComponent <TilemapGenerator>();
    }
    void Awake()
    {
        //Debug.Log("Connector Awake " + (GetInstanceID()));
        worldGeneratorScript = FindObjectOfType <WorldGeneratorScript>();
        //Change to tag later
        chunk             = transform.root.gameObject;
        mapArrayGenerator = GetComponentInParent <MapArrayGenerator>();
        mapScript         = GetComponentInParent <MapScript>();

        edgeCollider = GetComponent <EdgeCollider2D>();

        Vector2 screenSize         = new Vector2(Screen.width, Screen.height);
        Vector2 enlargedScreenSize = new Vector2(bufferMultipliers.x * screenSize.x, bufferMultipliers.y * screenSize.y);

        enlargedScreenRect = new Rect(-(enlargedScreenSize - screenSize) / 2, enlargedScreenSize);
    }
        public void TestRoomToMapDontThrow()
        {
            var expected        = 64;
            var expected2       = 128;
            var minimumRoomSize = 5;
            //Generate array where every coordinate is "1"
            var arr    = MapArrayGenerator.GenerateArray(expected, expected2, false);
            var origin = new Vector2Int(0, 0);
            var size   = new Vector2Int(64, 64);

            for (int i = 0; i < 100; i++)
            {
                var room = new Room(origin, size, minimumRoomSize);
                Assert.DoesNotThrow(() => room.ToMap(arr), "message");
            }
        }
        public void RoomMappedToMap()
        {
            var expected        = 64;
            var expected2       = 128;
            var minimumRoomSize = expected;
            var nodeOrigin      = new Vector2Int(0, 0);
            var nodeSize        = new Vector2Int(expected, expected);

            System.Random rand = new System.Random();
            for (int i = 0; i < 100; i++)
            {
                //Generate array where every coordinate is "0"
                var arr  = MapArrayGenerator.GenerateArray(expected, expected2, true);
                var room = new Room(nodeOrigin, nodeSize, minimumRoomSize / 2, 0, rand);
                room.ToMap(arr);
                Assert.IsTrue(ConfirmMapping(arr, room));
            }
        }
 void Awake()
 {
     mapArrayGenerator = GetComponent <MapArrayGenerator>();
 }
Exemple #8
0
 public virtual void Awake()
 {
     mapArrayGenerator = GetComponent <MapArrayGenerator>();
 }
    protected override MapArrayTile[,] GeneratePathInto(int seed, Side side,
                                                        MapArrayGenerator otherMapArrayGenerator, out Vector2 connectorCoords, out Vector2 plugCoords)
    {
        System.Random random        = new System.Random(seed);
        int           hallThickness = random.Next((int)hallThicknessRange.x, (int)hallThicknessRange.y);
        int           hallYCoord    = random.Next((int)otherMapArrayGenerator.roomBoundingRect.min.y + hallThickness / 2,
                                                  (int)otherMapArrayGenerator.roomBoundingRect.max.y - (hallThickness + 1) / 2);
        int hallXCoord = random.Next((int)otherMapArrayGenerator.roomBoundingRect.min.x + hallThickness / 2,
                                     (int)otherMapArrayGenerator.roomBoundingRect.max.x - (hallThickness + 1) / 2);

        MapArrayTile[,] otherMapArray = otherMapArrayGenerator.mapArray;
        Rect otherRoomBoundingRect = otherMapArrayGenerator.roomBoundingRect;

        plugCoords      = Vector2.zero;
        connectorCoords = Vector2.zero;

        switch (side)
        {
        case Side.Left:
            connectorCoords = new Vector2(-0.5f, hallYCoord);
            plugCoords      = new Vector2((int)otherRoomBoundingRect.min.x - 0.5f, hallYCoord);
            break;

        case Side.Right:
            connectorCoords = new Vector2(otherMapArray.GetLength(0) - 0.5f, hallYCoord);
            plugCoords      = new Vector2((int)otherRoomBoundingRect.max.x - 0.5f, hallYCoord);
            break;

        case Side.Top:
            connectorCoords = new Vector2(hallXCoord, otherMapArray.GetLength(1) - 0.5f);
            plugCoords      = new Vector2(hallXCoord, (int)otherRoomBoundingRect.max.y - 0.5f);
            break;

        case Side.Bottom:
            connectorCoords = new Vector2(hallXCoord, -0.5f);
            plugCoords      = new Vector2(hallXCoord, (int)otherRoomBoundingRect.min.y - 0.5f);
            break;

        default:
            Debug.Log("Side does not exist");
            break;
        }

        MapArrayTile[,] pathArray = new MapArrayTile[otherMapArray.GetLength(0), otherMapArray.GetLength(1)];
        FillWith(pathArray, MapArrayTile.None);

        //Returns the position of the connector in map coords
        switch (side)
        {
        case Side.Left:
            FillBoxWith(pathArray, 0, (int)otherRoomBoundingRect.min.x,
                        hallYCoord - hallThickness / 2, hallYCoord + (hallThickness + 1) / 2, MapArrayTile.Ground);
            break;

        case Side.Right:
            FillBoxWith(pathArray, (int)otherRoomBoundingRect.max.x, pathArray.GetLength(0),
                        hallYCoord - hallThickness / 2, hallYCoord + (hallThickness + 1) / 2, MapArrayTile.Ground);
            break;

        case Side.Top:
            FillBoxWith(pathArray, hallXCoord - hallThickness / 2, hallXCoord + (hallThickness + 1) / 2,
                        (int)otherRoomBoundingRect.max.y, pathArray.GetLength(1), MapArrayTile.Ground);
            break;

        case Side.Bottom:
            FillBoxWith(pathArray, hallXCoord - hallThickness / 2, hallXCoord + (hallThickness + 1) / 2,
                        0, (int)otherRoomBoundingRect.min.y, MapArrayTile.Ground);
            break;

        default:
            Debug.Log("Side does not exist");
            break;
        }
        return(pathArray);
    }
Exemple #10
0
 public void UpdateMap(int[,] map)
 {
     MapArrayGenerator.UpdateMap(map, tilemap);
 }
Exemple #11
0
 public void RenderMap(int[,] map)
 {
     MapArrayGenerator.RenderMap(map, tilemap, tile);
 }
 protected abstract MapArrayTile[,] GeneratePathInto(int seed, Side side,
                                                     MapArrayGenerator otherMapArrayGenerator, out Vector2 connectorCoords, out Vector2 plugCoords);