예제 #1
0
    protected void MakeHexMap()
    {
        switch (mapShape)
        {
        case MapShape.Rectangle:
            HexMap = new HexMap <TileData, EdgeData>(HexMapBuilder.CreateRectangularShapedMap(rectDimensions));
            break;

        case MapShape.Hexagon:
            HexMap = new HexMap <TileData, EdgeData>(HexMapBuilder.CreateHexagonalShapedMap(hexRadius));
            break;

        default:
            throw new ArgumentOutOfRangeException();
        }



        TileObjects = new GameObject[HexMap.TilesByPosition.Count];

        foreach (Tile <TileData> tile in HexMap.Tiles)
        {
            InstantiateNewTerrainTile(grassTilePrefab, tile);
        }
    }
예제 #2
0
 void Start()
 {
     mapBuilder           = GetComponent <HexMapBuilder>();
     navigationController = GetComponent <NavigationController>();
     player = FindObjectOfType <PlayerController>();
     turn   = Turn.INITIALIZE_GAME;
 }
        private GameObject[] tileObjects;                                            // this will contain all the GameObjects for visualisation purposes, their array index corresponds with the index of our Tiles


        void Start()
        {
            hexMap   = new HexMap <int, bool>(HexMapBuilder.CreateRectangularShapedMap(mapSize), null); //creates a HexMap using one of the pre-defined shapes in the static MapBuilder Class
            hexMouse = gameObject.AddComponent <HexMouse>();                                            //we attach the HexMouse script to the same gameObject this script is attached to, could also attach it anywhere else
            hexMouse.Init(hexMap);                                                                      //initializes the HexMouse
            tileObjects = new GameObject[hexMap.TilesByPosition.Count];                                 //creates an array with the size equal to the number on tiles of the map

            foreach (var tile in hexMap.Tiles)                                                          //loops through all the tiles, assigns them a random value and instantiates and positions a gameObject for each of them.
            {
                tile.Data = (Random.Range(0, 4));
                GameObject instance = GameObject.Instantiate(tilePrefab);
                instance.GetComponent <Renderer>().material = materials[tile.Data];
                instance.name = "MapTile_" + tile.Position;
                instance.transform.position = tile.CartesianPosition;
                tileObjects[tile.Index]     = instance;
            }

            foreach (var edge in hexMap.Edges) //we randomly spawn a GameObject on some corners (could be representing walls or rivers or anything else)
            {
                int randomNumber = Random.Range(0, 100);
                if (randomNumber > 89)
                {
                    edge.Data = true;
                    GameObject instance = GameObject.Instantiate(edgePrefab);
                    instance.name = "MapEdge_" + edge.Position;
                    instance.transform.position = edge.CartesianPosition;
                    instance.transform.rotation = Quaternion.Euler(0, edge.EdgeAlignmentAngle, 0);
                    //as we don't change the edges during runtime we don't need to add the gameObjects of the edges to an array as we don't need to manipulate them later on
                }
            }

            SetupCamera(); //set camera settings so that the map is captured by it
        }
예제 #4
0
        void Start()
        {
            hexMap   = new HexMap <int, bool, bool>(HexMapBuilder.CreateRectangularShapedMapOddRowsOneShorter(mapSize), null);
            hexMouse = gameObject.AddComponent <HexMouse>();
            hexMouse.Init(hexMap);

            InitMap();
            SetupCamera();
        }
        private List <GameObject> visionMarkers;                     //we will use this to display the border of the vision range

        void Start()
        {
            hexMap   = new HexMap <int>(HexMapBuilder.CreateHexagonalShapedMap(mapRadius), null); //creates a HexMap using one of the pre-defined shapes in the static MapBuilder Class
            hexMouse = gameObject.AddComponent <HexMouse>();                                      //we attach the HexMouse script to the same gameObject this script is attached to, could also attach it anywhere else
            hexMouse.Init(hexMap);                                                                //initializes the HexMouse

            InitMap();
            SetupCamera(); //set camera settings so that the map is captured by it
        }
예제 #6
0
        private List <GameObject> reachableTilesMarkers; // the gameObjects we use to visualise which tiles are within movementRange

        void Start()
        {
            hexMap   = new HexMap <MyTile, MyEdge>(HexMapBuilder.CreateRectangularShapedMapOddRowsOneShorter(mapSize), null);
            hexMouse = gameObject.AddComponent <HexMouse>();
            hexMouse.Init(hexMap);

            InitMap();
            reachableTilesMarkers = new List <GameObject>();
            SetupCamera();
        }
예제 #7
0
    void Start()
    {
        hexMap      = new HexMap(HexMapBuilder.CreateRectangularShapedMap(mapSize), null);
        tiles       = new TileData[hexMap.TileCount];
        tileObjects = new GameObject[hexMap.TileCount];

        hexMouse = gameObject.AddComponent <HexMouse>();
        hexMouse.Init(hexMap);
        SetupCamera();
        InitMapData();
        InitMapVisualisation();
    }
예제 #8
0
        private HexMap <int> hexMap;                                             // our map. For this example we create a map where an integer represents the data of each tile (which we don't actually use yet in this example)


        void Start()
        {
            hexMap = new HexMap <int>(HexMapBuilder.CreateRectangularShapedMap(mapSize), null); //creates a HexMap using one of the pre-defined shapes in the static MapBuilder Class

            foreach (var tile in hexMap.Tiles)                                                  //loops through all the tiles, assigns them a random value and instantiates and positions a gameObject for each of them.
            {
                GameObject instance = GameObject.Instantiate(tilePrefab);
                instance.transform.position = tile.CartesianPosition;
            }

            Camera.main.transform.position = new Vector3(hexMap.MapSizeData.center.x, 4, hexMap.MapSizeData.center.z); // centers the camera and moves it 5 units above the XZ-plane
            Camera.main.orthographic       = true;                                                                     //for this example we use an orthographic camera.
            Camera.main.transform.rotation = Quaternion.Euler(90, 0, 0);                                               //rotates the camera to it looks at the XZ-plane
            Camera.main.orthographicSize   = hexMap.MapSizeData.extents.z * 2 * 0.8f;                                  // sets orthographic size of the camera.
        }
    private void MakeHexMap()
    {
        hexMap        = new HexMap <int, bool>(HexMapBuilder.CreateHexagonalShapedMap(mapRadius));
        tileObjects   = new GameObject[hexMap.TilesByPosition.Count];
        visionMarkers = new List <GameObject>();

        foreach (Tile <int> tile in hexMap.Tiles)
        {
            var         types             = Enum.GetValues(typeof(TerrainType));
            Random      random            = new Random();
            TerrainType randomTerrainType = (TerrainType)types.GetValue(Random.Range(0, types.Length));

            GameObject tilePrefab = GetPrefab(randomTerrainType);
            Debug.Log(tilePrefab + " --- " + tile);
            InstantiateNewTerrainTile(tilePrefab, tile);
            tile.Data = (int)randomTerrainType;
        }
    }
예제 #10
0
    private GameObject[] tileObjects; // this will contain all the GameObjects for visualisation purposes, their array index corresponds with the index of our Tiles

    // TODO move the settings to the GameController
    /// <summary>
    /// Generates a new HexMap of environments, at the given offset
    /// </summary>
    /// <returns>The generated map</returns>
    public HexMap <Environment> GenerateMap(int offset)
    {
        Debug.Assert(tilePrefabs != null);

        HexMap <Environment> hexMap = new HexMap <Environment>(HexMapBuilder.CreateHexagonalShapedMap(mapSize), null);

        tileObjects = new GameObject[hexMap.TilesByPosition.Count];      //creates an array with the size equal to the number on tiles of the map
        Transform newMap = new GameObject("HexMap_" + offset).transform; // Make a new folder to put the tiles in

        foreach (var tile in hexMap.Tiles)
        {
            int        i        = Random.Range(0, tilePrefabs.Count);
            GameObject instance = Instantiate(tilePrefabs[i], newMap);
            tile.Data     = instance.GetComponent <Environment>();
            instance.name = instance.name + "_" + tile.Position;
            instance.transform.position = tile.CartesianPosition;
            tileObjects[tile.Index]     = instance;
        }

        return(hexMap);
    }
예제 #11
0
    int GetTileType(double value)
    {
        HexMapBuilder map = (HexMapBuilder)target;

        if (value >= map.waterMin && value < map.waterMax)
        {
            return(1);
        }
        else if (value < map.grassMax)
        {
            return(3);
        }
        else if (value < map.hillMax)
        {
            return(4);
        }
        else if (value < map.mountainMax)
        {
            return(5);
        }

        return(0);
    }
예제 #12
0
    public override void OnInspectorGUI()
    {
        HexMapBuilder map = (HexMapBuilder)target;

        EditorGUI.BeginChangeCheck();
        DrawDefaultInspector();

        if (EditorGUI.EndChangeCheck())
        {
            map.CreateMap();
        }

        EditorGUI.BeginChangeCheck();
        EditorGUILayout.Separator();
        EditorGUILayout.LabelField("Map Generator", EditorStyles.boldLabel);

        if (GUILayout.Button("GenerateSeed"))
        {
            map.seed = UnityEngine.Random.Range(int.MinValue, int.MaxValue);
        }

        map.seed = EditorGUILayout.IntField("Seed", map.seed);
        map.size = EditorGUILayout.IntSlider("Size", map.size, 1, 10);

        EditorGUILayout.LabelField("Noise Parameters");
        map.amp1Hz    = EditorGUILayout.Slider("1Hz", map.amp1Hz, 0f, 1f);
        map.amp10Hz   = EditorGUILayout.Slider("10Hz", map.amp10Hz, 0f, 1f);
        map.amp100Hz  = EditorGUILayout.Slider("100Hz", map.amp100Hz, 0f, 1f);
        map.amp1000Hz = EditorGUILayout.Slider("1000Hz", map.amp1000Hz, 0f, 1f);
        EditorGUILayout.MinMaxSlider("Water", ref map.waterMin, ref map.waterMax, 0f, 100f);
        EditorGUILayout.MinMaxSlider("Grass", ref map.waterMax, ref map.grassMax, 0, 100);
        EditorGUILayout.MinMaxSlider("Hill", ref map.grassMax, ref map.hillMax, 0, 100);
        EditorGUILayout.MinMaxSlider("Mountain", ref map.hillMax, ref map.mountainMax, 0, 100);

        if (!EditorGUI.EndChangeCheck())
        {
            return;
        }

        var random          = new System.Random(map.seed);
        var tiles           = new StringBuilder();
        var offset1Hz       = (float)random.NextDouble();
        var offset10Hz      = (float)random.NextDouble();
        var offset100Hz     = (float)random.NextDouble();
        var offset1000Hz    = (float)random.NextDouble();
        var variancey1Hz    = (float)random.NextDouble();
        var variancex1Hz    = (float)random.NextDouble();
        var variancey10Hz   = (float)random.NextDouble() * 10f + 5f;
        var variancex10Hz   = (float)random.NextDouble() * 10f + 5f;
        var variancey100Hz  = (float)random.NextDouble() * 100f + 50f;
        var variancex100Hz  = (float)random.NextDouble() * 100f + 50f;
        var variancey1000Hz = (float)random.NextDouble() * 1000f + 500f;
        var variancex1000Hz = (float)random.NextDouble() * 1000f + 500f;

        Vector3 center = new Vector3(map.size - 1, map.size - 1, 2 - map.size * 2);

        for (int y = (map.size - 1) * 2; y >= 0; y--)
        {
            for (int x = 0; x < (map.size - 1) * 2 + 1; x++)
            {
                var pos      = new Vector3(y, x, -y - x);
                var dir      = (pos - center);
                var distance = (Math.Abs(dir.x) + Math.Abs(dir.y) + Math.Abs(dir.z)) / 2.0;
                if (distance < map.size)
                {
                    var value = map.amp1Hz * Math.Sin(y * variancey1Hz + x * variancex1Hz + offset1Hz)
                                + map.amp10Hz * Math.Sin(y * variancey10Hz + x * variancex10Hz + offset10Hz)
                                + map.amp100Hz * Math.Sin(y * variancey100Hz + x * variancex100Hz + offset100Hz)
                                + map.amp1000Hz * Math.Sin(y * variancey1000Hz + x * variancex1000Hz + offset1000Hz);
                    var amp = map.amp1Hz + map.amp10Hz + map.amp100Hz + map.amp1000Hz;
                    value = (value / amp + 1f) * 50f;
                    int tileType = GetTileType(value);
                    tiles.Append(tileType).Append(' ');
                }
                else
                {
                    tiles.Append("0 ");
                }
            }

            tiles.Append("\n");
        }

        map.setMapData(tiles.ToString());
    }