私はこれに数週間取り組んできましたが、それを機能させることができます。それはほとんどそこにあります。私が見逃しているものがあると思います。私は基本的に、ブロックとボールの間の衝突検出を、私が望むように機能させることができません。
ボールには、数秒以内に大量のブロックを耕すチャンスがまだあります。同じような悩みを抱えている方のお話をお聞きしたいです。
コードは次のとおりです。
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);
}
}
}
}