Example #1
0
    // -----------------------------------------------------------------------------------------------------------------
    private void BuildTiles()
    {
        Texture2D heightmap = m_config.heightmap;
        float     tile_gap  = m_config.tile_gap_size;
        float     tile_unit = m_config.tile_unit_size;
        float     tw        = m_config.tile_mesh.GetBounds().x;
        float     th        = m_config.tile_mesh.GetBounds().z;

        // Tile width
        m_tile_width    = tw + tile_gap;
        m_tile_width_50 = m_tile_width * 0.5f;

        // Tile height
        m_tile_height    = th + tile_gap;
        m_tile_height_75 = m_tile_height * 0.75f;
        m_tile_height_50 = m_tile_height * 0.5f;
        m_tile_height_25 = m_tile_height * 0.25f;

        // Level size
        m_width  = heightmap.width;
        m_height = heightmap.height;

        utils.Log("Tile :: width={0:F2} height={1:F2} gap={2:F2} unit={3:F2}", tw, th, tile_gap, tile_unit);
        utils.Log("Map :: width={0} height={1}", heightmap.width, heightmap.height);

        // Init tags
        m_tag_owner = new CTag.COwner((int)CTile.ETag.T_MAX);
        m_tag_owner.InitTag((int)CTile.ETag.T_CURRENT, "current", 1, CTag.ELimitPolicy.LP_QUEUE);
        m_tag_owner.InitTag((int)CTile.ETag.T_VISITED, "visited", 10, CTag.ELimitPolicy.LP_QUEUE);
        m_tag_owner.InitTag((int)CTile.ETag.T_DEST_PATH, "dest-path", 25, CTag.ELimitPolicy.LP_DENY);
        m_tag_owner.InitTag((int)CTile.ETag.T_DEFAULT, "default");
        m_tag_owner.InitTag((int)CTile.ETag.T_APPLE, "apple");
        m_tag_owner.InitTag((int)CTile.ETag.T_BORDER, "border");
        m_tag_owner.InitTag((int)CTile.ETag.T_TAIL, "tail");

        // Build tiles
        m_tiles = new CTile[m_width, m_height];
        for (int z = 0; z < m_height; z++)
        {
            for (int x = 0; x < m_width; x++)
            {
                CreateTile(x, z, heightmap);
            }
        }

        // Link together neightbor tiles
        for (int z = 0; z < m_height; z++)
        {
            for (int x = 0; x < m_width; x++)
            {
                CTile t = m_tiles[x, z];
                for (int idx = (int)CTile.EDirection.DIR_1; idx < (int)CTile.EDirection.DIR_MAX; idx++)
                {
                    CTile.EDirection dir = (CTile.EDirection)idx;
                    t.SetNeighbor(dir, GetTileByOffset(t, dir, 1));
                }
            }
        }

        // Create vertical border
        for (int z = 0; z < m_height; z++)
        {
            m_tag_owner.SetTag(m_tiles[0, z], (int)CTile.ETag.T_BORDER);
            m_tag_owner.SetTag(m_tiles[m_width - 1, z], (int)CTile.ETag.T_BORDER);
        }

        // Create horizontal border
        for (int x = 0; x < m_height; x++)
        {
            m_tag_owner.SetTag(m_tiles[x, 0], (int)CTile.ETag.T_BORDER);
            m_tag_owner.SetTag(m_tiles[x, m_height - 1], (int)CTile.ETag.T_BORDER);
        }
    }