import { CircleSprite , ImageSprite } from './sprite' ; export default class Collide { canvas : HTMLCanvasElement ; constructor ( canvas ) { this . canvas = canvas ; } public isCandidateForCollide ( ball ) { return ball . isVisible && ! this . isBallOutCanvas ( ball ) ; } public isBallOutCanvas ( ball ) { let { width , height } = this . canvas ; let { x , y , radius } = ball ; return x + radius < 0 || x - radius > width || y - radius > height ; } public didCollide ( ball , bucket ) { let k1 = ball . verticalVelocity / ball . horizontalVelocity ; let b1 = ball . y - k1 * ball . x ; let inertSectionY = bucket . mockTop ; let insertSectionX = ( inertSectionY - b1 ) / k1 ; return ( insertSectionX > bucket . mockLeft && insertSectionX < bucket . mockLeft + bucket . mockWidth && ball . x > bucket . mockLeft && ball . x < bucket . mockLeft + bucket . mockWidth && ball . y > bucket . mockTop && ball . y < bucket . mockTop + bucket . mockHeight ) ; } }