/// <summary> /// Removes disabled blocks from list /// </summary> private void CheckBlocksForCollision(GameTime gameTime) { for (int i = Blocks.Count() - 1; i >= 0; i--) { Block block = Blocks[i]; for (int j = ballManager.Balls.Count() - 1; j >= 0; j--) { Ball ball = ballManager.Balls[j]; if (block.Intersects(ball)) //chek rectagle collision between ball and current block { //checks hit block.HitByBall(ball); if (!ball.Reflected) //only reflect once { ball.ReflectFromBlock(block); } } if (block.State == BlockState.Broken) { RemoveDisabledBlocks(block); break; } } block.Update(gameTime); } }
private void ReflectFromBlocks() { //ブロックテーブルの最下層に到達していなければ以降の判定をスキップ float baseLine = table.RowCount * 64; if (Position.Y > baseLine) { return; } //全てのブロックとのあたり判定を検証 for (int i = 0; i < table.RowCount; i++) { //この行に敷き詰められるブロック矩形 //Rectangle lineRect = new Rectangle(0, (i * 64), 64, 64); ////それと衝突しなければ以降の判定をスキップ //if(!lineRect.Intersects(CollisionSystem.ToRectangle(this))) //{ // continue; //} for (int j = 0; j < table.ColumnCount; j++) { Block block = table[i, j]; if (block.IsDestroy || !block.Intersects(this)) { //衝突していない continue; } ReflectFromBlock(i, j, table[i, j]); goto END; } } END :; }