diff --git a/Code/public/js/app.min.js b/Code/public/js/app.min.js index 819c5f0..a62315c 100644 --- a/Code/public/js/app.min.js +++ b/Code/public/js/app.min.js @@ -1 +1 @@ -var EnemyBots=new Array(5),myself=new Robot(5,5);EnemyBots.push(new Robot(1,1)),console.log(myself.height);const WIDTH_WINDOW=$(document).width()-30,HEIGHT_WINDOW=$(document).height()-30;var config={type:Phaser.AUTO,width:WIDTH_WINDOW,height:HEIGHT_WINDOW,parent:"all",backgroundColor:"#35363A",scene:[Boot,Type,Game,GamingBoard]},game=new Phaser.Game(config); \ No newline at end of file +var EnemyBots=new Array(5),myself=new Robot(5,5);EnemyBots.push(new Robot(1,1)),console.log(myself.height);const WIDTH_WINDOW=$(document).width()-30,HEIGHT_WINDOW=$(document).height()-30;var config={type:Phaser.AUTO,width:WIDTH_WINDOW,height:HEIGHT_WINDOW,parent:"all",backgroundColor:"#35363A"},game=new Phaser.Game(config);game.scene.add("Boot",Boot),game.scene.add("Type",Type),game.scene.add("Game",new Game(game)),game.scene.start("Boot"); \ No newline at end of file diff --git a/Code/public/js/class.min.js b/Code/public/js/class.min.js index 5640fcf..3625c9e 100644 --- a/Code/public/js/class.min.js +++ b/Code/public/js/class.min.js @@ -1 +1 @@ -class Boot extends Phaser.Scene{constructor(){super("Boot")}preload(){this.load.spritesheet("btn_play","assets/btnPlay.png",{frameWidth:650,frameHeight:170}),this.load.spritesheet("btn_duel","assets/btnDuel.png",{frameWidth:269,frameHeight:262}),this.load.spritesheet("btn_last","assets/btnLast.png",{frameWidth:269,frameHeight:262}),this.load.spritesheet("btn_team","assets/btnTeam.png",{frameWidth:269,frameHeight:262}),this.load.spritesheet("btn_flag","assets/btnFlag.png",{frameWidth:269,frameHeight:262}),this.load.spritesheet("btn_map","assets/btnMap.png",{frameWidth:269,frameHeight:262}),this.load.image("background","assets/background.png")}create(){this.add.text(WIDTH_WINDOW/2,HEIGHT_WINDOW/3,"WARIA",{font:"200px stencil",fill:"#e2e2e2"}).setOrigin(.5,.5);let t=this.add.sprite(WIDTH_WINDOW/2,HEIGHT_WINDOW/3*2,"btn_play").setInteractive();t.on("pointerout",()=>t.setFrame(0)),t.on("pointerover",()=>t.setFrame(1)),t.on("pointerdown",()=>this.clickPlay(t))}clickPlay(t){t.setFrame(2),console.log("Play"),this.scene.start("Type")}}class Game extends Phaser.Scene{constructor(){super("Game")}preload(){}create(){let t=this.add.sprite(WIDTH_WINDOW/1.5,HEIGHT_WINDOW/3*2,"btn_play").setOrigin(.5,.5).setInteractive();t.on("pointerout",()=>t.setFrame(0)),t.on("pointerover",()=>t.setFrame(1)),t.on("pointerdown",()=>this.clickPlay(t)),this.scene.launch("GamingBoard")}}class GamingBoard extends Phaser.Scene{constructor(){super("GamingBoard")}preload(){WIDTH_WINDOWt.setFrame(0)),t.on("pointerover",()=>t.setFrame(1)),t.on("pointerdown",()=>this.clickPlay(t))}clickPlay(t){this.scene.start("Game")}} \ No newline at end of file +class Boot extends Phaser.Scene{constructor(){super("Boot")}preload(){this.load.spritesheet("btn_play","assets/btnPlay.png",{frameWidth:650,frameHeight:170}),this.load.spritesheet("btn_duel","assets/btnDuel.png",{frameWidth:269,frameHeight:262}),this.load.spritesheet("btn_last","assets/btnLast.png",{frameWidth:269,frameHeight:262}),this.load.spritesheet("btn_team","assets/btnTeam.png",{frameWidth:269,frameHeight:262}),this.load.spritesheet("btn_flag","assets/btnFlag.png",{frameWidth:269,frameHeight:262}),this.load.spritesheet("btn_map","assets/btnMap.png",{frameWidth:269,frameHeight:262}),this.load.image("background","assets/background.png")}create(){this.add.text(WIDTH_WINDOW/2,HEIGHT_WINDOW/3,"WARIA",{font:"200px stencil",fill:"#e2e2e2"}).setOrigin(.5,.5);let t=this.add.sprite(WIDTH_WINDOW/2,HEIGHT_WINDOW/3*2,"btn_play").setInteractive();t.on("pointerout",()=>t.setFrame(0)),t.on("pointerover",()=>t.setFrame(1)),t.on("pointerdown",()=>this.clickPlay(t))}clickPlay(t){t.setFrame(2),console.log("Play"),this.scene.start("Type")}}class Game extends Phaser.Scene{constructor(t){super("Game"),this.game=t}preload(){this.gm=new GamingBoard,this.game.scene.add("GamingBoard",this.gm)}create(){let t=this.add.sprite(WIDTH_WINDOW/1.5,HEIGHT_WINDOW/3*2,"btn_play").setOrigin(.5,.5).setInteractive();t.on("pointerout",()=>t.setFrame(0)),t.on("pointerover",()=>t.setFrame(1)),t.on("pointerdown",()=>this.clickPlay(t)),this.scene.launch("GamingBoard"),this.scene.pause("GamingBoard")}clickPlay(t){this.scene.isPaused("GamingBoard")?this.scene.resume("GamingBoard"):this.scene.pause("GamingBoard")}}class GamingBoard extends Phaser.Scene{constructor(){super("GamingBoard")}preload(){WIDTH_WINDOWt.setFrame(0)),t.on("pointerover",()=>t.setFrame(1)),t.on("pointerdown",()=>this.clickPlay(t))}clickPlay(t){this.scene.start("Game")}} \ No newline at end of file diff --git a/Code/src/js/Init.js b/Code/src/js/Init.js index f317869..e1bd8e2 100644 --- a/Code/src/js/Init.js +++ b/Code/src/js/Init.js @@ -1,6 +1,6 @@ var EnemyBots = new Array(5); -var myself = new Robot(5,5); -EnemyBots.push(new Robot(1,1)); +var myself = new Robot(5, 5); +EnemyBots.push(new Robot(1, 1)); console.log(myself.height); const WIDTH_WINDOW = $(document).width() - 30; const HEIGHT_WINDOW = $(document).height() - 30; @@ -11,7 +11,11 @@ var config = { height: HEIGHT_WINDOW, parent: 'all', backgroundColor: '#35363A', - scene: [ Boot, Type, Game, GamingBoard ] }; var game = new Phaser.Game(config); + +game.scene.add('Boot', Boot); +game.scene.add('Type', Type); +game.scene.add('Game', new Game(game)); +game.scene.start('Boot'); diff --git a/Code/src/js/classes/Game.js b/Code/src/js/classes/Game.js index fef0591..6dbe9e4 100644 --- a/Code/src/js/classes/Game.js +++ b/Code/src/js/classes/Game.js @@ -1,9 +1,12 @@ class Game extends Phaser.Scene { - constructor() { + constructor(game) { super('Game'); + this.game = game; } preload() { + this.gm = new GamingBoard(); + this.game.scene.add('GamingBoard',this.gm); } create() { @@ -15,6 +18,13 @@ class Game extends Phaser.Scene { btn.on('pointerover', () => btn.setFrame(1)); btn.on('pointerdown', () => this.clickPlay(btn)); this.scene.launch('GamingBoard'); - //this.scene.isActive('GamingBoard'); + this.scene.pause('GamingBoard'); + } + + clickPlay(btn){ + if(this.scene.isPaused('GamingBoard')) + this.scene.resume('GamingBoard'); + else + this.scene.pause('GamingBoard'); } } \ No newline at end of file diff --git a/Code/src/js/classes/GamingBoard.js b/Code/src/js/classes/GamingBoard.js index 0760aa9..5870e81 100644 --- a/Code/src/js/classes/GamingBoard.js +++ b/Code/src/js/classes/GamingBoard.js @@ -16,8 +16,21 @@ class GamingBoard extends Phaser.Scene { create() { this.add.image(0, 0, 'background').alpha = 0.1; - this.add.circle(this.width*0.1,this.width*0.1,this.width*0.05, 0x6666ff); - this.add.circle(this.width*0.9,this.width*0.9,this.width*0.05, 0xff33cc); + this.enemy = this.add.circle(this.width * 0.1, this.width * 0.1, this.width * 0.05, 0x6666ff); + this.myself = this.add.circle(this.width * 0.9, this.width * 0.9, this.width * 0.05, 0xff33cc); } + + update(time, delta) { + super.update(time, delta); + if (this.enemy.x < this.myself.x) + this.myself.setX(this.myself.x - 0.5); + else if (-0.5 < this.enemy.x - this.myself.x < 0.5) + this.myself.setX(this.myself.x + 0.5); + + if (this.enemy.y < this.myself.y) + this.myself.setY(this.myself.y - 0.5); + else if (-0.5 < this.enemy.y - this.myself.y < 0.5) + this.myself.setY(this.myself.y - 0.5); + } } \ No newline at end of file