Exemplo n.º 1
0
//	void OnEnable()
//	{
//		Recreate();
//	}
//
//	void OnDisable()
//	{
//		Clear();
//	}

    public void DestroyBlock(BlockTurbo block)
    {
        if (block == null)
        {
            return;
        }

        int y = block.y;

        blockTypes[y][block.x] = BlockType.Empty;
        DestroyBlockRow(y);
        CreateBlockRow(y, blockTypes[y]);
    }
Exemplo n.º 2
0
    void CreateBlockRow(int y, List <BlockType> blockTypes)
    {
        List <BlockTurbo> row = rowBlocks[y];

        row.Clear();

        BoxCollider2D collider = null;
        int           w        = 0;

        for (int x = 0; x < config.mapWidth; ++x)
        {
            BlockType  bt    = blockTypes[x];
            BlockTurbo block = CreateBlock(bt, x, y);

            if (!collider)
            {
                w = 0;
                if (block)
                {
                    collider        = block.gameObject.AddComponent <BoxCollider2D>();
                    collider.offset = new Vector2(0.0f, 0.25f);
                    collider.size   = new Vector2(1.0f, 0.5f);
                }
            }
            else
            {
                if (bt == BlockType.Empty)
                {
                    collider = null;
                    w        = 0;
                }
                else
                {
                    ++w;

                    collider.offset = new Vector2(((float)w) * 0.5f, 0.25f);
                    collider.size   = new Vector2((float)(w + 1), 0.5f);
                }
            }

            if (block)
            {
                row.Add(block);
            }
        }
    }
Exemplo n.º 3
0
    BlockTurbo CreateBlock(BlockType blockType, int x, int y)
    {
        BlockTurbo turb = null;

        if (blockType == BlockType.Filled)
        {
            var go = Instantiate(GreenBlock) as GameObject;
            go.transform.position = new Vector2((float)x - 1.0f, (float)y);
            var blo = go.GetComponent <BlockTurbo>();
            blo.x = x;
            blo.y = y;
            turb  = blo;

            turb.DestroyMe += (BlockTurbo turbBlock) => {
                DestroyBlock(turbBlock);
            };
        }

        return(turb);
    }