コード例 #1
0
ファイル: SRChunkManager.cs プロジェクト: EliasFarhan/PCG917
    void CreateDoor(Vector2Int chunkPos1, Vector2Int chunkPos2)
    {
        Vector2Int deltaPos = chunkPos2 - chunkPos1;

        SRDoor door1 = ScriptableObject.CreateInstance <SRDoor>();
        SRDoor door2 = ScriptableObject.CreateInstance <SRDoor>();

        if (deltaPos == Vector2Int.down)
        {
            door1.Pos.x    = Random.Range(2, SRChunk.SizeX - 2);
            door1.Pos.y    = 0;
            door2.Pos.x    = door1.Pos.x;
            door2.Pos.y    = SRChunk.SizeY - 1;
            door1.Vertical = false;
            door2.Vertical = false;
        }
        else if (deltaPos == Vector2Int.up)
        {
            door2.Pos.x = Random.Range(2, SRChunk.SizeX - 2);
            door2.Pos.y = 0;
            door1.Pos.x = door2.Pos.x;
            door1.Pos.y = SRChunk.SizeY - 1;

            door1.Vertical = false;

            door2.Vertical = false;
        }
        else if (deltaPos == Vector2Int.right)
        {
            door2.Pos.x = 0;
            door2.Pos.y = Random.Range(2, SRChunk.SizeY - 2);
            door1.Pos.x = SRChunk.SizeX - 1;
            door1.Pos.y = door2.Pos.y;

            door1.Vertical = true;

            door2.Vertical = true;
        }
        else if (deltaPos == Vector2Int.left)
        {
            door1.Pos.x = 0;
            door1.Pos.y = Random.Range(2, SRChunk.SizeY - 2);
            door2.Pos.x = SRChunk.SizeX - 1;
            door2.Pos.y = door1.Pos.y;

            door1.Vertical = true;

            door2.Vertical = true;
        }
        else
        {
            return;
        }

        _envChunks[chunkPos1.x, chunkPos1.y].AddDoor(door1);
        _envChunks[chunkPos2.x, chunkPos2.y].AddDoor(door2);
    }
コード例 #2
0
ファイル: SRChunk.cs プロジェクト: EliasFarhan/PCG917
 //Doors are 3 tiles long
 public void AddDoor(SRDoor newDoor)
 {
     if (newDoor.Vertical)
     {
         for (int j = -1; j <= 1; j++)
         {
             _chunkTilemap.SetTile(
                 new Vector3Int(newDoor.Pos.x - SizeX / 2, newDoor.Pos.y + j - SizeY / 2, 0),
                 null);
         }
     }
     else
     {
         for (int i = -1; i <= 1; i++)
         {
             _chunkTilemap.SetTile(
                 new Vector3Int(newDoor.Pos.x + i - SizeX / 2, newDoor.Pos.y - SizeY / 2, 0),
                 null);
         }
     }
     _doors.Add(newDoor);
 }