import { Vector } from '../types' ; export class Paddle { private paddleImage : HTMLImageElement = new Image ( ) ; private moveLeft : boolean ; private moveRight : boolean ; constructor ( private speed , private paddleWidth , private paddleHeight , private position , image ) { this . speed = speed ; this . paddleWidth = paddleWidth ; this . paddleHeight = paddleHeight ; this . position = position ; this . moveLeft = false ; this . moveRight = false ; this . paddleImage . src = image ; document . addEventListener ( 'keydown' , this . handleKeyDown ) ; document . addEventListener ( 'keyup' , this . handleKeyUp ) ; } get width ( ) : number { return this . paddleWidth ; } get height ( ) : number { return this . paddleHeight ; } get pos ( ) : Vector { return this . position ; } get image ( ) : HTMLImageElement { return this . paddleImage ; } get isMovingLeft ( ) : boolean { return this . moveLeft ; } get isMovingRight ( ) : boolean { return this . moveRight ; } movePaddle ( ) { if ( this . moveLeft ) this . pos . x -= this . speed ; if ( this . moveRight ) this . pos . x += this . speed ; } handleKeyUp = ( e ) : void => { if ( e . code === 'ArrowLeft' || e . key === 'ArrowLeft' ) this . moveLeft = false ; if ( e . code === 'ArrowRight' || e . key === 'ArrowRight' ) this . moveRight = false ; } ; handleKeyDown = ( e ) : void => { if ( e . code === 'ArrowLeft' || e . key === 'ArrowLeft' ) this . moveLeft = true ; if ( e . code === 'ArrowRight' || e . key === 'ArrowRight' ) this . moveRight = true ; } ; }