Esempio n. 1
0
    private int GetCorrectDoorRotation(ExtendedTileType type, Dictionary <Vector2Int, GenTile> tiles, Vector2Int position)
    {
        Vector2Int toCheck;

        if (type == ExtendedTileType.DoorOuter)
        {
            toCheck = position + new Vector2Int(0, -1);
            if (tiles.ContainsKey(toCheck) && tiles[toCheck].type == Room.TileType.DOOR)
            {
                return(270);
            }
            toCheck = position + new Vector2Int(-1, 0);
            if (tiles.ContainsKey(toCheck) && tiles[toCheck].type == Room.TileType.DOOR)
            {
                return(180);
            }
            toCheck = position + new Vector2Int(0, 1);
            if (tiles.ContainsKey(toCheck) && tiles[toCheck].type == Room.TileType.DOOR)
            {
                return(90);
            }
            return(0);
        }
        toCheck = position + new Vector2Int(0, -1);
        if (tiles.ContainsKey(toCheck) && tiles[toCheck].type == Room.TileType.DOOR)
        {
            return(90);
        }
        return(0);
    }
Esempio n. 2
0
    public GameObject CreateGOFromType(Vector2 v, int rotation, Room.TileType type, ExtendedTileType t, GameObject root)
    {
        GameObject tmp = null;

        if (type != Room.TileType.GROUND)
        {
            CreateGOFromType(v, 0, Room.TileType.GROUND, GetRandomGroundType(), root);
        }
        if (prefabs.ContainsKey(t) && root != null)
        {
            tmp = Object.Instantiate(prefabs[t], root.transform);
            tmp.transform.position = v;
            tmp.transform.Rotate(new Vector3(0, 0, rotation));
        }
        return(tmp);
    }
Esempio n. 3
0
    public GameObject ProcessRoom(Dictionary <Vector2Int, GenTile> tiles)
    {
        GameObject root = new GameObject {
            name = "Room"
        };

        foreach (Vector2Int v in tiles.Keys)
        {
            ExtendedTileType type = GetRandomGroundType();
            int rotation          = 0;
            switch (tiles[v].type)
            {
            case Room.TileType.WALL:
                type     = GetCorrectWallType(tiles, v);
                rotation = GetCorrectWallRotation(tiles, v, type);
                break;

            case Room.TileType.GROUND:
                type = GetRandomGroundType();
                break;

            case Room.TileType.DOOR:
                type     = GetCorrectDoorType(tiles, v);
                rotation = GetCorrectDoorRotation(type, tiles, v);
                break;

            case Room.TileType.ROCK:
                type = GetCorrectRockType(tiles, v);
                break;
            }
            GameObject go = CreateGOFromType(v, rotation, tiles[v].type, type, root);
            // Todo dirty hack
            if (go.tag == "door")
            {
                go.GetComponent <Door>().SetToOuter(GenerationProcessor.GetDirectionVector(tiles[v].position));
            }
        }
        return(root);
    }
Esempio n. 4
0
    private int GetCorrectWallRotation(Dictionary <Vector2Int, GenTile> tiles, Vector2Int v, ExtendedTileType type)
    {
        switch (type)
        {
        case ExtendedTileType.BorderSingle:
            Vector2Int toCheck = v + new Vector2Int(0, -1);
            if (tiles.ContainsKey(toCheck) && tiles[toCheck].type != Room.TileType.WALL)
            {
                return(0);
            }
            toCheck = v + new Vector2Int(-1, 0);
            if (tiles.ContainsKey(toCheck) && tiles[toCheck].type != Room.TileType.WALL)
            {
                return(270);
            }
            toCheck = v + new Vector2Int(0, 1);
            if (tiles.ContainsKey(toCheck) && tiles[toCheck].type != Room.TileType.WALL)
            {
                return(180);
            }
            return(90);

        case ExtendedTileType.BorderInner:
            toCheck = v + new Vector2Int(1, -1);
            if (tiles.ContainsKey(toCheck) && tiles[toCheck].type != Room.TileType.WALL)
            {
                return(0);
            }
            toCheck = v + new Vector2Int(1, 1);
            if (tiles.ContainsKey(toCheck) && tiles[toCheck].type != Room.TileType.WALL)
            {
                return(90);
            }
            toCheck = v + new Vector2Int(-1, 1);
            if (tiles.ContainsKey(toCheck) && tiles[toCheck].type != Room.TileType.WALL)
            {
                return(180);
            }
            return(270);

        case ExtendedTileType.BorderOuter:
            Vector2Int toCheck1 = v + new Vector2Int(0, -1);
            Vector2Int toCheck2 = v + new Vector2Int(-1, 0);
            if (tiles.ContainsKey(toCheck1) && tiles.ContainsKey(toCheck2) && tiles[toCheck1].type != Room.TileType.WALL && tiles[toCheck2].type != Room.TileType.WALL)
            {
                return(270);
            }
            toCheck1 = v + new Vector2Int(0, 1);
            if (tiles.ContainsKey(toCheck1) && tiles.ContainsKey(toCheck2) && tiles[toCheck1].type != Room.TileType.WALL && tiles[toCheck2].type != Room.TileType.WALL)
            {
                return(180);
            }
            toCheck2 = v + new Vector2Int(1, 0);
            if (tiles.ContainsKey(toCheck1) && tiles.ContainsKey(toCheck2) && tiles[toCheck1].type != Room.TileType.WALL && tiles[toCheck2].type != Room.TileType.WALL)
            {
                return(90);
            }
            return(0);
        }
        return(0);
    }