示例#1
0
文件: Render.cs 项目: peke2/tetris
    /**
     *	落下ブロックの描画
     */
    void drawTetrimino(Resource res)
    {
        Tetrimino tetrimino = res.tetris.getTetrimino();

        GameObject[] blocks = res.minoBlocks;

        Tetrimino.Pattern pat = tetrimino.getPattern();

        int num_blocks = 0;
        int index      = 0;

        Vector2 offset = res.offset;

        int base_x, base_y;

        base_x = tetrimino.getPosX();
        base_y = tetrimino.getPosY();

        for (int y = 0; y < pat.h; y++)
        {
            for (int x = 0; x < pat.w; x++)
            {
                char c = pat.pat[index];

                if (c == '1')
                {
                    float      posx  = x + base_x + offset.x;
                    float      posy  = y + base_y + offset.y;
                    GameObject block = blocks[num_blocks];
                    block.transform.position = new Vector3(posx, posy, 0);
                    //blk.GetComponent<Renderer>().material.color = m_colorList[tetrimino.getColorIndex()];

                    int      color_index = tetrimino.getColorIndex();
                    MeshQuad mesh        = block.GetComponent <MeshQuad>();
                    Color[]  colors      = new Color[]
                    {
                        m_colorList[color_index],
                        m_colorList[color_index],
                        m_colorList[color_index],
                        m_colorList[color_index],
                    };
                    mesh.updateUv(m_blockUvList);
                    mesh.updateColor(colors);

                    num_blocks++;
                }

                index++;
            }
        }
    }
示例#2
0
文件: Render.cs 项目: peke2/tetris
    /**
     *	盤面の描画
     */
    void drawBoard(Resource res)
    {
        Stage stage    = res.tetris.getStage();
        int   w        = stage.getBoardWidth();
        int   h        = stage.getBoardHeight();
        int   h_margin = stage.getBoardHeightMargin();

        GameObject[] blocks = res.blocks;
        Stage.BlockInfo[,]  board = stage.getBlockInfo();
        Vector2 offset = res.offset;

        for (int y = 0; y < h; y++)
        {
            for (int x = 0; x < w; x++)
            {
                int  index     = x + y * w;
                bool isVisible = false;

                /*
                 * if(null != blocks[index])
                 * {
                 *      GameObject.Destroy(blocks[index]);
                 *      blocks[index] = null;
                 * }*/

                GameObject block = blocks[index];
                if (Stage.BLOCK_STATE.EXISTS == board[x, y].state)
                {
                    //block = Instantiate(tetrisBlock);
                    //block.GetComponent<Renderer>().material.color = m_colorList[board[x,y].color_index];

                    MeshQuad mesh   = block.GetComponent <MeshQuad>();
                    Color[]  colors = new Color[]
                    {
                        m_colorList[board[x, y].color_index],
                        m_colorList[board[x, y].color_index],
                        m_colorList[board[x, y].color_index],
                        m_colorList[board[x, y].color_index],
                    };
                    mesh.updateUv(m_blockUvList);
                    mesh.updateColor(colors);

                    //blocks[index] = block;
                    isVisible = true;
                }
                else if (Stage.BLOCK_STATE.NONE == board[x, y].state)
                {
                    //	ブランクはマージン以外の領域に描画
                    if (y < h - h_margin)
                    {
                        //	block = Instantiate(boardBlank);
                        //	blocks[index] = block;
                        MeshQuad mesh   = block.GetComponent <MeshQuad>();
                        Color[]  colors = new Color[]
                        {
                            new Color(1, 1, 1, 1),
                            new Color(1, 1, 1, 1),
                            new Color(1, 1, 1, 1),
                            new Color(1, 1, 1, 1),
                        };
                        mesh.updateUv(m_blankUvList);
                        mesh.updateColor(colors);
                        isVisible = true;
                    }

                    //	マージンを超えたブランクは非表示
                }
                if (true == isVisible)
                {
                    block.transform.position = new Vector3(x + offset.x, y + offset.y, 0);
                    block.SetActive(true);
                }
            }
        }
    }