public Resource(Tetris tetris, GameObject tetrisBlock, GameObject gameoverMark, Vector2[] blockUvList, Vector2[] blankUvList) { Stage stage = tetris.getStage(); m_tetris = tetris; int w = stage.getBoardWidth(); int h = stage.getBoardHeight(); m_blocks = new GameObject[w * h]; // 現状では落下ドロップは4個固定なので直値 m_minoBlocks = new GameObject[4]; for (int i = 0; i < 4; i++) { m_minoBlocks[i] = Instantiate(tetrisBlock); //m_minoBlocks[i].GetComponent<SpriteRenderer>().sortingOrder = LAYER_DROP; MeshQuad mesh = m_minoBlocks[i].GetComponent <MeshQuad>(); mesh.updateUv(blockUvList); } // 盤面の描画オブジェクトをあらかじめ用意 for (int i = 0; i < w * h; i++) { m_blocks[i] = Instantiate(tetrisBlock); //m_minoBlocks[i].GetComponent<SpriteRenderer>().sortingOrder = LAYER_DROP; MeshQuad mesh = m_blocks[i].GetComponent <MeshQuad>(); mesh.updateUv(blankUvList); } // ゲームオーバー表示 m_gameoverMark = Instantiate(gameoverMark); m_gameoverMark.GetComponent <SpriteRenderer>().sortingOrder = LAYER_GAMEOVER; }
/** * 落下ブロックの描画 */ 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++; } } }
/** * 盤面の描画 */ 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); } } } }