예제 #1
0
    public void LoadLevel()
    {
        TextAsset m_textAsset = Resources.Load("level_1") as TextAsset;

        if (m_textAsset == null)
        {
            Debug.Log("File not found\n");
            return;
        }
        ParseTMX  tmx   = new ParseTMX();
        Transform brick = (Transform)AssetDatabase.LoadAssetAtPath("Assets/Prefab/brick.prefab", typeof(Transform));

        if (brick == null)
        {
            Debug.LogError("Asset brick not found");
            return;
        }
        tmx.ParseFile(m_textAsset.text);
        for (int j = 0; j < tmx.m_height; j++)
        {
            for (int i = 0; i < tmx.m_width; i++)
            {
                int brick_id = tmx.m_brickData[j * tmx.m_width + i];
                if (brick_id != 0)
                {
                    float x = 1.0f - i * 0.2f;
                    float y = 1.0f - j * 0.1f;
                    Instantiate(brick, new Vector3(x, y, -0.168f), Quaternion.identity);
                }
            }
        }
    }
예제 #2
0
    public void LoadLevel(string level)
    {
        TextAsset m_textAsset = Resources.Load("Levels/" + level) as TextAsset;

        if (m_textAsset == null)
        {
            Debug.LogErrorFormat("File not found {0}", level);
            return;
        }
        else
        {
            Debug.Log("Loading level " + level);
        }
        ParseTMX tmx = new ParseTMX();

        tmx.ParseFile(m_textAsset.text);

        for (int j = 0; j < tmx.m_height; j++)
        {
            for (int i = 0; i < tmx.m_width; i++)
            {
                int brick_id   = tmx.m_brickData [j * tmx.m_width + i];
                int powerup_id = tmx.m_powerupData [j * tmx.m_width + i];
                if (brick_id != 0)
                {
                    AddBrick(i, j, brick_id, powerup_id);
                }
            }
        }
    }