Hi, I am working on a rpg game. I have been able to randomly generate an area, but I'd like to make rooms and corridors, but I do not understand how the Roguelike algorithm works in Unity after a lot of research. Could someone explain it to me?
"the roguelike algorithm" ... there are many ways of approaching building a dungeon. Which one have you researched? maybe narrow it down to "I don't understand this bit of this algorithm" rather than asking such an open ended question.
You're right! I have read about the standard algorithm used in the game Rogue from the 80's, this algorith is nowadays called the Roguelike algorithm. I have read a lot about how it works on these two sites and I totally understand what they mean: http://kuoi.org/~kamikaze/GameDesign/art07_rogue_dungeon.php http://www.roguebasin.com/index.php?title=Dungeon-Building_Algorithm My problem however is that I do not know how I should program this in C#. This is the C++ example I read, but it's not really helping :/ http://www.roguebasin.com/index.php?title=C++_Example_of_Dungeon-Building_Algorithm
Better try the following one. http://gamedevelopment.tutsplus.com...ngeons-with-procedural-recipes--gamedev-14360
Well, I'd like to just create cubes for the walls and the floor, something like this (not the ASCII) https://www.youtube.com/watch?v=GfbfYp7cJXQ
These are the steps you have to make for the algorithm and I do not how to code these (not even step 1 ) in Unity in C#: - Fill the whole map with solid earth - Dig out a single room in the centre of the map - Pick a wall of any room - Decide upon a new feature to build - See if there is room to add the new feature through the chosen wall - If yes, continue. If no, go back to step 3 - Add the feature through the chosen wall - Go back to step 3, until the dungeon is complete - Add the up and down staircases at random points in map - Finally, sprinkle some monsters and items liberally over dungeon
I have step one working (was not hard at all, but how can I create the rooms: Code (csharp): using UnityEngine; using System.Collections; public class Map : MonoBehaviour { public bool generated = false; public float screenWidth; public float screenHeight; public int width = 20; public int height = 20; public UnityEngine.Texture Blue; public UnityEngine.Texture Border; // Use this for initialization void Start () { screenWidth = Screen.width; screenHeight = Screen.height; } // Update is called once per frame void Update () { if (generated == false) { for (int y = 0; y < height; y++) { GameObject cube = GameObject.CreatePrimitive (PrimitiveType.Cube); cube.transform.position = new Vector3 (y + 1, 0, 0); cube.name = "MapTiles"; cube.renderer.material.mainTexture = Blue; for (int x = 0; x < width; x++) { GameObject cubetwee = GameObject.CreatePrimitive (PrimitiveType.Cube); cubetwee.transform.position = new Vector3 (y + 1, x + 1, 0); cubetwee.name = "Maptiles"; cubetwee.renderer.material.mainTexture = Blue; } } generated = true; } } }
Okay, so you're filling an area with cubes. I think it would be useful to put those cubes into a 2 dimensional array, so you can access them if you're erasing them. Code (csharp): public GameObject [] squares; ... squares = new GameObject [width , height];
How should I do that? I made this code and it generates some rooms: Code (csharp): using UnityEngine; using System.Collections; public class Map : MonoBehaviour { public bool generated = false; public bool lakegenerated = false; public float screenWidth; public float screenHeight; public int width = 20; public int height = 20; public UnityEngine.Texture Blue; public UnityEngine.Texture Border; public Transform Grass; public Transform Water; public int LakeAmount; public int LakeWidth; public int LakeHeight; public int LakePositionX; public int LakePositionY; // Use this for initialization void Start () { screenWidth = Screen.width; screenHeight = Screen.height; } // Update is called once per frame void Update () { if (generated == false) { for (int y = 0; y < height; y++) { { for (int x = -1; x < width; x++){ Instantiate(Grass, new Vector3 (y , x + 1, 0), Quaternion.identity); } } } generated = true; } if (lakegenerated == false) { for (int amount = 0; amount < LakeAmount; amount++) { LakeWidth = Random.Range (3, 15); LakeHeight = Random.Range (3, 15); LakePositionX = Random.Range (0, width - LakeWidth); LakePositionY = Random.Range (0, height - LakeHeight); for (int heightlake = 0; heightlake < LakeHeight (heightlake + LakePositionY) < height; heightlake++) { for (int widthlake = 0; widthlake < LakeWidth (widthlake + LakePositionX) < width; widthlake ++){ Instantiate(Water, new Vector3 (LakePositionX + heightlake , LakePositionY + widthlake + 1, 0), Quaternion.identity); } } } lakegenerated = true; } } }