Création d'un premier déplacement pour le robot d'un point A à un point B. Modification du code pour pouvoir envoyer des infos de Game à GamingBoard -> Ajout d'un bouton play pause pour stopper le déroulement de la partie.

master
clmaisonha 5 years ago
parent d660b74209
commit 237207c495

@ -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);
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");

@ -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_WINDOW<HEIGHT_WINDOW?this.width=.8*WIDTH_WINDOW:this.width=.8*HEIGHT_WINDOW,this.cameras.main.setViewport(WIDTH_WINDOW/10,HEIGHT_WINDOW/10,this.width,this.width)}create(){this.add.image(0,0,"background").alpha=.1,this.add.circle(.1*this.width,.1*this.width,.05*this.width,6711039),this.add.circle(.9*this.width,.9*this.width,.05*this.width,16724940)}}class Robot{constructor(t,e){this.height=t,this.width=e}}class Type extends Phaser.Scene{constructor(){super("Type")}preload(){}create(){this.add.text(WIDTH_WINDOW/2,HEIGHT_WINDOW/4,"WARIA",{font:"200px stencil",fill:"#e2e2e2"}).setOrigin(.5,1);let t=this.add.sprite(WIDTH_WINDOW/8*3,HEIGHT_WINDOW/4*2,"btn_duel").setInteractive();this.createbutton(t);let e=this.add.sprite(WIDTH_WINDOW/8*5,HEIGHT_WINDOW/4*2,"btn_last").setInteractive();this.createbutton(e);let s=this.add.sprite(WIDTH_WINDOW/8*2,HEIGHT_WINDOW/4*3,"btn_team").setInteractive();this.createbutton(s);let a=this.add.sprite(WIDTH_WINDOW/8*4,HEIGHT_WINDOW/4*3,"btn_flag").setInteractive();this.createbutton(a);let i=this.add.sprite(WIDTH_WINDOW/8*6,HEIGHT_WINDOW/4*3,"btn_map").setInteractive();this.createbutton(i)}createbutton(t){t.displayHeight=HEIGHT_WINDOW/4,t.scaleX=t.scaleY,t.on("pointerout",()=>t.setFrame(0)),t.on("pointerover",()=>t.setFrame(1)),t.on("pointerdown",()=>this.clickPlay(t))}clickPlay(t){this.scene.start("Game")}}
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_WINDOW<HEIGHT_WINDOW?this.width=.8*WIDTH_WINDOW:this.width=.8*HEIGHT_WINDOW,this.cameras.main.setViewport(WIDTH_WINDOW/10,HEIGHT_WINDOW/10,this.width,this.width)}create(){this.add.image(0,0,"background").alpha=.1,this.enemy=this.add.circle(.1*this.width,.1*this.width,.05*this.width,6711039),this.myself=this.add.circle(.9*this.width,.9*this.width,.05*this.width,16724940)}update(t,e){super.update(t,e),this.enemy.x<this.myself.x?this.myself.setX(this.myself.x-.5):-.5<this.enemy.x-this.myself.x<.5&&this.myself.setX(this.myself.x+.5),this.enemy.y<this.myself.y?this.myself.setY(this.myself.y-.5):-.5<this.enemy.y-this.myself.y<.5&&this.myself.setY(this.myself.y-.5)}}class Robot{constructor(t,e){this.height=t,this.width=e}}class Type extends Phaser.Scene{constructor(){super("Type")}preload(){}create(){this.add.text(WIDTH_WINDOW/2,HEIGHT_WINDOW/4,"WARIA",{font:"200px stencil",fill:"#e2e2e2"}).setOrigin(.5,1);let t=this.add.sprite(WIDTH_WINDOW/8*3,HEIGHT_WINDOW/4*2,"btn_duel").setInteractive();this.createbutton(t);let e=this.add.sprite(WIDTH_WINDOW/8*5,HEIGHT_WINDOW/4*2,"btn_last").setInteractive();this.createbutton(e);let s=this.add.sprite(WIDTH_WINDOW/8*2,HEIGHT_WINDOW/4*3,"btn_team").setInteractive();this.createbutton(s);let i=this.add.sprite(WIDTH_WINDOW/8*4,HEIGHT_WINDOW/4*3,"btn_flag").setInteractive();this.createbutton(i);let a=this.add.sprite(WIDTH_WINDOW/8*6,HEIGHT_WINDOW/4*3,"btn_map").setInteractive();this.createbutton(a)}createbutton(t){t.displayHeight=HEIGHT_WINDOW/4,t.scaleX=t.scaleY,t.on("pointerout",()=>t.setFrame(0)),t.on("pointerover",()=>t.setFrame(1)),t.on("pointerdown",()=>this.clickPlay(t))}clickPlay(t){this.scene.start("Game")}}

@ -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');

@ -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');
}
}

@ -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);
}
}
Loading…
Cancel
Save