diff --git a/MrBigsock/Assets/Code/Character.cs b/MrBigsock/Assets/Code/Character.cs index 5e263ce6a53557b1e19921c2b2b7cbc0a062afa6..a355487f889102c61792b7021287da7fe8c6932e 100644 --- a/MrBigsock/Assets/Code/Character.cs +++ b/MrBigsock/Assets/Code/Character.cs @@ -217,7 +217,7 @@ namespace BigSock { // Trigger the event for taking damage. OnTakeDamage?.Invoke(this, attack.Actor, attack); - if (TakeDamageAudio != null){ + if(TakeDamageAudio != null && source?.Count > 0 && source[0] != null) { source[0].clip = TakeDamageAudio; source[0].Play(); } diff --git a/MrBigsock/Assets/Code/InteractionSystem/Door.cs b/MrBigsock/Assets/Code/InteractionSystem/Door.cs index caa1b80e84403c5323240ac951b47d1515e6ab15..d90a8a7f49ba39a438a01294923b878ba024ba07 100644 --- a/MrBigsock/Assets/Code/InteractionSystem/Door.cs +++ b/MrBigsock/Assets/Code/InteractionSystem/Door.cs @@ -11,14 +11,15 @@ namespace BigSock.Interact { public Sprite newSprite; private GameObject[] enemies; private GameObject player; - private GameObject cameraPlayer; - private int i = TilemapGenerator.NextRoom(); - private GameObject boundary; + private GameObject cameraPlayer; + private int i = TilemapGenerator.NextRoom(); + private GameObject boundary; - public string InteractionPrompt => _prompt; + public string InteractionPrompt => _prompt; - public bool Interact(Interactor interactor) { - enemies = GameObject.FindGameObjectsWithTag((i - 1).ToString()); + public bool Interact(Interactor interactor) { + if(i > 0)enemies = GameObject.FindGameObjectsWithTag((i - 1).ToString()); + else if (i > 0) enemies = GameObject.FindGameObjectsWithTag((0).ToString()); if (enemies.Length == 0) { Debug.Log("Opening door!"); diff --git a/MrBigsock/Assets/Code/Map/Data/NeigbourParameters_BossRoom.asset b/MrBigsock/Assets/Code/Map/Data/NeigbourParameters_BossRoom.asset new file mode 100644 index 0000000000000000000000000000000000000000..503c5feb1cdb75de9e9d8a5780f9488a432b1089 --- /dev/null +++ b/MrBigsock/Assets/Code/Map/Data/NeigbourParameters_BossRoom.asset @@ -0,0 +1,19 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!114 &11400000 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: fbfb0de6beb24664cbb2d7f616b15910, type: 3} + m_Name: NeigbourParameters_BossRoom + m_EditorClassIdentifier: + width: 0 + height: 0 + smoothCount: 0 + empty: 0 + edgesAreWalls: 0 diff --git a/MrBigsock/Assets/Code/Map/Data/NeigbourParameters_BossRoom.asset.meta b/MrBigsock/Assets/Code/Map/Data/NeigbourParameters_BossRoom.asset.meta new file mode 100644 index 0000000000000000000000000000000000000000..ee83f0066c7078db607d9032f9d2a662e0625145 --- /dev/null +++ b/MrBigsock/Assets/Code/Map/Data/NeigbourParameters_BossRoom.asset.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 87913f8d01ddbaf49bcf053d9da111b9 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 11400000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/MrBigsock/Assets/Code/Map/NeighbourMapGenerator.cs b/MrBigsock/Assets/Code/Map/NeighbourMapGenerator.cs index e70145b59c504735098b31e59fe0f5b744280c82..23e3a32c8bd96c71868207094619988c0d4e8a7e 100644 --- a/MrBigsock/Assets/Code/Map/NeighbourMapGenerator.cs +++ b/MrBigsock/Assets/Code/Map/NeighbourMapGenerator.cs @@ -8,20 +8,26 @@ namespace Bigsock { [SerializeField] protected NeigbourSO[] mapParam; + [SerializeField] NeigbourSO BossRoom; private static List<int[,]> roomList = new List<int[,]>(); public override void RunProceduralGeneration() { - + for (int i = 0; i <= RoomCount - 1; i++) { int randomMap = Random.Range(0, mapParam.Length); int[,] map = tilemapGenerator.GenerateArray(mapParam[randomMap].width, mapParam[randomMap].height, mapParam[randomMap].empty); roomList.Add(map); - tilemapGenerator.RenderMap(roomList[i],i); + tilemapGenerator.RenderMap(roomList[i],i, false); tilemapGenerator.SpawnEnemies(map, 4 + i, i); + } + int[,] bossMap = tilemapGenerator.GenerateArray(BossRoom.width, BossRoom.height, BossRoom.empty); + roomList.Add(bossMap); + tilemapGenerator.RenderMap(roomList[roomList.Count - 1],roomList.Count - 1, true); + tilemapGenerator.SpawnBoss(bossMap, roomList.Count - 1); tilemapGenerator.polyCollider(roomList[0], 0); } @@ -30,5 +36,10 @@ namespace Bigsock { return roomList[i]; } + + public static int GetRoomListCount() + { + return roomList.Count; + } } } \ No newline at end of file diff --git a/MrBigsock/Assets/Code/Map/TilemapGenerator.cs b/MrBigsock/Assets/Code/Map/TilemapGenerator.cs index 7d8d53e076629d603b3ddd5322fe82d3b5ae1d87..a5dd3007e8f0d8bda403ea8f0ce5cf6aeba3370b 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,9 @@ namespace Bigsock } else WallTop[roomNr].SetTile(new Vector3Int(x, map.GetUpperBound(1), z_value), tileSetSO.wallTopTile[1]); //Middle part of top wall - - + int fast = 0; //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 +186,23 @@ namespace Bigsock WallBottom[roomNr].SetTile(new Vector3Int(x + x1, map.GetLowerBound(0) - 1, z_value), tileSetSO.wallBottomTile[1]); } } - door = true; + fast++; + doorInRoom = true; x += 3; //Jump x over the door location } + else if(fast == 0 && LastRoom) + { + DoorLocations.Add(new Vector3Int((int)WallTop[roomNr].transform.position.x + x + 2, + (int)WallTop[roomNr].transform.position.y, z_value)); + fast++; + } } 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 +217,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 +252,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 +289,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); diff --git a/MrBigsock/Assets/Code/Services/PrefabService.cs b/MrBigsock/Assets/Code/Services/PrefabService.cs index d39ec9a4026b39a1d8b7d0aedcb90fd83bf10224..3586eebbc3159b5f31ab2eec9c99ca3e8c25ba8c 100644 --- a/MrBigsock/Assets/Code/Services/PrefabService.cs +++ b/MrBigsock/Assets/Code/Services/PrefabService.cs @@ -41,14 +41,22 @@ namespace BigSock.Service { public GameObject Instance(string name, Vector3? pos = null) => Instance(_prefabs[_sanitize(name)], pos); - private GameObject Instance(GameObject obj, Transform parent) - { + private GameObject Instance(GameObject obj, Transform parent) { var res = MonoBehaviour.Instantiate(obj, parent); return res; } public GameObject Instance(string name, Transform parent) => Instance(_prefabs[_sanitize(name)], parent); + + public GameObject Instance(GameObject obj, Vector3 position, Quaternion rotation, Transform parent) { + return MonoBehaviour.Instantiate(obj, position, rotation, parent); + } + public GameObject Instance(GameObject obj, Vector3 position, Quaternion rotation) { + return MonoBehaviour.Instantiate(obj, position, rotation); + } + + /* Destroy an instance. */ diff --git a/MrBigsock/Assets/Prefabs/Enemy_Slime.prefab b/MrBigsock/Assets/Prefabs/Enemy_Slime.prefab index 7c7624f151db0fb59c56ffd93732208e2e5d56e1..7288d1a079b46defa98c06c69b4a12a876afd657 100644 --- a/MrBigsock/Assets/Prefabs/Enemy_Slime.prefab +++ b/MrBigsock/Assets/Prefabs/Enemy_Slime.prefab @@ -175,7 +175,7 @@ MonoBehaviour: TakeDamageAudio: {fileID: 8300000, guid: f1cd1110ebb2e3f4289a7667f4fea401, type: 3} baseMovementSpeed: 2 baseDamage: 1 - knockbackForce: 2 + knockbackForce: 3 baseHP: 10 baseMaxHP: 10 dropXP: 0 diff --git a/MrBigsock/Assets/Prefabs/attack.prefab b/MrBigsock/Assets/Prefabs/attack.prefab index 3eacefd09b62ecbda996ba020d96fee9d14152f8..8b60b9425a269e7bb29d93d2fdb32a5ada3da3a5 100644 --- a/MrBigsock/Assets/Prefabs/attack.prefab +++ b/MrBigsock/Assets/Prefabs/attack.prefab @@ -105,7 +105,7 @@ BoxCollider2D: m_SpriteTilingProperty: border: {x: 0, y: 0, z: 0, w: 0} pivot: {x: 0.5, y: 0.5} - oldSize: {x: 1.125, y: 0.75} + oldSize: {x: 2.25, y: 1.5} newSize: {x: 1, y: 1} adaptiveTilingThreshold: 0.5 drawMode: 0 diff --git a/MrBigsock/Assets/Prefabs/enemy_orc_range.prefab b/MrBigsock/Assets/Prefabs/enemy_orc_range.prefab index 5d86da904bf40c1508576ae41d25e3a72cbcf475..608d9a23734263d5a8a8866ccf547a00dcb0851c 100644 --- a/MrBigsock/Assets/Prefabs/enemy_orc_range.prefab +++ b/MrBigsock/Assets/Prefabs/enemy_orc_range.prefab @@ -171,10 +171,11 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: baseAttackSpeed: 1 + source: [] TakeDamageAudio: {fileID: 8300000, guid: 0d78a0205a770454c86c53710a0b4ff1, type: 3} baseMovementSpeed: 1 baseDamage: 1 - knockbackForce: 150 + knockbackForce: 2 baseHP: 10 baseMaxHP: 10 dropXP: 0 diff --git a/MrBigsock/Assets/Prefabs/enemy_orc_warrior.prefab b/MrBigsock/Assets/Prefabs/enemy_orc_warrior.prefab index b450ddb288f0b486bf413b312845e27496a8266c..44ec3f20590bb7947b28f15ac2238e9a86356581 100644 --- a/MrBigsock/Assets/Prefabs/enemy_orc_warrior.prefab +++ b/MrBigsock/Assets/Prefabs/enemy_orc_warrior.prefab @@ -144,6 +144,7 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: baseAttackSpeed: 1 + source: [] TakeDamageAudio: {fileID: 8300000, guid: 0d78a0205a770454c86c53710a0b4ff1, type: 3} baseMovementSpeed: 4 baseDamage: 1 diff --git a/MrBigsock/Assets/Prefabs/skleton-range.prefab b/MrBigsock/Assets/Prefabs/skleton-range.prefab index cc83d8c7843789dd5461ec02991a340c9938053e..90b88f7fbb1419bb9759eb630d57476523dc72b0 100644 --- a/MrBigsock/Assets/Prefabs/skleton-range.prefab +++ b/MrBigsock/Assets/Prefabs/skleton-range.prefab @@ -170,9 +170,11 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: baseAttackSpeed: 1 + source: [] + TakeDamageAudio: {fileID: 0} baseMovementSpeed: 1 baseDamage: 1 - knockbackForce: 150 + knockbackForce: 2 baseHP: 10 baseMaxHP: 10 dropXP: 0