Exemple #1
0
    void ConstructTexture()
    {
        tdMap = new TDMap(size_x, size_z);

        int       texWidth  = size_x * tileResolution;
        int       texHeight = size_z * tileResolution;
        Texture2D texture   = new Texture2D(texWidth, texHeight);

        Color[][] tiles = ChopUpTiles();

        for (int y = 0; y < size_z; y++)
        {
            for (int x = 0; x < size_x; x++)
            {
                Color[] p = tiles[(int)tdMap.GetTileAt(x, y).type];
                texture.SetPixels(x * tileResolution, y * tileResolution, tileResolution, tileResolution, p);
            }
        }

        texture.filterMode = FilterMode.Point;
        texture.wrapMode   = TextureWrapMode.Clamp;
        texture.Apply();

        MeshRenderer mesh_renderer = GetComponent <MeshRenderer>();

        mesh_renderer.sharedMaterials[0].mainTexture = texture;

        Debug.Log("Done Texture!");
    }
Exemple #2
0
    void BuildTexture()
    {
        TDMap map = new TDMap(sizeX, sizeZ);

        int textWidth  = sizeX * tileResolution;
        int textHeight = sizeZ * tileResolution;

        // Create a new texture 10 x 10 px
        Texture2D texture = new Texture2D(textWidth, textHeight);

        Color[][] tiles = ChopUpTiles();

        for (int y = 0; y < sizeZ; y++)
        {
            for (int x = 0; x < sizeX; x++)
            {
                Color[] p = tiles[map.GetTileAt(x, y)];
                texture.SetPixels(x * tileResolution, y * tileResolution, tileResolution, tileResolution, p);
            }
        }

        // For sharp edges
        texture.filterMode = FilterMode.Point;
        texture.wrapMode   = TextureWrapMode.Clamp;

        // Apply the textures
        texture.Apply();

        MeshRenderer mr = GetComponent <MeshRenderer> ();

        mr.sharedMaterials [0].mainTexture = texture;
    }
Exemple #3
0
    // create the map texture to be thrown into the UV
    void BuildTexture()
    {
        TDMap map = new TDMap(mapSizeWidth, mapSizeHeight, minRoomSize, maxRoomSize, totalRooms, seed, noiseFactor);

        int       textWidth  = mapSizeWidth * tileResolution;
        int       textHeight = mapSizeHeight * tileResolution;
        Texture2D texture    = new Texture2D(textWidth, textHeight);

        Color[][] tiles = ChopUpTiles();

        for (int y = 0; y < mapSizeHeight; y++)
        {
            for (int x = 0; x < mapSizeWidth; x++)
            {
                Color[] p = tiles[map.GetTileAt(x, y)];
                texture.SetPixels(x * tileResolution, y * tileResolution, tileResolution, tileResolution, p);
            }
        }

        texture.filterMode = FilterMode.Point;
        texture.wrapMode   = TextureWrapMode.Clamp;
        texture.Apply();

        MeshRenderer mesh_renderer = GetComponent <MeshRenderer>();

        mesh_renderer.sharedMaterials[0].mainTexture = texture;

        Debug.Log("Done Texture.");
    }
Exemple #4
0
    void BuildTexture()
    {
        TDMap map = new TDMap(size_x, size_y, mapType);

        int[,] mapData = map.GetMapDataAsInt();
        int       textureWidth  = size_x * tileResolution;
        int       textureHeight = size_y * tileResolution;
        Texture2D texture       = new Texture2D(textureWidth, textureHeight);

        Color[][] tiles = ChopUpTiles();
        Color[]   paint;
        for (int y = 0; y < size_y; y++)
        {
            for (int x = 0; x < size_x; x++)
            {
                paint = tiles[mapData[x, y]];
                texture.SetPixels(x * tileResolution, y * tileResolution, tileResolution, tileResolution, paint);
            }
        }

        texture.filterMode = FilterMode.Point;
        texture.wrapMode   = TextureWrapMode.Clamp;
        texture.Apply();

        MeshRenderer meshRenderer = GetComponent <MeshRenderer> ();

        //Debug.Log (meshRenderer.sharedMaterials[0]);
        //meshRenderer.sharedMaterials[0].mainTexture = texture;
        meshRenderer.materials[0].mainTexture = texture;

        //Debug.Log("Texture Complete!");
    }
Exemple #5
0
    void BuildTexture()
    {
        map = new TDMap(gridSizeX, gridSizeZ);

        int texWidth  = gridSizeX * tileResolution;
        int texHeight = gridSizeZ * tileResolution;

        texture    = new Texture2D(texWidth, texHeight);
        oldTexture = new Texture2D(texWidth, texHeight);

        for (int y = 0; y < gridSizeZ; y++)
        {
            for (int x = 0; x < gridSizeX; x++)
            {
                TDTile tile = map.GetTile(x, y);
                if (tile == null)
                {
                    continue;
                }

                //texture.SetPixels(x * tileResolution, y * tileResolution, tileResolution, tileResolution, tilePixels[tile.GetTileType()]);
                texture.SetPixels(x * tileResolution, y * tileResolution, tileResolution, tileResolution, spriteArray[tile.GetTileType()]);
            }
        }

        texture.filterMode = FilterMode.Point;
        texture.wrapMode   = TextureWrapMode.Clamp;
        texture.Apply();

        MeshRenderer meshRenderer = GetComponent <MeshRenderer>();

        meshRenderer.sharedMaterials[0].mainTexture = texture;

        Debug.Log("Done Texture!");
    }
Exemple #6
0
 public TDTile(int x, int y, TDMap map, string type)
 {
     this.x      = x;
     this.y      = y;
     this.map    = map;
     this.type   = type;
     this.Height = 0;
 }
Exemple #7
0
        public TileMapPathData(TDMap p_map)
        {
            m_tilePathMap = new TilePathDataNode[p_map.Width, p_map.Height];

            for (int i = 0; i < p_map.Width; i++)
            {
                for (int j = 0; j < p_map.Height; j++)
                {
                    m_tilePathMap[i, j] = new TilePathDataNode(p_map, new Coord(i, j));
                }
            }
        }
Exemple #8
0
        public void SendTruckToTile(EGFiretruck truckToSend, int x, int y)
        {
            TDPath truckPath = new TDPath();
            TDMap  dataMap   = _map.Map;

            truckPath.BuildPath(dataMap,
                                dataMap.GetTile(Mathf.FloorToInt(truckToSend.GetPosition().x), Mathf.FloorToInt(-truckToSend.GetPosition().z)),
                                dataMap.GetTile(x, y));
            truckToSend.SetPath(truckPath);
            truckToSend.SetIdle(false);

            _dispatcher.AddActiveTruck(truckToSend);
        }
Exemple #9
0
    // Use this for initialization
    void Start()
    {
        int numTilesPerRow = terrainTiles.width / tileResolution;
        int numRows        = terrainTiles.height / tileResolution;

        tileDataMap = new TDMap(size_x, size_z, terrainTiles, numRows, numTilesPerRow);

        PathSearch tempPathSearch = (PathSearch)FindObjectOfType(typeof(PathSearch));

        tempPathSearch.SetTileNodeList(tileDataMap.Tiles, size_x);

        BuildMesh();
    }
Exemple #10
0
    void XMLWrite(string name, TDMap t)
    {
        MapName = name;
        toSave  = t.mapData;
        int x = 0;


        DirectoryInfo d = new DirectoryInfo(Environment.CurrentDirectory);
        string        p = d.FullName + @"\Assets\Maps\";

        d = new DirectoryInfo(p);

        string originalName = name;

        FileInfo[] files      = d.GetFiles();
        bool       fileExists = false;

        for (int j = 0; j < files.Length; j++)
        {
            if (files[j].Name.Equals(MapName + ".xml"))
            {
                fileExists = true;
            }
        }

        while (fileExists)
        {
            MapName = originalName + "(" + x + ")";
            x++;
            fileExists = false;
            for (int j = 0; j < files.Length; j++)
            {
                if (files[j].Name.Equals(MapName + ".xml"))
                {
                    fileExists = true;
                }
            }
        }


        XmlWriterSettings mySettings = new XmlWriterSettings();

        mySettings.Indent          = true;
        mySettings.IndentChars     = ("\t");
        mySettings.NewLineHandling = NewLineHandling.Entitize;
        writer = XmlWriter.Create(p + MapName + ".xml", mySettings);
    }
Exemple #11
0
    public OnMapGenerator(TDMap map, int size_x, int size_y, float tile_size, Transform MapTransform)
    {
        this.size_x       = size_x;
        this.size_y       = size_y;
        this.map          = map;
        this.MapTransform = MapTransform;
        this.tile_size    = tile_size;

        ChanceTree       = TGMap.instance.ChanceTree;
        ChanceVegetation = TGMap.instance.ChanceVegetation;

        DeleteOld(MapTransform);

        plant_prefab = (GameObject)Resources.Load("Prefabs/plant");
        trees        = Resources.LoadAll <GameObject>("Envitoment/threes");

        foreach (natureType t in EnumCheck <natureType> .GetEnumValues())
        {
            nature.Add(t, new List <Sprite>());
        }


        Debug.Log("done");
        foreach (Sprite s in Resources.LoadAll <Sprite>("Envitoment/natureT"))
        {
            if (s.name.Contains("plant"))
            {
                nature[natureType.plant].Add(s);
            }
            else if (s.name.Contains("leaves"))
            {
                nature[natureType.leaves].Add(s);
            }
            else if (s.name.Contains("bush"))
            {
                nature[natureType.bush].Add(s);
            }
        }
    }
    // Update is called once per frame
    void Update()
    {
        bool firstRun = true;
        if (firstRun)
        {
            map = _TGMap.getMapData();
            firstRun = false;
        }

        Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
        RaycastHit hitInfo;

        if (_TGMap.GetComponent<Collider>().Raycast(ray, out hitInfo, Mathf.Infinity))
        {
            int x = Mathf.FloorToInt(hitInfo.point.x / _TGMap.tileSize);
            int z = Mathf.FloorToInt(hitInfo.point.z / _TGMap.tileSize);

            currentTileCoord.x = x;
            currentTileCoord.z = z;
            selectionCube.transform.position = currentTileCoord * _TGMap.tileSize;
        }
        else
        {

        }

        if (Input.GetMouseButtonDown(0))
        {
            occupy = map.getTile((int)playerSelectedCoord.x, (int)playerSelectedCoord.z);
            if (map.getTile((int)currentTileCoord.x, (int)currentTileCoord.z).getOccupied() == 1)
            {
                playerSelected = true;
                Debug.Log("Player Selected" + map.getTile((int)currentTileCoord.x, (int)currentTileCoord.z));
                playerSelectedCoord = new Vector3(currentTileCoord.x, 0, currentTileCoord.z);

            }
            else if (map.getTile((int)currentTileCoord.x, (int)currentTileCoord.z).getOccupied() == 0 && playerSelected == true)
            {
                playerSelected = false;
                Debug.Log("Player Moved New coord: " + map.getTile((int)currentTileCoord.x, (int)currentTileCoord.z));
                Debug.Log("Player Moved Old coord: " + map.getTile((int)playerSelectedCoord.x, (int)playerSelectedCoord.z));
                path = checkPath(map, map.getTile((int)playerSelectedCoord.x, (int)playerSelectedCoord.z), 7);

                if (path != null)
                {
                    Debug.Log(path);
                    Debug.Log(path.path[0]);
                    moving = path.path.Count - 1;
                }

            }

        }
        if(Input.GetMouseButtonDown(1))
        {
            if (map.getTile((int)currentTileCoord.x, (int)currentTileCoord.z).getOccupied() == 2)
            {
                opponent = map.getTile((int)currentTileCoord.x, (int)currentTileCoord.z);
                attacker = map.getTile((int)playerSelectedCoord.x, (int)playerSelectedCoord.z);
                float hitRoll = Random.Range(0, 10);
                float cover = 0;
                //cover calculations
                Debug.Log(opponent.x + "And" + attacker.x + "ys = " + opponent.y + "And " + attacker.y);
                Debug.Log("Neighbors: " + map.getTile(opponent.findNeighbors()[0]).getType() + ", " + map.getTile(opponent.findNeighbors()[1]).getType() + ", " + map.getTile(opponent.findNeighbors()[2]).getType() + ", " + map.getTile(opponent.findNeighbors()[3]).getType());
                //Left cover
                if ((opponent.x > attacker.x && map.getTile(opponent.findNeighbors()[1]).getType() == 3)&& !((Mathf.Abs(opponent.x-attacker.x) == 1 && (map.getTile(attacker.findNeighbors()[0]).getType() == 3)) || map.getTile(attacker.findNeighbors()[3]).getType() == 3))
                {
                    Debug.Log("Covered! Left");
                    cover = 2;
                }
                //Right Cover
                else if (opponent.x < attacker.x && map.getTile(opponent.findNeighbors()[2]).getType() == 3 && !((Mathf.Abs(opponent.x - attacker.x) == 1 && (map.getTile(attacker.findNeighbors()[0]).getType() == 3)) || map.getTile(attacker.findNeighbors()[3]).getType() == 3))
                {
                    Debug.Log("Covered! Right");
                    cover = 2;
                }
                //Down Cover
                else if (opponent.y > attacker.y && map.getTile(opponent.findNeighbors()[0]).getType() == 3 && !((Mathf.Abs(opponent.y - attacker.y) == 1 && (map.getTile(attacker.findNeighbors()[1]).getType() == 3)) || map.getTile(attacker.findNeighbors()[2]).getType() == 3))
                {
                    Debug.Log("Covered! Down");
                    cover = 2;
                }
                //Up Cover
                else if (opponent.y < attacker.y && map.getTile(opponent.findNeighbors()[3]).getType() == 3 && !((Mathf.Abs(opponent.y - attacker.y) == 1 && (map.getTile(attacker.findNeighbors()[1]).getType() == 3)) || map.getTile(attacker.findNeighbors()[2]).getType() == 3))
                {
                    Debug.Log("Covered! Up");
                    cover = 2;
                }
                Debug.Log("Cover Bonus! " + cover);
                //hit
                Debug.Log("HitRoll = " + hitRoll);
                if((hitRoll - (cover * 3)) > 1) //90% base, -30 for half, -60 for fullcover
                {
                    opponent.getEnemy().setHealth(opponent.getEnemy().getHealth() - 3);
                    Debug.Log("Hit! Health: " + opponent.getEnemy().getHealth());
                }
                else
                {

                }
                if(opponent.getEnemy().getHealth() <= 0)
                {
                    opponent.setOccupied(0);
                }
                _TGMap.UpdateGraphics();

            }
        }
        if (moving >= 0)
        {
            TDTile next = (TDTile)path.getPath()[moving];
            Debug.Log(moving);
            occupy.removePlayer();
            map.setTile(next.position, 1, 1);
            map.setTile(occupy.position, 1, 0);
            occupy.switchPlayers(next);
            occupy = next;
            _TGMap.UpdateGraphics();
            moving -= 1;
        }
    }
Exemple #13
0
    void BuildTexture()
    {
        TDMap map = new TDMap (size_x, size_y, mapType);
        int[,] mapData = map.GetMapDataAsInt();
        int textureWidth = size_x * tileResolution;
        int textureHeight = size_y * tileResolution;
        Texture2D texture = new Texture2D(textureWidth, textureHeight);

        Color[][] tiles = ChopUpTiles();
        Color[] paint;
        for (int y = 0; y < size_y; y++) {
            for (int x = 0; x < size_x; x++) {
                paint = tiles[mapData[x, y]];
                texture.SetPixels ( x * tileResolution, y * tileResolution, tileResolution, tileResolution, paint);
            }
        }

        texture.filterMode = FilterMode.Point;
        texture.wrapMode = TextureWrapMode.Clamp;
        texture.Apply ();

        MeshRenderer meshRenderer = GetComponent<MeshRenderer> ();
        //Debug.Log (meshRenderer.sharedMaterials[0]);
        //meshRenderer.sharedMaterials[0].mainTexture = texture;
        meshRenderer.materials[0].mainTexture = texture;

        //Debug.Log("Texture Complete!");
    }
Exemple #14
0
    public void BuildMesh()
    {
        map = new TDMap(size_x / (int)tileSize, size_z / (int)tileSize);
        int numTiles = size_x * size_z;
        int numTris = numTiles * 2;

        int vsize_x = size_x + 1;
        int vsize_z = size_z + 1;
        int numVerts = vsize_x * vsize_z;

        // Generate the mesh data

        Vector3[] vertices = new Vector3[numVerts];
        Vector3[] normals = new Vector3[numVerts];
        Vector2[] uv = new Vector2[numVerts];

        int[] triangles = new int[numTris * 3];

        int x, z;
        int[] Relevamt = TextureInitialization.getRedAssets();
        //int[] heightMap = TextureInitialization.getRedAssets();
        for (z = 0; z < vsize_z; z++)
        {
            for (x = 0; x < vsize_x; x++)
            {
                int height = Relevamt[z* vsize_x + x];//heightMap[z * vsize_x  + x];
                vertices[z * vsize_x + x] = new Vector3(x * tileSize, height, z * tileSize);
                normals[z * vsize_x + x] = Vector3.up;
                uv[z * vsize_x + x] = new Vector2((float)x / size_x, (float)z / size_z);
            }
           //Debug.Log(""+ heightMap[z*vsize_x + 1]);
        }
        Debug.Log("Done Verts!");

        for (z = 0; z < size_z; z++)
        {
            for (x = 0; x < size_x; x++)
            {
                int squareIndex = z * size_x + x;
                int triOffset = squareIndex * 6;
                triangles[triOffset + 0] = z * vsize_x + x + 0;
                triangles[triOffset + 1] = z * vsize_x + x + vsize_x + 0;
                triangles[triOffset + 2] = z * vsize_x + x + vsize_x + 1;

                triangles[triOffset + 3] = z * vsize_x + x + 0;
                triangles[triOffset + 4] = z * vsize_x + x + vsize_x + 1;
                triangles[triOffset + 5] = z * vsize_x + x + 1;
            }
        }

        Debug.Log("Done Triangles!");

        // Create a new Mesh and populate with the data
        Mesh mesh = new Mesh();
        mesh.vertices = vertices;
        mesh.triangles = triangles;
        mesh.normals = normals;
        mesh.uv = uv;

        // Assign our mesh to our filter/renderer/collider
        MeshFilter mesh_filter = GetComponent<MeshFilter>();
        MeshRenderer mesh_renderer = GetComponent<MeshRenderer>();
        MeshCollider mesh_collider = GetComponent<MeshCollider>();

        mesh_filter.mesh = mesh;
        mesh_collider.sharedMesh = mesh;
        Debug.Log("Done Mesh!");
        UpdateGraphics();
    }
Exemple #15
0
 void Initialize()
 {
     //gridMap = new Vector3[size_x, size_y];
     mapData = new TDMap(size_x, size_y, MapType.Forest);
 }
Exemple #16
0
    void BuildTexture()
    {
        TDMap map = new TDMap (sizeX, sizeZ);

        int textWidth = sizeX * tileResolution;
        int textHeight = sizeZ * tileResolution;

        // Create a new texture 10 x 10 px
        Texture2D texture = new Texture2D (textWidth, textHeight);

        Color[][] tiles = ChopUpTiles ();

        for (int y = 0; y < sizeZ; y++) {
            for (int x = 0; x < sizeX; x++) {
                Color[] p = tiles[map.GetTileAt(x, y)];
                texture.SetPixels(x*tileResolution, y*tileResolution, tileResolution, tileResolution, p);
            }
        }

        // For sharp edges
        texture.filterMode = FilterMode.Point;
        texture.wrapMode = TextureWrapMode.Clamp;

        // Apply the textures
        texture.Apply ();

        MeshRenderer mr = GetComponent<MeshRenderer> ();
        mr.sharedMaterials [0].mainTexture = texture;
    }
Exemple #17
0
 /** Creates tile collision data from the tilemap. */
 public TilePathDataNode(TDMap p_map, Coord p_tileLoc)
 {
     TDTile tile = p_map.GetTile(p_tileLoc.X, p_tileLoc.Y);
 }
Exemple #18
0
 public TDTile(int x, int y, TDMap map)
 {
     this.x   = x;
     this.y   = y;
     this.map = map;
 }
    public TDPath checkPath(TDMap map, TDTile start, int maxStamina)
    {
        TDTile selected = new TDTile();
        TDTile finalSelected = new TDTile();
        TDTile pathRun = new TDTile();
        ArrayList finalPath = new ArrayList();
        ArrayList unvisited = new ArrayList();
        for (int i = start.position - maxStamina - maxStamina * map.getWidth(); i < start.position + maxStamina + maxStamina * map.getWidth(); i++)
        {
            if (i > 0 && i < map.getWidth() * map.getHeight())
            {
                map.getTile(i).distance = 20000;
                map.getTile(i).previousTile = null;
                unvisited.Add(map.getTile(i));
            }
            Debug.Log("On position " + i);
            if (i % map.getWidth() == start.x + maxStamina)
            {

                i += map.getWidth() - maxStamina * 2 - 1;
                Debug.Log("Switched Rows " + i);

            }
        }
        map.getTile(start.position).distance = 0;
        int looped = 0;
        int finalDistance = -1;
        while (unvisited.Count > 0 && !selected.equals(map.getTile((int)currentTileCoord.x, (int)currentTileCoord.z)) && selected.distance < maxStamina)
        {
            looped++;
            selected.distance = 200000;
            for (int i = 0; i < unvisited.Count; i++)
            {
                TDTile comparing = (TDTile)unvisited[i];
                if (comparing.distance < selected.distance)
                {

                    selected = comparing;
                    if (selected.equals(map.getTile((int)currentTileCoord.x, (int)currentTileCoord.z)))
                    {
                        if (selected.distance > maxStamina)
                        {
                            return null;
                        }
                        finalDistance = selected.distance;
                        finalSelected = selected;
                        pathRun = finalSelected;
                        while (pathRun.previousTile != null)
                        {
                            finalPath.Add(pathRun);
                            pathRun = pathRun.previousTile;
                        }

                        return new TDPath(finalPath, finalDistance);
                    }
                    Debug.Log(" Selected: " + selected + " " + selected.distance + "looped: " + looped);
                }
                unvisited.Remove(selected);
                for (int j = 0; j < selected.findNeighbors().Length; j++)
                {
                    TDTile neighbor = map.getTile(selected.findNeighbors()[j]);
                    if (neighbor != null)
                    {
                        if (unvisited.Contains(neighbor))
                        {
                            int alternate = selected.distance + 1;
                            if (alternate < neighbor.distance)
                            {
                                neighbor.distance = alternate;
                                neighbor.previousTile = selected;
                            }

                        }
                    }
                }
            }
        }
        return null;
    }
Exemple #20
0
    public void BuildMesh()
    {
        map   = new TDMap(sizeX, sizeZ);
        sizeX = map.GetSizeX();
        sizeZ = map.GetSizeY();

        int numTiles     = sizeX * sizeZ;
        int numTriangles = numTiles * 2;

        int vSizeX   = sizeX + 1;
        int vSizeZ   = sizeZ + 1;
        int numVerts = vSizeX * vSizeZ;

        Vector3[] vertices = new Vector3[numVerts];
        Vector3[] normals  = new Vector3[numVerts];
        Vector2[] uv       = new Vector2[numVerts];

        int[] triangles = new int[numTriangles * 3];

        int x, z;

        for (z = 0; z < vSizeZ; z++)
        {
            for (x = 0; x < vSizeX; x++)
            {
                vertices[z * vSizeX + x] = new Vector3(x * tileSize, 0, z * tileSize);
                normals[z * vSizeX + x]  = Vector3.up;
                uv[z * vSizeX + x]       = new Vector2((float)x / sizeX, (float)z / sizeZ);
            }
        }

        for (z = 0; z < sizeZ; z++)
        {
            for (x = 0; x < sizeX; x++)
            {
                int squareIndex    = z * sizeX + x;
                int triangleOffset = squareIndex * 6;

                triangles[triangleOffset + 0] = z * vSizeX + x + 0;
                triangles[triangleOffset + 1] = z * vSizeX + x + vSizeX + 0;
                triangles[triangleOffset + 2] = z * vSizeX + x + vSizeX + 1;

                triangles[triangleOffset + 3] = z * vSizeX + x + 0;
                triangles[triangleOffset + 4] = z * vSizeX + x + vSizeX + 1;
                triangles[triangleOffset + 5] = z * vSizeX + x + 1;
            }
        }

        Mesh mesh = new Mesh();

        mesh.vertices  = vertices;
        mesh.triangles = triangles;
        mesh.normals   = normals;
        mesh.uv        = uv;

        MeshFilter   filter   = GetComponent <MeshFilter>();
        MeshCollider collider = GetComponent <MeshCollider>();

        filter.mesh         = mesh;
        collider.sharedMesh = mesh;

        BuildTexture();
    }
Exemple #21
0
    // Update is called once per frame
    public void BuildMesh()
    {
        instance     = this;
        MapCreated   = false;
        MapWorldSize = new Vector2(size_x * tileSize, size_y * tileSize);
        if (grid != null)
        {
            grid.node_radius   = tileSize / 2;
            grid.GridWorldSize = MapWorldSize;
        }

        CalcTex();

        Global_TDMap = new TDMap(size_x, size_y, MapTerrainType, TileChance, MaxHeightForPlants, MaxHeightLeap);

        int numTiles = size_x * size_y;
        int numTris  = numTiles * 2;
        int vsize_x  = size_x * 2;
        int vsize_y  = size_y * 2;
        int numVerts = vsize_x * vsize_y;

        if (vsize_x * vsize_y > 65000)
        {
            size_x = 125;
            size_y = 125;
            return;
        }

        Vector3[] vertices = new Vector3[numVerts];
        Vector3[] normals  = new Vector3[numVerts];
        Vector2[] uv       = new Vector2[numVerts];

        int[] triangles = new int[numTris * 3];

        int x, y;

        Vector3 sp = Vector3.zero;

        sp.x -= tileSize * size_x / 2;
        sp.y -= tileSize * size_x / 2;
        float r = Random.Range(-2f, 2f);

        for (y = 0; y < vsize_y; y++)
        {
            for (x = 0; x < vsize_x; x++)
            {
                vertices[y * vsize_x + x] = new Vector3((x + 1) / 2 * tileSize, (y + 1) / 2 * tileSize, 0) + sp;
                normals[y * vsize_x + x]  = new Vector3(0, 0, -1);
                uv[y * vsize_x + x]       = GetTexture(Global_TDMap.GetTile(x / 2, y / 2).type, x, y);
            }
        }


        if (Heights)
        {
            for (y = 1; y < vsize_y - 1; y += 2)
            {
                for (x = 1; x < vsize_x - 1; x += 2)
                {
                    r = Random.Range(0, 0);

                    if (Global_TDMap.GetIfWater(x / 2, y / 2))
                    {
                        r = -Random.Range(-8f, -10f);
                    }
                    else
                    {
                        r = Global_TDMap.GetIfMountine((x + 0) / 2, (y + 0) / 2);
                    }
                    vertices[y * vsize_x + x].z           = r;
                    vertices[y * vsize_x + x + 1].z       = r;
                    vertices[(y + 1) * vsize_x + x].z     = r;
                    vertices[(y + 1) * vsize_x + x + 1].z = r;
                }
            }

            for (y = 0; y < vsize_y; y++)
            {
                vertices[y * vsize_x].z = vertices[y * vsize_x + 1].z;
                vertices[y * vsize_x + vsize_x - 1].z = vertices[y * vsize_x + vsize_x - 2].z;
            }

            for (x = 0; x < vsize_x; x++)
            {
                vertices[x].z = vertices[vsize_x + x].z;
                vertices[(vsize_y - 1) * vsize_x + x].z = vertices[(vsize_y - 2) * vsize_x + x].z;
            }

            print("End OF Heights!");
        }
        for (y = 0; y < size_y; y++)
        {
            for (x = 0; x < size_x; x++)
            {
                //x = 1
                int squareIndex = y * size_x + x;
                int triOffset   = squareIndex * 6;
                triangles[triOffset + 0] = (y * 2) * vsize_x + (x * 2) + 0;
                triangles[triOffset + 1] = (y * 2) * vsize_x + (x * 2) + vsize_x + 0;
                triangles[triOffset + 2] = (y * 2) * vsize_x + (x * 2) + vsize_x + 1;

                triangles[triOffset + 3] = (y * 2) * vsize_x + (x * 2) + 0;
                triangles[triOffset + 4] = (y * 2) * vsize_x + (x * 2) + vsize_x + 1;
                triangles[triOffset + 5] = (y * 2) * vsize_x + (x * 2) + 1;
            }
        }

        Mesh mesh = new Mesh();

        mesh.vertices  = vertices;
        mesh.normals   = normals;
        mesh.uv        = uv;
        mesh.triangles = triangles;

        MeshFilter   mesh_filter   = GetComponent <MeshFilter>();
        MeshRenderer mesh_renderer = GetComponent <MeshRenderer>();
        MeshCollider mesh_collider = GetComponent <MeshCollider>();

        mesh_filter.mesh         = mesh;
        mesh_collider.sharedMesh = mesh;
        Debug.Log("Done Mesh!");
        //BuildTexture();

        OnMapGenerator GenerateTrees = new OnMapGenerator(Global_TDMap, size_x, size_y, tileSize, MapHolder);

        StartCoroutine(GenerateTreesEI(GenerateTrees));
        //MapCreated = true;
    }
Exemple #22
0
 void Initialize()
 {
     //gridMap = new Vector3[size_x, size_y];
     mapData = new TDMap (size_x, size_y, MapType.Forest);
 }
Exemple #23
0
    public TDMap(int size_x, int size_y, MapType type, TCSV[] TileChanceC, int MaxHeightForPlants, int MaxWalkableHeight)
    {
        CreateTileTypes(TileChanceC);
        this.size_x = size_x;
        this.size_y = size_y;
        MHP         = MaxHeightForPlants;
        MWH         = MaxWalkableHeight;
        tiles       = new TDTile[size_x, size_y];

        float chance = 0;
        TCSV  tile_t = TileChanceC[0];

        for (int x = 0; x < size_x; x++)
        {
            for (int y = 0; y < size_y; y++)
            {
                chance = 0;
                foreach (TCSV t in TileChanceC)
                {
                    float temp = Random.Range(0, (int)TileChance[t.tile_name]);
                    if (temp > chance)
                    {
                        chance = temp;
                        tile_t = t;
                    }
                }
                tiles[x, y] = new TDTile(x, y, this, tile_t.tile_name);
            }
        }

        for (int x = 0; x < size_x; x++)
        {
            for (int y = 0; y < size_y; y++)
            {
                int a = Mathf.Clamp((int)type, 0, 1);
                GetMoreRealisticTile(x, y, 2 + a);
            }
        }
        for (int x = 0; x < size_x; x++)
        {
            for (int y = 0; y < size_y; y++)
            {
                int a = Mathf.Clamp(-(int)type, 0, 1);
                GetMoreRealisticTile(x, y, 2 - a);
            }
        }
        for (int x = 0; x < size_x; x++)
        {
            for (int y = 0; y < size_y; y++)
            {
                GetMoreRealisticTile(x, y, 1);
            }
        }
        for (int x = 0; x < size_x; x++)
        {
            for (int y = 0; y < size_y; y++)
            {
                GetMoreRealisticTile(x, y, 2);
            }
        }
        GlobalMap = this;
    }
Exemple #24
0
 void buildTDMap()
 {
     map = new TDMap(meshSize * (mapSize), meshSize * (mapSize), numRivers, numLakes, dirtPatches, numDeserts, desertSize, desertDensity, numStone, stoneSize, stoneDensity, forestDensity, forestThickness);
 }