Search Unity

Trying stuff with the Rogue tutorial

Discussion in 'Getting Started' started by Chachapoya, Jan 14, 2019.

  1. Chachapoya

    Chachapoya

    Joined:
    Jan 14, 2019
    Posts:
    5
    Hello,
    I wanted to try a personnal Tileset with the tutorial project Rogue, but my tileset is way bigger. I know how to reduce my tileset, but i would like to increase the base resolution of the tiles.

    In this tutorial, we never define the base size of a tile.

    I tried to look into the Board Manager script what could define this but I dont get it.
    And there is no grid created outside of the script.



    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using System;
    4. using UnityEngine;
    5. using Random = UnityEngine.Random;
    6.  
    7. public class BoardManager : MonoBehaviour
    8. {
    9.     [Serializable]
    10.     public class Count
    11.     {
    12.         public int minimum;
    13.         public int maximum;
    14.  
    15.         public Count (int min, int max)
    16.         {
    17.             minimum = min;
    18.             maximum = max;
    19.         }
    20.     }
    21.  
    22.     public int columns = 8;
    23.     public int rows = 8;
    24.     public Count wallCount = new Count(5, 9);
    25.     public Count foodCount = new Count(1, 5);
    26.  
    27.     public GameObject exit;
    28.     public GameObject[] floorTiles;
    29.     public GameObject[] outWallTiles;
    30.     public GameObject[] wallTiles;
    31.     public GameObject[] enemyTiles;  
    32.     public GameObject[] foodTiles;
    33.  
    34.     private Transform boardHolder;
    35.     private List<Vector3> gridPositions = new List<Vector3>();
    36.    
    37.     void InitialiseList()
    38.     {
    39.         gridPositions.Clear();
    40.  
    41.         for (int x = 1; x < columns - 1; x++)
    42.         {
    43.             for (int y = 1; y < rows - 1; y++)
    44.             {
    45.                 gridPositions.Add(new Vector3(x, y, 0f));
    46.             }
    47.         }
    48.     }
    49.  
    50.     void BoardSetup ()
    51.     {
    52.         boardHolder = new GameObject("Board").transform;
    53.  
    54.         for (int x = -1; x < columns + 1; x++)
    55.         {
    56.             for (int y = -1; y < rows + 1; y++)
    57.             {
    58.                 GameObject toInstantiate = floorTiles[Random.Range(0, floorTiles.Length)];
    59.  
    60.                 if (x == -1 || x == columns || y == -1 || y == rows)
    61.                     toInstantiate = outWallTiles[Random.Range(0, outWallTiles.Length)];
    62.                 GameObject instance = Instantiate(toInstantiate, new Vector3(x, y, 0f), Quaternion.identity) as GameObject;
    63.  
    64.                 instance.transform.SetParent(boardHolder);
    65.             }
    66.         }
    67.     }
    68.  
    69.     Vector3 RandomPosition()
    70.     {
    71.         int randomIndex = Random.Range(0, gridPositions.Count);
    72.         Vector3 randomPosition = gridPositions[randomIndex];
    73.         gridPositions.RemoveAt(randomIndex);
    74.         return randomPosition;
    75.     }
    76.  
    77.     void LayoutObjectAtRandom(GameObject[] tileArray, int minimum, int maximum)
    78.     {
    79.         int objectCount = Random.Range(minimum, maximum + 1);
    80.         for (int i = 0; i < objectCount; i++)
    81.         {
    82.             Vector3 randomPosition = RandomPosition();
    83.             GameObject tileChoice = tileArray[Random.Range(0, tileArray.Length)];
    84.             Instantiate(tileChoice, randomPosition, Quaternion.identity);
    85.         }
    86.     }
    87.     public void SetupScene(int level)
    88.     {
    89.         BoardSetup();
    90.         InitialiseList();
    91.  
    92.         LayoutObjectAtRandom(wallTiles, wallCount.minimum, wallCount.maximum);
    93.  
    94.         LayoutObjectAtRandom(foodTiles, foodCount.minimum, foodCount.maximum);
    95.  
    96.         int enemyCount = (int)Mathf.Log(level, 2f);
    97.         LayoutObjectAtRandom(enemyTiles, enemyCount, enemyCount);
    98.  
    99.         Instantiate(exit, new Vector3(columns - 1, rows - 1, 0f), Quaternion.identity);
    100.     }
    101. }
    102.