import { Shape } from "../shape" ; import { Util } from "../util" ; import { TimeState } from "../level" ; import { AudioManager } from "../audio" ; import { Collision } from "../physics/collision" ; /** A bumper is a shape which knocks the marble away on contact. */ export abstract class AbstractBumper extends Shape { wiggleAnimationStart = - Infinity ; shareNodeTransforms = false ; get animationDuration ( ) { return this . dts . sequences [ 0 ] . duration * 1000 ; } onMarbleContact ( collision ) { let time = this . level . timeState ; this . wiggleAnimationStart = time . timeSinceLoad ; AudioManager . play ( this . sounds [ 0 ] ) ; if ( ! collision ) return ; let marble = this . level . marble ; marble . setLinearVelocityInDirection ( collision . normal , 15 , false ) ; marble . slidingTimeout = 2 ; this . level . replay . recordMarbleContact ( this ) ; } render ( time ) { let currentCompletion = Util . clamp ( ( time . timeSinceLoad - this . wiggleAnimationStart ) / this . animationDuration , 0 , 1 ) ; this . sequenceKeyframeOverride . set ( this . dts . sequences [ 0 ] , currentCompletion * ( this . dts . sequences [ 0 ] . numKeyframes - 1 ) ) ; super . render ( time ) ; } }