Exemplo n.º 1
0
    void Start()
    {
        tileMap            = GetComponent <TileMap>();
        currentTileCoord.y = cube.transform.position.y;
        cubeParent         = cube.parent;
        cube.GetComponent <Renderer>().material = materials[0];

        if (!mouseOverIsActive)
        {
            dataTileMap = tileMap.getDTileMap();

            //Debug.Log(dataTileMap);

            int new_x;
            int new_z;

            for (int i = 0; i < tries; i++)
            {
                new_x = Random.Range(0, dataTileMap.getSize_x());
                new_z = Random.Range(0, dataTileMap.getSize_z());
                //Debug.Log( "Coord : " + new_x + " , " + new_z );

                if (dataTileMap.isWalkable(new_x, new_z))
                {
                    cube.transform.position = new Vector3(new_x + cube.localScale.x, currentTileCoord.y, new_z + cube.localScale.z);
                    break;
                }
            }
        }
    }
Exemplo n.º 2
0
    void BuildTexture()
    {
        map = new DTileMap(size_x, size_z);
        //Debug.Log(map);

        int textWidth  = size_x * tileResolution;
        int textHeight = size_z * tileResolution;

        Texture2D texture = new Texture2D(textWidth, textHeight);

        Color[][] tiles = ChopUpTiles();

        makeIslands(islandsNum, map);

        map.makeBridges();

        map.generatePathfindingGraph();

        for (int z = 0; z < size_z; z++)
        {
            for (int x = 0; x < size_x; x++)
            {
                Color[] color = tiles [map.GetTileGraphicIDAt(x, z)];
                texture.SetPixels(x * tileResolution, z * tileResolution, tileResolution, tileResolution, color);
            }
        }

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

        MeshRenderer mesh_renderer = GetComponent <MeshRenderer> ();

        mesh_renderer.sharedMaterials [0].mainTexture = texture;
    }
Exemplo n.º 3
0
    void BuildTexture()
    {
        DTileMap map = new DTileMap(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[ 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!");
    }
Exemplo n.º 4
0
    void BuildTexture()
    {
        DTileMap map = new DTileMap(size_x, size_z, this);

        tiles = map.GetMapData();
        GeneratePathfindingGraph();
    }    //BuildTexture
Exemplo n.º 5
0
    void BuildTexture()
    {
        DTileMap map = new DTileMap(sizeX, sizeZ);

        int texWidth  = sizeX * tileResolution;
        int texHeight = sizeZ * tileResolution;
        //Texture2D texture = new Texture2D(sizeX * tileResolution, sizeZ * tileResolution);
        Texture2D texture = new Texture2D(texWidth, texHeight);

        Color[][] tiles = ChopUpTiles();

        for (int y = 0; y < sizeZ; y++)
        {
            for (int x = 0; x < sizeX; x++)
            {
                //Color c = new Color(Random.Range(0f, 1f), Random.Range(0f, 1f), Random.Range(0f, 1f));
                //texture.SetPixel(x, y, c);

                //Color[] p = tiles[map.GetTileAt(x, y)];
                //texture.SetPixels(x * tileResolution, y * tileResolution, tileResolution, tileResolution, p);
                Build3DRoom(x, y, map.GetTileAt(x, y));
            }
        }

        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!");
    }
Exemplo n.º 6
0
    void BuildTexture()
    {
        DTileMap map = new DTileMap(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[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!");
    }
Exemplo n.º 7
0
    void BuildSquareTexture()
    {
        DTileMap map = new DTileMap(distance, distance);

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

        Color[][] tiles = ChopUpTiles();

        for (int z = 0; z < distance; z++)
        {
            for (int x = 0; x < distance; x++)
            {
                Color[] p = tiles [map.GetTileAt(x, z)];
                texture.SetPixels(
                    x * tileResolution,
                    z * 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;
    }
Exemplo n.º 8
0
 public void makeIslands(int size, DTileMap map)
 {
     for (int i = 0; i < islandsNum; i++)
     {
         int width  = Random.Range(minIsland_x, maxIsland_x + 1);
         int height = Random.Range(minIsland_z, maxIsland_z + 1);
         map.makeIsland(Random.Range(0, size_x - width), Random.Range(0, size_z - height), width, height);
     }
 }
Exemplo n.º 9
0
    public void BuildMap()
    {
        if (transform.childCount > 0) DestroyMap();
        map_is_built = true;
        DTileMap map = new DTileMap(size_x, size_z, numrooms, room_size_x , room_size_y, room_x_variance, room_y_variance );
        tiles = new int[size_x, size_z];

        //Initialize the Tiles
        for (int x = 0; x < size_x; x++)
        {
            for (int z = 0; z < size_z; z++)
            {
                tiles[x, z] = map.map_data[x, z];
                //Debug.Log(tiles[x, z]);
            }
        }
        GenerateMapVisuals();
    }
Exemplo n.º 10
0
    void BuildTexture(int level)
    {
        size_x         = 24;
        size_z         = 18;
        tileSize       = 1;
        tileResolution = 100;

        DTileMap map = new DTileMap(size_z, size_x, level);

        Debug.Log("Build texture level: " + level);
        int tWidth  = size_x * 100;
        int tHeight = size_z * 100;

        Debug.Log("Mesh building successful.");
        Texture2D texture = new Texture2D(tWidth, tHeight);


        Color[][] tiles = TileSlicing();


        for (int x = 0; x < size_x; x++)
        {
            for (int y = 0; y < size_z; y++)
            {
                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("Texture applied successfully.");
    }
Exemplo n.º 11
0
 // Use this for initialization
 void Start()
 {
     MapInfo = new DTileMap(size_x, size_z);
     BuildMesh();
 }
Exemplo n.º 12
0
    //    Color[][] ChopUpTiles() {
    //        int numTilesPerRow = 4;
    //        int numRows = 1;
    //        
    //        Color[][] tiles = new Color[numTilesPerRow*numRows][];
    //        
    //        for(int y=0; y<numRows; y++) {
    //            for(int x=0; x<numTilesPerRow; x++) {
    //                tiles[y*numTilesPerRow + x] = terrainTiles.GetPixels( x*tileWidth , y*tileHeight, tileWidth, tileHeight );
    //            }
    //        }
    //
    //        return tiles;
    //    }
    //    
    //    void BuildTexture() {
    //
    //        DTileMap map = new DTileMap(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[ 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!");
    //    }
    public void BuildMesh()
    {
        DTileMap map = new DTileMap (size_x, size_y);

        int numTiles = size_x * size_y;
        int numVerts = numTiles * 3;

        // Generate the mesh data
        Vector3[] vertices = new Vector3[ numVerts ];
        Vector3[] normals = new Vector3[numVerts];
        Vector2[] uv = new Vector2[numVerts];

        int[] triangles = new int[ numVerts ];

        int x, z;
        for (z=0; z < size_y; z++) {
            for (x=0; x < size_x; x++) {
                int tileIndex = (z * size_x + x)*3;
                bool isUp = (x + z) % 2 == 0;

                if (isUp) {
                    vertices [tileIndex] = new Vector3 ((x + 1) * tileWidth , z * tileHeight , -1 );
                    vertices [tileIndex + 1] = new Vector3 ((x) * tileWidth, (z + 1) * tileHeight , -1 );
                    vertices [tileIndex + 2] = new Vector3 ((x + 2) * tileWidth, (z + 1) * tileHeight , -1 );

                    uv [tileIndex] = new Vector2 ((0.5f + map.GetTileAt (x, z)) / texNum, 0);
                    uv [tileIndex + 1] = new Vector2 ((0f + map.GetTileAt (x, z)) / texNum, 1);
                    uv [tileIndex + 2] = new Vector2 ((1f + map.GetTileAt (x, z)) / texNum, 1);

                } else {
                    vertices [tileIndex] = new Vector3 (x * tileWidth, z * tileHeight , -1 );
                    vertices [tileIndex + 1] = new Vector3 ((x + 1) * tileWidth, (z + 1) * tileHeight , -1 );
                    vertices [tileIndex + 2] = new Vector3 ((x + 2) * tileWidth, (z) * tileHeight , -1 );

                    uv [tileIndex + 0] = new Vector2 ((1f + map.GetTileAt (x, z)) / texNum, 0);
                    uv [tileIndex + 1] = new Vector2 ((0.5f + map.GetTileAt (x, z)) / texNum, 1);
                    uv [tileIndex + 2] = new Vector2 ((0f + map.GetTileAt (x, z)) / texNum, 0);
                }

                triangles [tileIndex] = tileIndex;
                triangles [tileIndex + 1] = tileIndex + 1;
                triangles [tileIndex + 2] = tileIndex + 2;

                normals [tileIndex] = Vector3.forward;
                normals [tileIndex + 1] = Vector3.forward;
                normals [tileIndex + 2] = Vector3.forward;

        //				Debug.Log( "vert1: (" + vertices[tileIndex].x + " , " + vertices[tileIndex].z );
        //				Debug.Log( "vert2: (" + vertices[tileIndex+1].x + " , " + vertices[tileIndex+1].z );
        //				Debug.Log( "vert3: (" + vertices[tileIndex+2].x + " , " + vertices[tileIndex+2].z );
        //
        //				Debug.Log( "uv1: (" + uv[tileIndex].x + " , " + uv[tileIndex].y );
        //				Debug.Log( "uv2: (" + uv[tileIndex+1].x + " , " + uv[tileIndex+1].y );
        //				Debug.Log( "uv3: (" + uv[tileIndex+2].x + " , " + uv[tileIndex+2].y );

            }
        }
        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;
        //
        //				if( z % 2 == 0 )
        //				{
        //
        //					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 + 1;
        //
        //					triangles[triOffset + 3] = z * vsize_x + x + 		   1;
        //					triangles[triOffset + 4] = z * vsize_x + x + vsize_x + 0;
        //					triangles[triOffset + 5] = z * vsize_x + x + vsize_x + 1;
        //				}
        //				else
        //				{
        //					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> ();

        mesh_filter.mesh = mesh;
        Debug.Log ("Done Mesh!");

        //BuildTexture();
    }
Exemplo n.º 13
0
    public void BuildMesh()
    {
        DTileMap map = new DTileMap(size_x, size_z);


        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;

        Vector3[] vertices  = new Vector3[numVerts];
        Vector3[] normals   = new Vector3[numVerts];
        Vector2[] uv        = new Vector2[numVerts];
        int[]     triangles = new int[numTris * 3];

        int x, z;

        for (z = 0; z < vsize_z; z++)
        {
            for (x = 0; x < vsize_x; x++)
            {
                vertices[z * vsize_x + x] = new Vector3(x * tileSize, 0, z * tileSize);
                normals[z * vsize_x + x]  = Vector3.up;
                uv[z * vsize_x + x]       = new Vector2((float)x / size_x, (float)z / size_z);
            }
        }
        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;
            }
        }



        ///
        Mesh mesh = new Mesh();

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



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

        mesh_filter.mesh         = mesh;
        mesh_collider.sharedMesh = mesh;


        BuildTexture();
    }