@ -12,10 +12,12 @@ class Game extends Phaser.Scene {
create ( ) {
create ( ) {
//this.add.image(0,0,'background').alpha = 0.1;
//this.add.image(0,0,'background').alpha = 0.1;
let btn = this . add . sprite ( WIDTH _WINDOW / 1.5 , ( HEIGHT _WINDOW / 3 ) * 2 , 'btn_play' ) . setOrigin ( 0.5 , 0.5 ) . setInteractive ( ) ;
let btn = this . add . sprite ( WIDTH _MAP + WIDTH _WINDOW / 10 , WIDTH _MAP + HEIGHT _WINDOW / 10 + 5 , 'play' ) . setOrigin ( 1 , 0 ) . setInteractive ( ) ;
//btn.setFrame(0);
this . line = 0 ;
btn . on ( 'pointerout' , ( ) => btn . setFrame ( 0 ) ) ;
btn . displayHeight = HEIGHT _WINDOW / 15 ;
btn . on ( 'pointerover' , ( ) => btn . setFrame ( 1 ) ) ;
btn . scaleX = btn . scaleY ;
btn . on ( 'pointerout' , ( ) => this . changeFrame ( btn , 0 ) ) ;
btn . on ( 'pointerover' , ( ) => this . changeFrame ( btn , 1 ) ) ;
btn . on ( 'pointerdown' , ( ) => this . clickPlay ( btn ) ) ;
btn . on ( 'pointerdown' , ( ) => this . clickPlay ( btn ) ) ;
this . scene . launch ( 'GamingBoard' ) ;
this . scene . launch ( 'GamingBoard' ) ;
this . scene . pause ( 'GamingBoard' ) ;
this . scene . pause ( 'GamingBoard' ) ;
@ -26,17 +28,18 @@ class Game extends Phaser.Scene {
this . tree . addRect ( new RectangleNode ( WIDTH _WINDOW / 1.5 , 400 , this , 'attack' ) ) ;
this . tree . addRect ( new RectangleNode ( WIDTH _WINDOW / 1.5 , 400 , this , 'attack' ) ) ;
let robot = new Robot ( WIDTH _MAP * 0.1 , WIDTH _MAP * 0.1 , WIDTH _MAP * 0.9 , WIDTH _MAP * 0.9 , 0x6666ff , this . gm );
let robot = new Robot ( WIDTH _MAP * 0.1 , WIDTH _MAP * 0.1 , WIDTH _MAP * 0.9 , WIDTH _MAP * 0.9 , 0x6666ff , this . gm , 'myself' );
let condition = new RectangleNode ( WIDTH _WINDOW / 1.7 , 400 , this , 'condition' , robot , true , false , 0.5 , 0 ) ;
let condition = new RectangleNode ( WIDTH _WINDOW / 1.7 , 400 , this , 'condition' , robot , true , false , 1 / 3 , 0 ) ;
condition . addRect ( new RectangleNode ( WIDTH _WINDOW / 1.2 , 600 , this , 'move' , false ) ) ;
condition . addRect ( new RectangleNode ( WIDTH _WINDOW / 1.2 , 600 , this , 'move' , false ) ) ;
condition . addRect ( new RectangleNode ( WIDTH _WINDOW / 1.5 , 600 , this , 'attack' ) )
condition . addRect ( new RectangleNode ( WIDTH _WINDOW / 1.5 , 600 , this , 'attack' ) )
this . tree . addRect ( condition ) ;
this . tree . addRect ( condition ) ;
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 , 0xff 33cc , this . gm ) ) ;
this . gm . addRobot ( new Robot ( WIDTH _MAP * 0.1 , WIDTH _MAP * 0.1 , WIDTH _MAP * 0.2 , WIDTH _MAP * 0.1 , 0xff 0000 , this . gm ) ) ;
this . gm . addRobot ( new Robot ( WIDTH _MAP * 0.1 , WIDTH _MAP * 0.1 , WIDTH _MAP * 0.1 , WIDTH _MAP * 0.9 , 0xff ffff , this . gm ) ) ;
this . gm . addRobot ( new Robot ( WIDTH _MAP * 0.1 , WIDTH _MAP * 0.1 , WIDTH _MAP * 0.1 , WIDTH _MAP * 0.9 , 0xff 0000 , this . gm ) ) ;
this . input . on ( 'drag' , this . doDrag ) ;
this . input . on ( 'drag' , this . doDrag ) ;
this . input . on ( 'dragstart' , ( ) => this . pauseScene ( btn ) ) ;
}
}
update ( time , delta ) {
update ( time , delta ) {
@ -49,15 +52,27 @@ class Game extends Phaser.Scene {
target . setY ( dragY ) ;
target . setY ( dragY ) ;
}
}
pauseScene ( btn ) {
this . line = 0 ;
this . scene . pause ( 'GamingBoard' ) ;
this . changeFrame ( btn , 0 ) ;
}
clickPlay ( btn ) {
clickPlay ( btn ) {
btn . setFrame ( 2 ) ;
if ( this . scene . isPaused ( 'GamingBoard' ) )
if ( this . scene . isPaused ( 'GamingBoard' ) )
this . resume ( ) ;
this . resume ( ) ;
else
else
this . scene . pause ( 'GamingBoard' ) ;
this . pauseScene ( ) ;
this . changeFrame ( btn , 1 ) ;
}
changeFrame ( btn , bonus ) {
btn . setFrame ( this . line * 2 + bonus ) ;
}
}
resume ( ) {
resume ( ) {
this . line = 1 ;
const sortDesc = ( a , b ) => a . getX ( ) - b . getX ( ) ;
const sortDesc = ( a , b ) => a . getX ( ) - b . getX ( ) ;
this . tree . lRect . sort ( sortDesc ) ;
this . tree . lRect . sort ( sortDesc ) ;
this . tree . lRect . forEach ( function ( element ) {
this . tree . lRect . forEach ( function ( element ) {