import { Coin } from '../objects/coin' ; import { Player } from '../objects/player' ; export class GameScene extends Phaser . Scene { private background : Phaser . GameObjects . Image ; private coin : Coin ; private coinsCollectedText : Phaser . GameObjects . Text ; private collectedCoins : number ; private player : Player ; constructor ( ) { super ( { key : 'GameScene' } ) ; } preload ( ) { this . load . image ( 'background' , './assets/images/background.png' ) ; this . load . image ( 'player' , './assets/images/player.png' ) ; this . load . image ( 'coin' , './assets/images/coin.png' ) ; } init ( ) { this . collectedCoins = 0 ; } create ( ) { this . background = this . add . image ( 0 , 0 , 'background' ) ; this . background . setOrigin ( 0 , 0 ) ; this . coin = new Coin ( { scene : this , x : Phaser . Math . RND . integerInRange ( 100 , 700 ) , y : Phaser . Math . RND . integerInRange ( 100 , 500 ) , texture : 'coin' } ) ; this . player = new Player ( { scene : this , x : this . sys . canvas . width / 2 , y : this . sys . canvas . height / 2 , texture : 'player' } ) ; this . coinsCollectedText = this . add . text ( this . sys . canvas . width / 2 , this . sys . canvas . height - 50 , this . collectedCoins + '' , { fontFamily : 'Arial' , fontSize : 38 + 'px' , stroke : '#fff' , strokeThickness : 6 , color : '#000000' } ) ; } update ( ) { this . player . update ( ) ; this . coin . update ( ) ; if ( Phaser . Geom . Intersects . RectangleToRectangle ( this . player . getBounds ( ) , this . coin . getBounds ( ) ) ) { this . updateCoinStatus ( ) ; } } private updateCoinStatus ( ) { this . collectedCoins ++ ; this . coinsCollectedText . setText ( this . collectedCoins + '' ) ; this . coin . changePosition ( ) ; } }