Optimize collision detection using algorithm such as Quaternary Spatial Partitioning.
|
// TODO reduce the computational cost |
|
let remainingContributions = 0 |
|
this.blocks |
|
.filter((b) => b.life > 0) |
|
.forEach((b) => { |
|
const d = intersectDirection(this.ball, b) |
|
// the ball hit the block |
|
if (d !== Direction.None) { |
|
this.ball.onCollide(d) |
|
b.onCollide() |
|
this.score += b.origianlLife |
|
} |
|
remainingContributions += b.life |
|
}) |
Optimize collision detection using algorithm such as Quaternary Spatial Partitioning.
github-breakout/src/game/breakout.ts
Lines 85 to 98 in 61b9678