- Home /
Roguelike Tutorial Expansion of Layout
Hey there, I have finished the Roguelike Tutorial on this site and I have learned a lot. Now I am trying to figure out how to expand on this game and learn even more. The first thing I wanted to do was expand the layout width and height.
My obvious first thought was to change the variables that control how many rows and columns there are.
public int columns = 8; //Number of columns in our game board.
public int rows = 8; //Number of rows in our game board.
If you take a look at the original code, the writer even commented what these two variables do. Unfortunately, changing these values has no effect. I looked throughout the rest of the code and I just can't seem to find any other way to control the board layout.
This is the last piece of code that may be helpful in answering this question.
void BoardSetup ()
{
//Instantiate Board and set boardHolder to its transform.
boardHolder = new GameObject ("Board").transform;
//Loop along x axis, starting from -1 (to fill corner) with floor or outerwall edge tiles.
for(int x = -1; x < columns + 1; x++)
{
//Loop along y axis, starting from -1 to place floor or outerwall tiles.
for(int y = -1; y < rows + 1; y++)
{ //Choose a random tile from our array of floor tile prefabs and prepare to instantiate it.
GameObject toInstantiate = floorTiles[Random.Range (0,floorTiles.Length)]; //Check if we current position is at board edge, if so choose a random outer wall prefab from our array of outer wall tiles.
if(x == -1 || x == columns || y == -1 || y == rows)
toInstantiate = outerWallTiles [Random.Range (0, outerWallTiles.Length)]; //Instantiate the GameObject instance using the prefab chosen for toInstantiate at the Vector3 corresponding to current grid position in loop, cast it to GameObject.
GameObject instance = Instantiate (toInstantiate, new Vector3 (x, y, 0f), Quaternion.identity) as GameObject;
//Set the parent of our newly instantiated object instance to boardHolder, this is just organizational to avoid cluttering hierarchy.
instance.transform.SetParent (boardHolder);
}
}
}
By the way, tags are pointless if you can't create your own. How are tutorial, rogue, layout, and board not accepted tags?
Answer by tanoshimi · Mar 13, 2015 at 07:47 AM
Those are the variables that you change to alter the width and height. But they're public variables, so you set them in the inspector not in code. Highlight the GameManager prefab as shown:
And, while "tutorial" should perhaps be a tag, tags become pointless if you let people define their own - we'd just get an infinite list. You already have the ability to search the whole site for particular words, tags are designed to group questions into common categories.
Thank you for the response. I actually figured this out yesterday but it took nearly 24 hours for this question to be posted and so I thought it was denied.
Upon expanding my board layout I realize that the board is now offset ins$$anonymous$$d of centred. How would I go about fixing this? I tried adjusting the camera location but that just made things worse.
Answer by TheOneRaven · May 14, 2017 at 12:11 PM
@Tekniko Hey! I was wondering if you figured out how to re-center the offset board after altering its size. I can't seem to figure this one out :/
Your answer
Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
Multiple Cars not working 1 Answer
LocalScale not working idealy 1 Answer
Instantiated Sprite is not rendering. 1 Answer
C# Transform modification. 1 Answer