diff --git a/MrBigsock/Assets/Code/Map/TilemapGenerator.cs b/MrBigsock/Assets/Code/Map/TilemapGenerator.cs index 7d8d53e076629d603b3ddd5322fe82d3b5ae1d87..52d5756a6b41a858c9787e3f3ce6f081d93642bc 100644 --- a/MrBigsock/Assets/Code/Map/TilemapGenerator.cs +++ b/MrBigsock/Assets/Code/Map/TilemapGenerator.cs @@ -14,13 +14,16 @@ namespace Bigsock [SerializeField] PolygonCollider2D polygonCollider; [SerializeField] GameObject Door; [SerializeField] GameObject[] Enemy; + [SerializeField] GameObject Boss; private int z_value = 0; - private static int i = 0; + private static int roomID = 0; static List<Vector3Int> DoorLocations = new List<Vector3Int>(); //static List<Vector2> MapBoudary = new List<Vector2>(); static List<List<Vector2>> MapBoundaryList = new List<List<Vector2>>(); + /* + Makes an array with numbers, where each number decides what type of tile will be on what spot on the floor*/ public int[,] GenerateArray(int width, int height, bool empty) { int[,] map = new int[width, height]; @@ -40,11 +43,11 @@ namespace Bigsock return map; } - public void RenderMap(int[,] map, int roomNr) + public void RenderMap(int[,] map, int roomNr, bool LastRoom) { int doorLocation = Random.Range(0, map.GetUpperBound(0) - 4); //int doorLocation = Random.Range(0, 1); - bool door = false; + bool doorInRoom = false; int doorTop = Random.Range(0, 2); // 0 = bottom, 1 = top int topWallVariable; @@ -116,10 +119,8 @@ namespace Bigsock } else WallTop[roomNr].SetTile(new Vector3Int(x, map.GetUpperBound(1), z_value), tileSetSO.wallTopTile[1]); //Middle part of top wall - - //Check for where the door will be located : when there is no door - if (x == doorLocation && !door) + if (x == doorLocation && !doorInRoom && !LastRoom) { bool doorPlaced = false; for (int x1 = 0; x1 < 4; x1++) @@ -184,13 +185,16 @@ namespace Bigsock WallBottom[roomNr].SetTile(new Vector3Int(x + x1, map.GetLowerBound(0) - 1, z_value), tileSetSO.wallBottomTile[1]); } } - door = true; + doorInRoom = true; x += 3; //Jump x over the door location } } SetMapBoundary(map, roomNr); } + + /* + Gives out the corner points of the room to know how to set the boundries in the world */ public void SetMapBoundary(int[,] map, int roomNr) { List<Vector2> MapBoudary = new List<Vector2>(); @@ -205,16 +209,29 @@ namespace Bigsock MapBoundaryList.Add(MapBoudary); } + /* + Returns the spesific MapBoundry from a list*/ public static List<Vector2> GetRoomBoundary(int i) { return MapBoundaryList[i]; } + /* + Returns the ID of the next room*/ public static int NextRoom() { - return i++; + return roomID++; + } + + /* + Returns the ID of the previous room*/ + public static int LastRoom() + { + return roomID--; } + /* + Spawns enemies inside the boundry of a spesific room by giving it the space the floor ocopay*/ public void SpawnEnemies(int[,] map, int enemies, int roomNr) { foreach (var item in Enemy) @@ -227,12 +244,20 @@ namespace Bigsock { int enemyRandom = Random.Range(0, Enemy.Length); int randomLocation_x = Random.Range(1, map.GetUpperBound(0) - 1); - int randomLocation_y = Random.Range(1, map.GetUpperBound(1) - 1); + int randomLocation_y = Random.Range(map.GetLowerBound(1) + 2, map.GetUpperBound(1) - 1); Instantiate(Enemy[enemyRandom], new Vector3Int((int)FloorTilemap[roomNr].transform.position.x + randomLocation_x, (int)FloorTilemap[roomNr].transform.position.y + randomLocation_y, 0), Quaternion.identity); } } + public void SpawnBoss(int[,] bossRoom, int roomNr) + { + Instantiate(Boss, new Vector3Int((int)FloorTilemap[roomNr].transform.position.x + bossRoom.GetUpperBound(0)/2, + (int)FloorTilemap[roomNr].transform.position.y + bossRoom.GetUpperBound(1) / 2, 0), Quaternion.identity); + } + + /* + Sets new points for where the polygon collider for a room is goint to be set*/ public void polyCollider(int[,] map, int roomNr) { polygonCollider.pathCount = 1; @@ -256,6 +281,8 @@ namespace Bigsock return new Vector3Int(DoorLocations[door].x + 1, DoorLocations[door].y + 3, DoorLocations[door].z); } + /* + Changes the wall on the top of the map to a different tile*/ private void ChangeTopTile(int[,] map, int x, int y, int roomNr) { WallTop[roomNr].SetTile(new Vector3Int(x, y, z_value), null);