import { IImageConstructor } from '../interfaces/image.interface' ; export class Player extends Phaser . GameObjects . Image { private cursors : Phaser . Types . Input . Keyboard . CursorKeys ; private walkingSpeed : number ; constructor ( aParams ) { super ( aParams . scene , aParams . x , aParams . y , aParams . texture ) ; this . initVariables ( ) ; this . initImage ( ) ; this . initInput ( ) ; this . scene . add . existing ( this ) ; } private initVariables ( ) { this . walkingSpeed = 5 ; } private initImage ( ) { this . setOrigin ( 0.5 , 0.5 ) ; } private initInput ( ) { this . cursors = this . scene . input . keyboard . createCursorKeys ( ) ; } update ( ) { this . handleInput ( ) ; } private handleInput ( ) { if ( this . cursors . right . isDown ) { this . x += this . walkingSpeed ; this . setFlipX ( false ) ; } else if ( this . cursors . left . isDown ) { this . x -= this . walkingSpeed ; this . setFlipX ( true ) ; } else if ( this . cursors . up . isDown ) { this . y -= this . walkingSpeed ; } else if ( this . cursors . down . isDown ) { this . y += this . walkingSpeed ; } } }