@ -10,15 +10,10 @@ class Game extends Phaser.Scene {
}
}
create ( ) {
create ( ) {
//this.add.image(0,0,'background').alpha = 0.1;
this . selected = null ;
this . createButton ( ) ;
let btn = this . add . sprite ( WIDTH _MAP + WIDTH _WINDOW / 10 , WIDTH _MAP + HEIGHT _WINDOW / 10 + 5 , 'play' ) . setOrigin ( 1 , 0 ) . setInteractive ( ) ;
this . line = 0 ;
btn . displayHeight = HEIGHT _WINDOW / 15 ;
btn . scaleX = btn . scaleY ;
btn . on ( 'pointerout' , ( ) => this . changeFrame ( btn , 0 ) ) ;
btn . on ( 'pointerover' , ( ) => this . changeFrame ( btn , 1 ) ) ;
btn . on ( 'pointerdown' , ( ) => this . clickPlay ( btn ) ) ;
this . scene . launch ( 'GamingBoard' ) ;
this . scene . launch ( 'GamingBoard' ) ;
this . scene . pause ( 'GamingBoard' ) ;
this . scene . pause ( 'GamingBoard' ) ;
@ -37,9 +32,6 @@ class Game extends Phaser.Scene {
this . gm . addRobot ( robot ) ;
this . gm . addRobot ( robot ) ;
this . gm . addRobot ( new Robot ( WIDTH _MAP * 0.1 , WIDTH _MAP * 0.1 , WIDTH _MAP * 0.2 , WIDTH _MAP * 0.1 , 0xff0000 , this . gm ) ) ;
this . gm . addRobot ( new Robot ( WIDTH _MAP * 0.1 , WIDTH _MAP * 0.1 , WIDTH _MAP * 0.2 , WIDTH _MAP * 0.1 , 0xff0000 , this . gm ) ) ;
this . gm . addRobot ( new Robot ( WIDTH _MAP * 0.1 , WIDTH _MAP * 0.1 , WIDTH _MAP * 0.1 , WIDTH _MAP * 0.9 , 0xff0000 , this . gm ) ) ;
this . gm . addRobot ( new Robot ( WIDTH _MAP * 0.1 , WIDTH _MAP * 0.1 , WIDTH _MAP * 0.1 , WIDTH _MAP * 0.9 , 0xff0000 , this . gm ) ) ;
this . input . on ( 'drag' , this . doDrag ) ;
this . input . on ( 'dragstart' , ( ) => this . pauseScene ( btn ) ) ;
}
}
update ( time , delta ) {
update ( time , delta ) {
@ -47,6 +39,28 @@ class Game extends Phaser.Scene {
this . tree . updateLine ( ) ;
this . tree . updateLine ( ) ;
}
}
OK ( ) {
this . pencil . setVisible ( false ) ;
this . bin . setVisible ( false ) ;
this . plus . setVisible ( false ) ;
if ( this . selected != null ) {
this . selected . deselect ( ) ;
}
this . selected = this . tree . getSelected ( ) ;
if ( this . selected == null )
return ;
if ( this . selected !== this . tree ) {
this . pencil . setVisible ( true ) ;
this . bin . setVisible ( true ) ;
}
if ( this . selected . canAddNode ) {
this . plus . setVisible ( true ) ;
}
}
doDrag ( pointer , target , dragX , dragY ) {
doDrag ( pointer , target , dragX , dragY ) {
target . setX ( dragX ) ;
target . setX ( dragX ) ;
target . setY ( dragY ) ;
target . setY ( dragY ) ;
@ -58,14 +72,6 @@ class Game extends Phaser.Scene {
this . changeFrame ( btn , 0 ) ;
this . changeFrame ( btn , 0 ) ;
}
}
clickPlay ( btn ) {
if ( this . scene . isPaused ( 'GamingBoard' ) )
this . resume ( ) ;
else
this . pauseScene ( ) ;
this . changeFrame ( btn , 1 ) ;
}
changeFrame ( btn , bonus ) {
changeFrame ( btn , bonus ) {
btn . setFrame ( this . line * 2 + bonus ) ;
btn . setFrame ( this . line * 2 + bonus ) ;
@ -83,4 +89,72 @@ class Game extends Phaser.Scene {
this . gm . modifyNodes ( this . tree . getNodes ( ) ) ;
this . gm . modifyNodes ( this . tree . getNodes ( ) ) ;
this . scene . resume ( 'GamingBoard' ) ;
this . scene . resume ( 'GamingBoard' ) ;
}
}
createButton ( ) {
let x = WIDTH _MAP + WIDTH _WINDOW / 10 ;
let y = WIDTH _MAP + HEIGHT _WINDOW / 10 + 5 ;
let diffX = ( HEIGHT _WINDOW / 10 ) ;
let width = HEIGHT _WINDOW / 15 ;
let play = this . add . sprite ( x , y , 'play' ) . setOrigin ( 1 , 0 ) . setInteractive ( ) ;
this . pencil = this . add . sprite ( x - diffX , y , 'pencil' ) . setOrigin ( 1 , 0 ) . setInteractive ( ) . setVisible ( false ) ;
this . bin = this . add . sprite ( x - diffX * 2 , y , 'bin' ) . setOrigin ( 1 , 0 ) . setInteractive ( ) . setVisible ( false ) ;
this . plus = this . add . sprite ( x - diffX * 3 , y , 'plus' ) . setOrigin ( 1 , 0 ) . setInteractive ( ) . setVisible ( false ) ;
this . line = 0 ;
play . displayHeight = play . displayWidth = width ;
this . pencil . displayHeight = this . pencil . displayWidth = width ;
this . bin . displayHeight = this . bin . displayWidth = width ;
this . plus . displayHeight = this . plus . displayWidth = width ;
this . creatBtnOutAndOver ( play ) ;
this . creatBtnOutAndOver ( this . pencil ) ;
this . creatBtnOutAndOver ( this . bin ) ;
this . creatBtnOutAndOver ( this . plus ) ;
play . on ( 'pointerdown' , ( ) => this . clickPlay ( play ) ) ;
this . pencil . on ( 'pointerdown' , ( ) => this . clickPencil ( ) ) ;
this . bin . on ( 'pointerdown' , ( ) => this . clickBin ( ) ) ;
this . plus . on ( 'pointerdown' , ( ) => this . clickPlus ( ) ) ;
this . input . on ( 'pointerdown' , ( ) => this . OK ( ) ) ;
this . input . on ( 'drag' , this . doDrag ) ;
this . input . on ( 'dragstart' , ( ) => this . pauseScene ( play ) ) ;
}
creatBtnOutAndOver ( btn ) {
btn . on ( 'pointerout' , ( ) => this . changeFrame ( btn , 0 ) ) ;
btn . on ( 'pointerover' , ( ) => this . changeFrame ( btn , 1 ) ) ;
}
clickPlay ( btn ) {
if ( this . scene . isPaused ( 'GamingBoard' ) )
this . resume ( ) ;
else
this . pauseScene ( btn ) ;
this . changeFrame ( btn , 1 ) ;
}
clickPencil ( ) {
console . log ( "PENCIL" ) ;
this . changeFrame ( this . pencil , 0 ) ;
}
clickBin ( ) {
console . log ( "BIN" ) ;
this . tree . delete ( this . selected ) ;
this . changeFrame ( this . bin , 0 ) ;
}
clickPlus ( ) {
console . log ( "PLUS" ) ;
this . changeFrame ( this . plus , 0 ) ;
}
}
}