示例#1
0
    private void ClearTiles(GridLayout grid)
    {
        if (activeObject == null)
        {
            return;
        }

        PressurePlateGate gate        = activeObject;
        SpriteRenderer    sprite      = gate.transform.GetComponentInChildren <SpriteRenderer>();
        Vector3Int        gateCellPos = grid.WorldToCell(gate.transform.position);
        Vector3Int        lowerLeft   = grid.WorldToCell(gate.transform.position - (Vector3)(Vector3.one * sprite.size / 2));
        Vector3Int        upperRight  = grid.WorldToCell(gate.transform.position + (Vector3)(Vector3.one * sprite.size / 2));

        foreach (string layerName in ClearTileLayers)
        {
            Transform layer = grid.transform.Find(layerName);
            if (layer == null)
            {
                continue;
            }

            Tilemap tilemap = layer.GetComponent <Tilemap>();
            if (tilemap == null)
            {
                continue;
            }

            tilemap.BoxFill(lowerLeft, upperRight);
        }
    }
示例#2
0
    void Draw(Bounds bnds)
    {
        var min = grid.WorldToCell(bnds.min);
        var max = grid.WorldToCell(bnds.max);

        tilemap.BoxFill(min, unwalkable, min.x, min.y, max.x, max.y);
    }
示例#3
0
    public static void MapBoxFill(ref Tilemap map, ref Tile tile, Vector3Int pos, Vector3Int size)
    {
        var x = pos.x + size.x - 1;
        var y = pos.y + size.y - 1;

        map.BoxFill(pos, tile, pos.x, pos.y, x, y);
    }
示例#4
0
    // Use this for initialization
    void Start()
    {
        //Entnimmt die Tilemap Objekte aus den GameObjects
        map       = mapObject.GetComponent <Tilemap>();
        backTiles = backgroundObject.GetComponent <Tilemap>();
        //Erstmal alle Entfernen
        map.ClearAllTiles();
        backTiles.ClearAllTiles();
        //Map laden
        LevelMap levelData = LevelMap.getDefaultLevelMap();

        //hintergrund befüllen
        backTiles.BoxFill(new Vector3Int((int)levelData.größe.x, (int)levelData.größe.y, 0), backgroundTile, 0, 0, (int)levelData.größe.x, (int)levelData.größe.y);
        //Tiles Spawnen
        for (int x = 0; x <= levelData.größe.x; x++)
        {
            for (int y = 0; y <= levelData.größe.y; y++)
            {
                map.SetTile(new Vector3Int(x, y, 0), tiles[levelData.tiles[x][y]]); //Tile an Position wird zu einem element aus tiles gesetzt
            }
        }
        //Start und Ziel
        map.SetTile(new Vector3Int((int)levelData.start.x, (int)levelData.start.y, 0), tiles[5]);
        map.SetTile(new Vector3Int((int)levelData.ziel.x, (int)levelData.ziel.y, 0), tiles[6]);
    }
示例#5
0
    // Update is called once per frame
    void Update()
    {
        Vector3Int coord  = new Vector3Int(1, 1, 1);
        Vector3Int coord2 = new Vector3Int(10, 10, 10);

        tMap.BoxFill(coord2, tile, -10 - 10, -10, 10, 10);
    }
示例#6
0
 public void Build(Tilemap buildTilemap, TileBase tile, int startX, int startY, int endX, int endY)
 {
     if (buildTilemap == null || tile == null)
     {
         return;
     }
     buildTilemap.BoxFill(Vector3Int.zero, tile, startX, startY, endX, endY);
 }
示例#7
0
 void ClearTile()
 {
     if (tilemap.HasTile(playerPos))
     {
         tilemap.BoxFill(playerPos, EmptyTile, playerPos.x - 2, playerPos.y - 2, playerPos.x + 1, playerPos.y + 1);
         //tilemap.SetTile(playerPos,EmptyTile);
     }
 }
示例#8
0
 public void Clear(Vector3Int?min = null, Vector3Int?max = null)
 {
     if (min == null || max == null)
     {
         tileMap.ClearAllTiles();
     }
     else
     {
         Vector3Int delta = max.Value - min.Value;
         tileMap.BoxFill(min.Value, null, 0, 0, delta.x, delta.y);
     }
 }
示例#9
0
    void Start()
    {
        if (width % 2 != 0 || height % 2 != 0)
        {
            Debug.LogWarning("Grid dimensions will behave unexpectedly with non-even values!");
        }

        // Update tilemap bounds
        tilemap.origin = new Vector3Int(-width / 2 - borderSize, -height / 2 - borderSize, 0);
        tilemap.size   = new Vector3Int(width + borderSize * 2, height + borderSize * 2, 0);

        // Apply tiles
        tilemap.BoxFill(
            Vector3Int.zero,
            borderTile,
            -width / 2 - borderSize,
            -height / 2 - borderSize,
            width / 2 + borderSize,
            height / 2 + borderSize
            );
        tilemap.BoxFill(Vector3Int.zero, groundTile, -width / 2, -height / 2, width / 2, height / 2);
    }
示例#10
0
    public void BoxFillCells(int x, int y, int cellIndex, CellLayer layer, int startX, int startY, int endX, int endY)
    {
        WorldCell cell = null;

        if (cellIndex >= 0 && cellIndex < BaseWorldCells.Count)
        {
            cell = BaseWorldCells[cellIndex];
        }

        var     tilePos = new Vector3Int(x, y, 1);
        Tilemap tilemap = GetTilemap(layer);

        tilemap.BoxFill(tilePos, cell, startX, startY, endX, endY);
    }
示例#11
0
    // for funsies
    //private HashSet<Vector2> spawnerSet;ev

    // Start is called before the first frame update
    void Start()
    {
        main     = this;
        camera   = Camera.main.gameObject;
        player   = PlayerClass.main.gameObject;
        spawners = new List <SpawnerClass>();
        for (int i = 0; i < spritesToMatch.Count; i++)
        {
            spawners.Add(new SpawnerClass(spritesToMatch[i], enemiesToMatch[i]));
        }
        tm = this.gameObject.GetComponent <Tilemap>();
        Vector3Int starter = new Vector3Int(0, 0, 0);

        otherTiles = floorPillars.gameObject.GetComponent <TileSetter>();
        Vector3Int ender = new Vector3Int(otherTiles.getWidth() - 1, otherTiles.getHeight() - 1, 0);

        tm.BoxFill(ender, theFloor, starter.x, starter.y, ender.x, ender.y);
        width  = otherTiles.getWidth();
        height = otherTiles.getHeight();
        //Debug.Log(width);
        initialSpawnersLeft = spawnersLeft;
        for (int i = 0; i < height; i++)
        {
            genRowSpawners(i);
            //Debug.Log(i);
        }
        if (initialSpawnersLeft == spawnersLeft && initialSpawnersLeft > 0)
        {
            Vector3Int  v = new Vector3Int(width - 1, height - 1, 0);
            SpawnerTile t = chooseSpawner(v);
            spawnerTiles.Add(t);
            theSpawners.SetTile(v, t);
        }
        genWalls();
        int larger = Math.Max(width, height);

        camera.transform.position = new Vector3(width / 2.0f, height / 2.0f, -10);
        camera.GetComponent <Camera>().orthographicSize = (camScaling / 10.0f) * larger;
        Vector2[] thePoints = { new Vector2(-20, -20), new Vector2(width + 20, -20), new Vector2(width + 20, height + 20), new Vector2(-20, height + 20), new Vector2(-20, -20) };
        theWalls = GameObject.Find("Walls");
        theWalls.GetComponent <EdgeCollider2D>().points     = thePoints;
        theWalls.GetComponent <EdgeCollider2D>().edgeRadius = 20;
        if (TryGetComponent <RedDragonFloor>(out RedDragonFloor rdf))
        {
            rdf.changeCamera(camera);
        }

        StartCoroutine("beAsleep");
    }
示例#12
0
 void FillMap()
 {
     FloorMap.BoxFill(new Vector3Int(Width - 1, Height - 1, 0), FloorTile, 0, 0, Width, Height);
     for (int x = 0; x < Width; x++)
     {
         for (int y = 0; y < Height; y++)
         {
             if (MapData[x, y])
             {
                 FloorMap.SetTile(new Vector3Int(x, y, 0), null);
                 WallMap.SetTile(new Vector3Int(x, y, 0), WallTile);
             }
         }
     }
 }
示例#13
0
    IEnumerator LavaAscension()
    {
        //Debug.Log("hello !?");
        while (currentHeight < maxYPosition)
        {
            yield return(new WaitForSeconds(speedInterval));

            lavaGrid.size = new Vector3Int(24, currentHeight + ascensionHeight, 0);
            //lavaGrid.size = new Vector3Int(24, 10, 0);
            lavaGrid.BoxFill(new Vector3Int(0, currentHeight, 0), lavaTile, minXPosition, currentHeight, maxXPosition, currentHeight + ascensionHeight - 1);
            //lavaGrid.BoxFill(new Vector3Int(0,2,0), lavaTile, minXPosition, 2, maxXPosition, 4);
            lavaLight.position = new Vector2(0, lavaLight.position.y + ascensionHeight);
            currentHeight     += ascensionHeight;
        }
    }
示例#14
0
    public void add_fog()
    {
        fog_of_war.BoxFill(new Vector3Int(0, 0, 0), fog_base, 0, 0, util_ref.m_gen.x_dim, util_ref.m_gen.y_dim);
        has_seen    = new bool[util_ref.m_gen.x_dim, util_ref.m_gen.y_dim];
        is_visible  = new bool[util_ref.m_gen.x_dim, util_ref.m_gen.y_dim];
        transparent = new bool[util_ref.m_gen.x_dim, util_ref.m_gen.y_dim];

        for (int x = 0; x < util_ref.m_gen.x_dim; x++)
        {
            for (int y = 0; y < util_ref.m_gen.y_dim; y++)
            {
                Vector3Int pos = new Vector3Int(x, y, 0);
                fog_of_war.SetTileFlags(pos, TileFlags.None);
                fog_of_war.SetColor(pos, prev_seen);
                has_seen[x, y]    = false;
                is_visible[x, y]  = false;
                transparent[x, y] = util_ref.m_gen.is_floor[x, y];
            }
        }
    }
示例#15
0
 private void GenerateSky()
 {
     if (level.time == TimeOfDay.Day)
     {
         sun.SetActive(true);
         moon.SetActive(false);
         sunsetSun.SetActive(false);
     }
     else if (level.time == TimeOfDay.Sunset)
     {
         sun.SetActive(false);
         moon.SetActive(false);
         sunsetSun.SetActive(true);
     }
     else
     {
         sun.SetActive(false);
         moon.SetActive(true);
         sunsetSun.SetActive(false);
     }
     skyBackgroundTilemap.BoxFill(Vector3Int.zero, database.timeTiles[(int)level.time], -15, 0, level.extraLength, yRange);
 }
示例#16
0
    void GenerateChunk(Tilemap tilemap, Tile[] tileset, Vector3Int chunk, int baseTilePercent)
    {
        Vector3Int pos = new Vector3Int(chunk.x * chunkWidth, chunk.y * chunkWidth, 0);

        tilemap.SetTile(new Vector3Int(pos.x + chunkWidth - 1, pos.y + chunkWidth - 1, 0), tileset[0]);
        tilemap.BoxFill(pos, tileset[0], pos.x, pos.y, pos.x + chunkWidth - 1, pos.y + chunkWidth - 1);
        for (int x = 0; x < chunkWidth; x++)
        {
            for (int y = 0; y < chunkWidth; y++)
            {
                float rand = Random.Range(0, 100);
                if (rand > baseTilePercent)
                {
                    float max = 100 - baseTilePercent;
                    rand -= baseTilePercent;
                    float result = ((float)rand / (float)max) * (tileset.Length - 1);
                    int   tile   = Mathf.RoundToInt(result);

                    tilemap.SetTile(new Vector3Int(pos.x + x, pos.y + y, 0), tileset[tile]);
                }
            }
        }
    }
示例#17
0
    void LoadMap(int stage)
    {
        //surrounding steel wall
        map.BoxFill(new Vector3Int(-14, -14, 0), steelTile, -14, -14, 13, 13);

        string fileName = @"J:\My Projects\90Tank\Assets\Maps\stage" + stage.ToString() + ".csv";

        print("Load map " + fileName);
        try
        {
            using (StreamReader fileReader = new StreamReader(fileName, System.Text.Encoding.ASCII))
            {
                char[]     b    = new char[52];
                Tile       tile = emptyTile;
                Vector3Int grid = new Vector3Int();
                for (int j = 0; j < 26; j++)
                {
                    string       line = fileReader.ReadLine();
                    StringReader sr   = new StringReader(line);
                    sr.Read(b, 0, 52);
                    for (int i = 0; i < 26; i++)
                    {
                        GameObject wood;
                        char       c = b[i * 2];
                        if (c == 'e')
                        {
                            tile = emptyTile;
                        }
                        else if (c == 'b')
                        {
                            tile = brickTile;
                        }
                        else if (c == 's')
                        {
                            tile = steelTile;
                        }
                        else if (c == 'i')
                        {
                            tile = iceTile;
                        }
                        else if (c == 'f')
                        {
                            //tile = forestTile;
                            tile = emptyTile;
                            wood = Object.Instantiate <GameObject>(woods);
                            wood.transform.position = new Vector3(0.25f * (i - 12.5f), 0.25f * (j - 12.5f));
                        }
                        else if (c == 'r')
                        {
                            tile = riverTile;
                        }
                        else
                        {
                            print("unknown tile:" + i + "," + j + "," + c);
                        }
                        grid.x = i - 13;
                        grid.y = j - 13;
                        map.SetTile(grid, tile);
                    }
                }
            }
        }
        catch (IOException e)
        {
            print("The file could not be read:");
            print(e.Message);
        }
        print("Map loaded");
    }
示例#18
0
    public void Start()
    {
        Random.InitState(Seed);

        // setja fyrsta herbergi niður
        Houses.Add(new House(roomSize));

        //finna stað fyrir næsta herbergi, algorythminn þerf 2 herbergi til að virka, þaðann getur það gert restina
        Vector2 dir      = Random.insideUnitCircle.normalized;
        House   last     = Houses[0];
        House   newHouse = new House(roomSize, new House[1] {
            last
        });

        newHouse.position = ToInt2(last.position + (last.buffer + newHouse.buffer) * dir);
        Houses.Add(newHouse);

        for (int i = 0; i < HouseNum - 2; i++)
        {
            //setja niður restina af herbergjunum
            int  startPoint = 0;
            int  p1Index    = 0;
            bool ended;
            do
            {
                ended = true;
                House p0 = Houses[startPoint];
                House p1;
                newHouse = new House(roomSize);


                do // selecting p1 so it is close enough to fit Newroom between it and p0
                {
                    if (p1Index == startPoint)
                    {
                        p1Index++;
                    }
                    p1Index %= Houses.Count;
                    p1       = Houses[p1Index];
                    p1Index++;
                    //loopið hleypir ekki út fyrr en það er búið að finna rétt hús.
                } while (p1.position.Equals(p0.position) || (p1.position - p0.position).sqrMagnitude > Mathf.Pow(p0.buffer + p1.buffer + newHouse.buffer, 2));


                //staðirnir sem húsið getur verið eru þeir punktar þar sem það snertir bæði p1 og p0
                Vector2[] points = FindTangentCircle(p0, p1, newHouse);
                Vector2   selpoint;

                if (++startPoint >= Houses.Count)
                {
                    startPoint = 0;
                }
                //reyna að nota þann punkt sem er nær miðju
                if (points[0].sqrMagnitude < points[1].sqrMagnitude)
                {
                    selpoint = points[0];
                }
                else
                {
                    selpoint = points[1];
                }
                foreach (var Room in Houses)
                {
                    // passa að sá punktur virki fyrir Húsið
                    if ((selpoint - Room.position).sqrMagnitude < Mathf.Pow(Room.buffer + newHouse.buffer, 2))
                    {
                        ended = false;
                        break;
                    }
                }//ef það virkar ekki nota hinn punktinn
                if (ended == false)
                {
                    ended = true;
                    if (points[0].sqrMagnitude > points[1].sqrMagnitude)
                    {
                        selpoint = points[0];
                    }
                    else
                    {
                        selpoint = points[1];
                    }
                    foreach (var Room in Houses)
                    {
                        if ((selpoint - Room.position).sqrMagnitude < Mathf.Pow(Room.buffer + newHouse.buffer, 2))
                        {
                            ended = false;
                            break;
                        }
                    }
                }
                //notað til að tengja húsin saman með stígum
                newHouse.connectedHouses = new House[2] {
                    p0, p1
                };
                newHouse.position = ToInt2(selpoint);
            } while (!ended);
            Houses.Add(newHouse);
        }

        foreach (House house in Houses)
        {
            //passa að húsið passar inn í tilemappið
            if (Mathf.Abs(tilemap.size.x + tilemap.origin.x) < Mathf.Abs(house.position.x) + house.dimensions.x / 2)
            {
                tilemap.size = new Vector3Int(
                    (Mathf.Abs(house.position.x) + house.dimensions.x - tilemap.origin.x) * 2 + 2,
                    tilemap.size.y, 1);
            }
            if (Mathf.Abs(tilemap.size.y + tilemap.origin.y) < Mathf.Abs(house.position.y) + house.dimensions.y / 2)
            {
                tilemap.size = new Vector3Int(tilemap.size.x,
                                              (Mathf.Abs(house.position.y) + house.dimensions.y - tilemap.origin.y) * 2 + 2,
                                              1);
            }

            tilemap.origin = -(tilemap.size / 2);

            if (house.connectedHouses[0] != null)
            {
                foreach (House otherHouse in house.connectedHouses)
                {
                    if (otherHouse == null)
                    {
                        break;
                    }
                    ///<summary>
                    /// Determine whether the side of a given rectangle that intersects the line between the two given points is vertical
                    /// </summary>
                    bool[] verticality = new bool[2] {
                        house.Verticality(otherHouse.position), otherHouse.Verticality(house.position)
                    };

                    Vector2Int[] WallPoints;

                    if (verticality[0] == verticality[1])
                    {
                        WallPoints = new Vector2Int[4];
                        //the first and last tunnel nodes are the points where the lines intersect with the exits of the rooms.
                        WallPoints[0] = house.position + house.DetExitTile(otherHouse.position - house.position);
                        WallPoints[3] = otherHouse.position + otherHouse.DetExitTile(house.position - otherHouse.position);

                        if (verticality[0])
                        {
                            //the other two nodes are the in the middle of them
                            WallPoints[1] = new Vector2Int((WallPoints[0].x + WallPoints[3].x) / 2, WallPoints[0].y);
                            WallPoints[2] = new Vector2Int((WallPoints[0].x + WallPoints[3].x) / 2, WallPoints[3].y);
                        }
                        else
                        {
                            WallPoints[1] = new Vector2Int(WallPoints[0].x, (WallPoints[0].y + WallPoints[3].y) / 2);
                            WallPoints[2] = new Vector2Int(WallPoints[3].x, (WallPoints[0].y + WallPoints[3].y) / 2);
                        }
                    }
                    else
                    {
                        WallPoints = new Vector2Int[3];

                        WallPoints[0] = house.position + house.DetExitTile(otherHouse.position - house.position);
                        WallPoints[2] = otherHouse.position + otherHouse.DetExitTile(house.position - otherHouse.position);

                        if (verticality[0] && !verticality[1])
                        {
                            WallPoints[1] = new Vector2Int(WallPoints[2].x, WallPoints[0].y);
                        }
                        else
                        {
                            WallPoints[1] = new Vector2Int(WallPoints[0].x, WallPoints[2].y);
                        }
                    }

                    Vector2Int lastPoint = default;
                    foreach (Vector2Int wallPoint in WallPoints)
                    {
                        if (lastPoint != default)
                        {
                            ///TODO: Optimize
                            Vector2Int direction = lastPoint - wallPoint;
                            direction = ToInt2(((Vector2)direction).normalized);
                            Vector2Int currentPoint = wallPoint;
                            while (!currentPoint.Equals(lastPoint))
                            {
                                if (tilemap.GetTile((Vector3Int)currentPoint) == null)
                                {
                                    tilemap.SetTile((Vector3Int)currentPoint, Path);
                                }
                                currentPoint += direction;
                            }
                        }
                        lastPoint = wallPoint;
                    }
                }
            }
            //ástæðan fyrir því að deila dimension með tvemur er að dimension er öll lengdin a fhúsinu en við þurfum bara lengdina frá miðjunni
            tilemap.BoxFill((Vector3Int)house.position, HouseWall,
                            house.position.x - house.dimensions.x / 2,
                            house.position.y - house.dimensions.y / 2,
                            house.position.x + house.dimensions.x / 2,
                            house.position.y + house.dimensions.y / 2);
            tilemap.BoxFill((Vector3Int)house.position, Inside,
                            house.position.x - house.dimensions.x / 2 + 1,
                            house.position.y - house.dimensions.y / 2 + 1,
                            house.position.x + house.dimensions.x / 2 - 1,
                            house.position.y + house.dimensions.y / 2 - 1);
        }
        //minkar minnið sem leikurinn tekur
        tilemap.CompressBounds();
        tilemap.size = new Vector3Int(tilemap.size.x + 12, tilemap.size.y + 12, 1);
        //fillir inn á milli húsa
        for (int iteration = 0; iteration < 6; iteration++)
        {
            List <Vector3Int> newTiles = new List <Vector3Int>();
            for (int x = -tilemap.size.x; x < tilemap.size.x; x++)
            {
                for (int y = -tilemap.size.y; y < tilemap.size.y; y++)
                {
                    if (tilemap.GetTile(new Vector3Int(x, y, 0)) == null)
                    {
                        if (tilemap.GetTile(new Vector3Int(x + 1, y, 0)) != null ||
                            tilemap.GetTile(new Vector3Int(x - 1, y, 0)) != null ||
                            tilemap.GetTile(new Vector3Int(x, y + 1, 0)) != null ||
                            tilemap.GetTile(new Vector3Int(x, y - 1, 0)) != null)
                        {
                            newTiles.Add(new Vector3Int(x, y, 0));
                        }
                    }
                }
            }
            foreach (Vector3Int newTile in newTiles)
            {
                if (iteration > 3)
                {
                    tilemap.SetTile(newTile, OutsideWall);
                }
                else
                {
                    tilemap.SetTile(newTile, Outside);
                }
            }
        }
    }
示例#19
0
 void Start()
 {
     tileMap.BoxFill(new Vector3Int(0, 0, 0), darkness, -40, -40, 10, 10);
 }
示例#20
0
 void Fill(Tile tile, int X1, int Y1, int X2, int Y2)
 {
     grid.BoxFill(new Vector3Int(X1, Y1, 0), tile, X1, Y1, X2, Y2);
 }
示例#21
0
    public void Generate()
    {
        Debug.Log("Generate!");

        targetTilemap.ClearAllTiles();
        targetTilemap.SetTile(new Vector3Int(size.x - 1, size.y - 1, 0), field);

        targetTilemap.BoxFill(Vector3Int.zero, field, 0, 0, size.x - 1, size.y - 1);

        List <MountainSeed> mountain_seeds = new List <MountainSeed>();
        List <SeaSeed>      sea_seeds      = new List <SeaSeed>();
        List <ForestSeed>   forest_seeds   = new List <ForestSeed>();

        // 山の種を作る。
        for (int i = 0; i < mountainSeedCount; ++i)
        {
            int x = Random.Range(2, size.x);
            int y = Random.Range(2, size.y);

            var new_seed = new MountainSeed();
            new_seed.position.x = x;
            new_seed.position.y = y;
            new_seed.influence  = Random.Range(2, 8);

            mountain_seeds.Add(new_seed);
        }
        // 森の種を作る
        for (int i = 0; i < seaSeedCount; ++i)
        {
            int x = Random.Range(2, size.x);
            int y = Random.Range(2, size.y);

            var new_seed = new ForestSeed();
            new_seed.position.x = x;
            new_seed.position.y = y;
            new_seed.influence  = Random.Range(2, 4);

            forest_seeds.Add(new_seed);
        }
        // 湖の種を作る
        for (int i = 0; i < seaSeedCount; ++i)
        {
            int x = Random.Range(2, size.x);
            int y = Random.Range(2, size.y);

            var new_seed = new SeaSeed();
            new_seed.position.x = x;
            new_seed.position.y = y;
            new_seed.influence  = Random.Range(2, 8);

            sea_seeds.Add(new_seed);
        }

        // 山を成長させる。
        for (int i = 0; i < mountain_seeds.Count; ++i)
        {
            var seed = mountain_seeds[i];
            Elevation(seed.position.x, seed.position.y, seed.influence);
        }

        // 森を成長させる。
        for (int i = 0; i < forest_seeds.Count; ++i)
        {
            var seed = forest_seeds[i];
            Sprout(seed.position.x, seed.position.y, seed.influence);
        }

        // 川を成長させます
        for (int i = 0; i < sea_seeds.Count; ++i)
        {
            var seed = sea_seeds[i];
            Erosion(seed.position.x, seed.position.y, seed.influence);
        }

        // プレイヤーの初期位置を設定します(マップの真ん中)
        player.SetTilemap(targetTilemap);
        player.SetPlayerPosition(new Vector2Int(size.x / 2, size.y / 2));

        for (int x = 0; x < town.Length; ++x)
        {
            targetTilemap.SetTile(new Vector3Int(size.x / 2 + x, size.y / 2, 0), town[x]);
            targetTilemap.SetTransformMatrix(new Vector3Int(size.x / 2 + x, size.y / 2, 0), Matrix4x4.identity);
        }
    }
示例#22
0
    List <Vector2Int> deadEndList     = new List <Vector2Int>(); //where deadEnds have been placed

    // Start is called before the first frame update
    void Start()
    {
        wallTilemap.BoxFill(new Vector3Int(0, 0, 0), topTile, -10, -10, size + 10, size + 10);//fill the world

        //finding start and end points
        float dist = 0;            //distance between start and end point

        while (dist < size / 1.5f) //find endpoints that are kinda far apart
        {
            startPoint = new Vector2Int(0, 0);
            endPoint   = new Vector2Int(UnityEngine.Random.Range(0, size - 1), UnityEngine.Random.Range(0, size - 1));
            dist       = Vector2Int.Distance(startPoint, endPoint);
        }
        objectPositions.Add(startPoint);
        objectPositions.Add(endPoint);
        doorPos.position = tilemap.GetCellCenterWorld(new Vector3Int(endPoint.x, endPoint.y, 0)) + new Vector3(0, 0.1f, 0);
        generatePath(startPoint, endPoint);//generate the path from the begining to end
        playerTransform.position = tilemap.CellToWorld(new Vector3Int(startPoint.x, startPoint.y, 0));
        playerTransform.position = new Vector3(playerTransform.position.x, 1, playerTransform.position.z);
        //Debug.Log(tilemap.CellToWorld(new Vector3Int(startPoint.x, startPoint.y, 0)));

        //placing side paths with dead ends
        for (int i = 0; i < deadEnds; i++)
        {
            Vector2Int end = new Vector2Int(UnityEngine.Random.Range(0, size - 1), UnityEngine.Random.Range(0, size - 1));
            deadEndList.Add(end);
            //Debug.Log(end);
            generatePath(filledPoints[UnityEngine.Random.Range(0, filledPoints.Count - 1)], end);
        }

        //add edges
        int j = 0;

        foreach (Vector2Int point in filledPoints)                    //for every point
        {
            if (!filledPoints.Contains(point + new Vector2Int(0, 1))) //if there is not a filled point directly above it
            {
                j++;
                if (j == wallFrequency)//if it hit the iteration, set it to a either a random tile or a torch
                {
                    j = 0;
                    TileBase tile = (UnityEngine.Random.Range(0, 2) >= 1) ? randomWallTile : torchTile;
                    tilemap.SetTile(new Vector3Int(point.x, point.y + 1, 0), wallTile);
                    objectsTilemap.SetTile(new Vector3Int(point.x, point.y + 1, 0), tile);
                    wallTilemap.SetTile(new Vector3Int(point.x, point.y + 1, 0), null);
                }
                else
                {
                    tilemap.SetTile(new Vector3Int(point.x, point.y + 1, 0), wallTile);
                }
                wallTilemap.SetTile(new Vector3Int(point.x, point.y + 1, 0), null);
            }
        }

        //add switches/locks
        for (int z = 0; z < 3; z++)
        {
            bool placed = false;//while it isn't placed
            while (!placed)
            {
                Vector2Int tryPosition = deadEndList[z];//pick a random tile
                objectPositions.Add(tryPosition);
                Vector3 worldPos = tilemap.GetCellCenterWorld(new Vector3Int(tryPosition.x, tryPosition.y, 0));
                //Debug.Log(tilemap.GetCellCenterWorld(new Vector3Int(tryPosition.x, tryPosition.y, 0)));
                //place the lever
                GameObject lev = Instantiate(lever, worldPos, Quaternion.identity);
                lev.tag = lockTags[z];
                //get the hazard
                GameObject barrier = locks[z];
                if (filledPoints.Contains(tryPosition + new Vector2Int(0, 1)))
                {
                    Instantiate(barrier, tilemap.GetCellCenterWorld(new Vector3Int(tryPosition.x, tryPosition.y + 1, 0)), Quaternion.identity, lev.transform);
                }
                if (filledPoints.Contains(tryPosition + new Vector2Int(1, 1)))
                {
                    Instantiate(barrier, tilemap.GetCellCenterWorld(new Vector3Int(tryPosition.x + 1, tryPosition.y + 1, 0)), Quaternion.identity, lev.transform);
                }
                if (filledPoints.Contains(tryPosition + new Vector2Int(1, 0)))
                {
                    Instantiate(barrier, tilemap.GetCellCenterWorld(new Vector3Int(tryPosition.x + 1, tryPosition.y, 0)), Quaternion.identity, lev.transform);
                }
                if (filledPoints.Contains(tryPosition + new Vector2Int(1, -1)))
                {
                    Instantiate(barrier, tilemap.GetCellCenterWorld(new Vector3Int(tryPosition.x + 1, tryPosition.y - 1, 0)), Quaternion.identity, lev.transform);
                }
                if (filledPoints.Contains(tryPosition + new Vector2Int(0, -1)))
                {
                    Instantiate(barrier, tilemap.GetCellCenterWorld(new Vector3Int(tryPosition.x, tryPosition.y - 1, 0)), Quaternion.identity, lev.transform);
                }
                if (filledPoints.Contains(tryPosition + new Vector2Int(-1, -1)))
                {
                    Instantiate(barrier, tilemap.GetCellCenterWorld(new Vector3Int(tryPosition.x - 1, tryPosition.y - 1, 0)), Quaternion.identity, lev.transform);
                }
                if (filledPoints.Contains(tryPosition + new Vector2Int(-1, 0)))
                {
                    Instantiate(barrier, tilemap.GetCellCenterWorld(new Vector3Int(tryPosition.x - 1, tryPosition.y, 0)), Quaternion.identity, lev.transform);
                }
                if (filledPoints.Contains(tryPosition + new Vector2Int(-1, 1)))
                {
                    Instantiate(barrier, tilemap.GetCellCenterWorld(new Vector3Int(tryPosition.x - 1, tryPosition.y + 1, 0)), Quaternion.identity, lev.transform);
                }
                placed = true;
                lev.transform.position += new Vector3(0, 0.1f, 0);
                //}
            }
        }

        //add hazards/distractions
        for (int s = 0; s < numHazards; s++)
        {
            bool placed = false;//while it isn't placed
            while (!placed)
            {
                Vector2Int tryPosition = filledPoints[UnityEngine.Random.Range(0, filledPoints.Count - 1)];//pick a random tile
                bool       isValid     = true;
                foreach (Vector2Int pos in objectPositions)
                {
                    if (Vector2.Distance(pos, tryPosition) < objectDistance)
                    {
                        isValid = false;
                    }
                }
                if (isValid && !isAccessable(tryPosition))//if it's accessable
                {
                    Vector3 worldPos = tilemap.GetCellCenterWorld(new Vector3Int(tryPosition.x, tryPosition.y, 0));
                    objectPositions.Add(tryPosition);
                    //place the distraciton
                    GameObject distraction = distractions[UnityEngine.Random.Range(0, distractions.Length - 1)];
                    GameObject dis         = Instantiate(distraction, worldPos, Quaternion.identity);

                    //get the hazard
                    GameObject hazard = hazards[UnityEngine.Random.Range(0, hazards.Length - 1)];
                    if (filledPoints.Contains(tryPosition + new Vector2Int(0, 1)))
                    {
                        Instantiate(hazard, tilemap.GetCellCenterWorld(new Vector3Int(tryPosition.x, tryPosition.y + 1, 0)), Quaternion.identity, dis.transform);
                    }
                    if (filledPoints.Contains(tryPosition + new Vector2Int(1, 1)))
                    {
                        Instantiate(hazard, tilemap.GetCellCenterWorld(new Vector3Int(tryPosition.x + 1, tryPosition.y + 1, 0)), Quaternion.identity, dis.transform);
                    }
                    if (filledPoints.Contains(tryPosition + new Vector2Int(1, 0)))
                    {
                        Instantiate(hazard, tilemap.GetCellCenterWorld(new Vector3Int(tryPosition.x + 1, tryPosition.y, 0)), Quaternion.identity, dis.transform);
                    }
                    if (filledPoints.Contains(tryPosition + new Vector2Int(1, -1)))
                    {
                        Instantiate(hazard, tilemap.GetCellCenterWorld(new Vector3Int(tryPosition.x + 1, tryPosition.y - 1, 0)), Quaternion.identity, dis.transform);
                    }
                    if (filledPoints.Contains(tryPosition + new Vector2Int(0, -1)))
                    {
                        Instantiate(hazard, tilemap.GetCellCenterWorld(new Vector3Int(tryPosition.x, tryPosition.y - 1, 0)), Quaternion.identity, dis.transform);
                    }
                    if (filledPoints.Contains(tryPosition + new Vector2Int(-1, -1)))
                    {
                        Instantiate(hazard, tilemap.GetCellCenterWorld(new Vector3Int(tryPosition.x - 1, tryPosition.y - 1, 0)), Quaternion.identity, dis.transform);
                    }
                    if (filledPoints.Contains(tryPosition + new Vector2Int(-1, 0)))
                    {
                        Instantiate(hazard, tilemap.GetCellCenterWorld(new Vector3Int(tryPosition.x - 1, tryPosition.y, 0)), Quaternion.identity, dis.transform);
                    }
                    if (filledPoints.Contains(tryPosition + new Vector2Int(-1, 1)))
                    {
                        Instantiate(hazard, tilemap.GetCellCenterWorld(new Vector3Int(tryPosition.x - 1, tryPosition.y + 1, 0)), Quaternion.identity, dis.transform);
                    }
                    placed = true;
                    dis.transform.position += new Vector3(0, 0.1f, 0);
                }
            }
        }



        //add exit door
    }