我已经为此工作了几个星期,我可以让它像它一样工作。它几乎就在那里,我想我只是缺少一些东西。我基本上不能让块和球之间的碰撞检测像我想让它们工作一样工作。
球仍然有机会在几秒钟内犁出大量的块。我很想听听有类似问题的人的意见。
这是代码;
private function checkCollision():void
    {
        grdx = Math.floor((ball.x) / 28);
        grdy = Math.floor((ball.y) / 14);
        ngrdx = Math.floor((ball.x + dx) / 28);
        ngrdy = Math.floor((ball.y + dy) / 14);
        if (grdy <= level.length - 1 && ngrdy <= level.length - 1 && grdy >= 0 && ngrdy >= 0) 
        {   
            if(level[grdy][ngrdx] > 0) 
            {
                level[grdy][ngrdx] = 0;
                bnm = "Block_" + grdy + "_" + ngrdx;    
                if (this.getChildByName(bnm) != null)
                {
                    this.removeChild(this.getChildByName(bnm));
                    dx *= -1;   
                    totalBreaks++;
                    trace("Hit on X");
                    trace("Block: " + totalBreaks + " / " +  totalBlocks);
                }
            }
            else if(level[ngrdy][grdx] > 0) 
            {               
                bnm = "Block_" + ngrdy + "_" + grdx;
                level[ngrdy][grdx] = 0; 
                 if (this.getChildByName(bnm) != null)
                {
                    this.removeChild(this.getChildByName(bnm));
                    dy *= -1;
                    totalBreaks++;
                    trace("Hit on Y");
                    trace("Block: " + totalBreaks + " / " +  totalBlocks);
                }
            }
            if(level[ngrdy][ngrdx] > 0) 
            {               
                bnm = "Block_" + ngrdy + "_" + ngrdx;
                level[ngrdy][ngrdx] = 0;    
                if (this.getChildByName(bnm) != null)
                {
                    this.removeChild(this.getChildByName(bnm));
                    dy *= -1;
                    dx *= -1;
                    totalBreaks++;
                    trace("hit on X,Y");
                    trace("Block: " + totalBreaks + " / " +  totalBlocks);
                }
            }
        }
    }