Beispiel #1
0
    // ロード開始
    public void Load(int stage)
    {
        TMXLoader tmx = new TMXLoader();

        // ファイルパスを作成
        string path = string.Format("Levels/{0:D3}", stage);

        tmx.Load(path);

        // 0番目のレイヤーに情報を取得する
        Layer2D layer = tmx.GetLayer(0);

        // タイルの配置
        for (int j = 0; j < layer.Height; j++)
        {
            for (int i = 0; i < layer.Width; i++)
            {
                // 座標を指定してレイヤーの値を取得
                int   v = layer.Get(i, j);
                float x = GetChipX(i);
                float y = GetChipY(j);

                switch (v)
                {
                case CHIP_PLAYER:
                {
                    // プレイヤを移動させる
                    GameObject obj    = GameObject.Find("Player") as GameObject;
                    Player     player = obj.GetComponent <Player>();
                    player.SetPosition(x, y);
                }
                break;

                case CHIP_WALL:
                    // 壁を作成
                    Wall.Add(x, y);
                    break;

                case CHIP_SPIKE:
                    // トゲを生成
                    Spike.Add(x, y);
                    break;

                case CHIP_FLOOR_MOVE:
                    // 移動床を作成
                    FloorMove.Add(x, y);
                    break;

                case CHIP_GOAL:
                {
                    // ゴールを移動させる
                    GameObject obj  = GameObject.Find("Goal") as GameObject;
                    Goal       goal = obj.GetComponent <Goal>();
                    goal.SetPosition(x, y);
                }
                break;
                }
            }
        }
    }
Beispiel #2
0
    public void Load(int stage)
    {
        TMXLoader tmx  = new TMXLoader();
        string    path = string.Format("Levels/{0:D3}", stage);

        tmx.Load(path);
        Layer2D layer = tmx.GetLayer(0);

        //Debug.Log ("幅:" + layer.Width);
        //Debug.Log ("高:" + layer.Height);
        for (int j = 0; j < layer.Height; j++)
        {
            for (int i = 0; i < layer.Width; i++)
            {
                int   v = layer.Get(i, j);
                float x = GetChipX(i);
                float y = GetChipY(j);
                switch (v)
                {
                case CHIP_PLAYER:
                {
                    GameObject obj    = GameObject.Find("Player") as GameObject;
                    Player     player = obj.GetComponent <Player> ();
                    player.SetPosition(x, y);
                }
                break;

                case CHIP_WALL:
                    Wall.Add(x, y);
                    break;

                case CHIP_SPIKE:
                    Spike.Add(x, y);
                    break;

                case CHIP_FLOOR_MOVE:
                    FloorMove.Add(x, y);
                    break;

                case CHIP_GOAL:
                {
                    GameObject obj  = GameObject.Find("Goal") as GameObject;
                    Goal       goal = obj.GetComponent <Goal>();
                    goal.SetPosition(x, y);
                }
                break;
                }
            }
        }
    }