private void handleBallCollision(BallCollisionEvent event) { CollisionUtils.bounceOff(event.getSourceBall(), event.getTargetBall()); event.getSourceBall().incrementCollisionCount(); event.getTargetBall().incrementCollisionCount(); predictCollisions(event.getSourceBall()); predictCollisions(event.getTargetBall()); }
private void predictCollisions(Ball sourceBall) { double dt = CollisionUtils.calcTimeToHitWall(sourceBall, WallType.HORIZONTAL); if (CollisionUtils.isCollisionConsistency(dt)) { queue.add(new WallCollisionEvent(timer.getTimestamp(dt), sourceBall, WallType.HORIZONTAL)); } dt = CollisionUtils.calcTimeToHitWall(sourceBall, WallType.VERTICAL); if (CollisionUtils.isCollisionConsistency(dt)) { queue.add(new WallCollisionEvent(timer.getTimestamp(dt), sourceBall, WallType.VERTICAL)); } for (Ball targetBall : objectContainer.getBalls()) { dt = CollisionUtils.calcTimeToHitBall(sourceBall, targetBall); if (CollisionUtils.isCollisionConsistency(dt)) { queue.add(new BallCollisionEvent(timer.getTimestamp(dt), sourceBall, targetBall)); } } }
private void handleWallCollision(WallCollisionEvent event) { CollisionUtils.bounceOffWall(event.getSourceBall(), event.getWallType()); event.getSourceBall().incrementCollisionCount(); predictCollisions(event.getSourceBall()); }