From 9a062269ce445294383446fabaeff098b94fd247 Mon Sep 17 00:00:00 2001 From: clmaisonha Date: Wed, 17 Jun 2020 23:08:14 +0200 Subject: [PATCH] =?UTF-8?q?Les=20points=20de=20boucliers=20se=20r=C3=A9g?= =?UTF-8?q?=C3=A9n=C3=A8rent=20en=20fonction=20du=20temps=20(5=20pas=20sec?= =?UTF-8?q?onde)=20-=20Affichage=20d'un=20cercle=20pour=20afficher=20la=20?= =?UTF-8?q?distance=20de=20tir=20du=20cercle=20bleu=20-=20Cr=C3=A9ation=20?= =?UTF-8?q?des=20diff=C3=A9rentes=20sc=C3=A8ne=20qui=20gereront=20par=20la?= =?UTF-8?q?=20suite=20la=20cr=C3=A9ation=20propre=20=C3=A0=20chaque=20acti?= =?UTF-8?q?on=20(attaquer,=20d=C3=A9placement,=20condition).=20Pour=20le?= =?UTF-8?q?=20moment,=20il=20y=20a=20beaucoup=20de=20code=20en=20double=20?= =?UTF-8?q?entre=20ces=20sc=C3=A8nes=20car=20elles=20ont=20le=20m=C3=AAme?= =?UTF-8?q?=20principe=20de=20fonctionnement.=20Elles=20seront=20par=20la?= =?UTF-8?q?=20suite=20regroup=C3=A9=20par=20un=20p=C3=A8re.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Code/public/js/app.min.js | 2 +- Code/public/js/class.min.js | 2 +- Code/src/js/Init.js | 1 + Code/src/js/classes/AddAttack.js | 29 +++++++++++++++++++++++++++++ Code/src/js/classes/AddCondition.js | 28 ++++++++++++++++++++++++++++ Code/src/js/classes/AddMove.js | 29 +++++++++++++++++++++++++++++ Code/src/js/classes/Game.js | 2 +- Code/src/js/classes/GamingBoard.js | 11 ++++++++++- Code/src/js/classes/HealthBar.js | 10 +++++++++- Code/src/js/classes/PlusNode.js | 12 +++++++----- Code/src/js/classes/Robot.js | 28 ++++++++++++++++++++++++++++ 11 files changed, 144 insertions(+), 10 deletions(-) create mode 100644 Code/src/js/classes/AddAttack.js create mode 100644 Code/src/js/classes/AddCondition.js create mode 100644 Code/src/js/classes/AddMove.js diff --git a/Code/public/js/app.min.js b/Code/public/js/app.min.js index 1f84513..41588d3 100644 --- a/Code/public/js/app.min.js +++ b/Code/public/js/app.min.js @@ -1 +1 @@ -const COLOR_ATTACK=16711680,COLOR_MOVE=255,COLOR_CONDITION=921102,WIDTH_WINDOW=$(document).width()-20,HEIGHT_WINDOW=$(document).height()-20,WIDTH_MAP=WIDTH_WINDOWt.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 Condition{constructor(t,e=!1,i=!1,s,h){this.shieldFilter=e,this.rangeFilter=i,this.shield=s,this.range=h,this.target=t,this.lNode=[]}addNode(t){this.lNode.push(t)}do(t){if(this.doCondition(t))for(let e=0;et.getX()-e.getX();this.tree.lRect.sort(t),this.tree.lRect.forEach(function(e){void 0!==e.lRect&&e.lRect.sort(t)}),this.gm.modifyNodes(this.tree.getNodes()),this.scene.resume("GamingBoard")}createButton(){let t=WIDTH_MAP+WIDTH_WINDOW/10,e=WIDTH_MAP+HEIGHT_WINDOW/10+5,i=HEIGHT_WINDOW/10,s=HEIGHT_WINDOW/15,h=this.add.sprite(t,e,"play").setOrigin(1,0).setInteractive();this.pencil=this.add.sprite(t-i,e,"pencil").setOrigin(1,0).setInteractive().setVisible(!1),this.bin=this.add.sprite(t-2*i,e,"bin").setOrigin(1,0).setInteractive().setVisible(!1),this.plus=this.add.sprite(t-3*i,e,"plus").setOrigin(1,0).setInteractive().setVisible(!1),this.line=0,h.displayHeight=h.displayWidth=s,this.pencil.displayHeight=this.pencil.displayWidth=s,this.bin.displayHeight=this.bin.displayWidth=s,this.plus.displayHeight=this.plus.displayWidth=s,this.creatBtnOutAndOver(h),this.creatBtnOutAndOver(this.pencil),this.creatBtnOutAndOver(this.bin),this.creatBtnOutAndOver(this.plus),h.on("pointerdown",()=>this.clickPlay(h)),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(h))}creatBtnOutAndOver(t){t.on("pointerout",()=>this.changeFrame(t,0)),t.on("pointerover",()=>this.changeFrame(t,1))}clickPlay(t){this.scene.isPaused("GamingBoard")?this.resume():this.pauseScene(t),this.changeFrame(t,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.scene.launch("PlusNode"),this.changeFrame(this.plus,0),this.scene.pause("Game")}}class GamingBoard extends Phaser.Scene{constructor(){super("GamingBoard"),this.listRobot=[]}preload(){this.cameras.main.setViewport(WIDTH_WINDOW/10,HEIGHT_WINDOW/10,WIDTH_MAP,WIDTH_MAP)}create(){this.add.image(0,0,"background").alpha=.1;for(let t=0;tthis.resume())}update(t,e){super.update(t,e),this.listRobot.forEach(function(t){t.read()});for(let t=0;tthis.listRobot[0].addNode(t))}chooseTarget(t){let e=2*WIDTH_MAP,i=[];this.listRobot.forEach(function(s){if(s!==t&&s.isAlive()){let h=Math.hypot(s.x-t.x,s.y-t.y);e>=h&&(e>h&&(e=h,i=[]),i.push(s))}}),this.listRobot.length>1?t.setTarget(i[Math.floor(Math.random()*(i.length+1))]):t.setTarget(i[0])}}class HealthBar{constructor(t,e,i,s,h,a,n){this.bar=new Phaser.GameObjects.Graphics(t),this.width=e,this.height=i,this.valueMax=a,this.value=a,this.color=n,this.draw(),this.setX(s),this.setY(h),t.add.existing(this.bar)}decrease(t){this.value-=t;let e=0;return this.value<0&&(e=-this.value,this.value=0),this.draw(),e}setX(t){this.bar.setX(t-this.width/2)}setY(t){this.bar.setY(t)}draw(){this.bar.clear(),this.bar.fillStyle(0),this.bar.fillRect(0,0,this.width,this.height),this.bar.fillStyle(16777215),this.bar.fillRect(2,2,this.width-4,this.height-4);let t=this.value/this.valueMax;t<.3?this.bar.fillStyle(16711680):this.bar.fillStyle(this.color);let e=Math.floor(t*(this.width-4));this.bar.fillRect(2,2,e,this.height-4)}destroy(){this.bar.destroy()}}class Missile extends Phaser.GameObjects.Image{constructor(t,e,i,s){super(t,0,0,e),this.visible=!1,this.setOrigin(.5,.5),this.setScale(.02)}}class Move{constructor(t){this.toward=t}do(t){return!!t.haveTarget()&&(!0===this.toward?this.moveToward(t):this.fleeFrom(t))}moveToward(t){return t.advanceToTarget()}fleeFrom(t){return t.fleeFromTarget()}}class PlusNode extends Phaser.Scene{constructor(){super("PlusNode")}create(){this.add.rectangle(0,0,WIDTH_WINDOW,HEIGHT_WINDOW,0).setOrigin(0,0).setAlpha(.5),this.add.rectangle(0,HEIGHT_WINDOW/2,WIDTH_WINDOW,HEIGHT_WINDOW/2,3487290).setOrigin(0,.5),this.createNode(),this.createButton()}createNode(){let t=WIDTH_WINDOW/2,e=HEIGHT_WINDOW/2,i=WIDTH_WINDOW/4,s=HEIGHT_WINDOW/10,h={font:s.toString()+"px stencil",fill:"#e2e2e2"};this.add.text(t-i,e-s,"ATTACK",h).setOrigin(.5,.5),this.add.text(t,e-s,"MOVE",h).setOrigin(.5,.5),this.add.text(t+i,e-s,"CONDITION",h).setOrigin(.5,.5),this.add.sprite(t-i,e+s,"attack").setOrigin(.5,.5).setInteractive().on("pointerdown",()=>this.click("attack")),this.add.sprite(t,e+s,"move").setOrigin(.5,.5).setInteractive().on("pointerdown",()=>this.click("move")),this.add.sprite(t+i,e+s,"condition").setOrigin(.5,.5).setInteractive().on("pointerdown",()=>this.click("condition"))}click(t){t.toString(),console.log(t.toString())}createButton(){let t=WIDTH_WINDOW/2,e=HEIGHT_WINDOW-100;this.cancelBtn=this.add.image(t,e,"cancel").setOrigin(.5,.5).setInteractive(),this.cancelBtn.on("pointerover",()=>this.cancelBtn.setFrame(1)),this.cancelBtn.on("pointerout",()=>this.cancelBtn.setFrame(0)),this.cancelBtn.on("pointerdown",()=>this.cancel())}cancel(){this.scene.resume("Game"),this.scene.stop("PlusNode")}}class RectangleNode{constructor(t,e,i,s,...h){switch(s.toString().toLowerCase()){case"attack":this.rect=new Phaser.GameObjects.Image(i,t,e,"attackN"),this.node=new Attack,this.canAddNode=!1,this.line=i.add.graphics();break;case"move":this.rect=new Phaser.GameObjects.Image(i,t,e,"moveN"),this.node=new Move(h[0]),this.canAddNode=!1,this.line=i.add.graphics(),!0===h[0]?this.rect.setFrame(0):this.rect.setFrame(2);break;case"condition":let a;this.rect=new Phaser.GameObjects.Image(i,t,e,"conditionN"),this.node=new Condition(h[0],h[1],h[2],h[3],h[4]),this.canAddNode=!0,this.lRect=[],this.scene=i,this.line=i.add.graphics(),a="myself"===h[0].name.toString().toLowerCase()?0:1;let n=0;!0===h[1]&&(n=Math.floor(3*h[3])),h[2],this.rect.setFrame(4*a+n);break;case"waria":this.rect=new Phaser.GameObjects.Image(i,t,e,"logoWaria").setInteractive(),this.canAddNode=!0,this.lRect=[],this.scene=i,this.scene.add.existing(this.rect);break;default:return void console.log("Création d'un node echoué")}s.toString().toLowerCase(),this.rect.on("pointerdown",()=>this.click()),this.rect.setOrigin(.5,0),this.rect.displayHeight=HEIGHT_WINDOW/6,this.rect.scaleX=this.rect.scaleY}getSelected(){if(this.rect.isTinted)return this;if(this.canAddNode)for(let t=0;tthis.addLine(t))}addLine(t){t.setLine(this.rect.x,this.rect.y+.9*this.rect.displayHeight)}getNodes(){if(void 0===this.node){let t=[];return this.lRect.forEach(function(e){void 0!==e.node&&(void 0!==e.lRect&&(e.node.clearNodes(),e.lRect.forEach(t=>e.node.addNode(t.node))),t.push(e.node))}),t}}destroy(){this.line.destroy(),this.rect.destroy(),void 0!==this.lRect&&this.lRect.forEach(t=>t.destroy())}delete(t){let e=this.lRect.indexOf(t);if(-1!==e)return this.lRect.splice(e,1),t.destroy(),!0;for(let e=0;e=0&&this.x>=this.target.x||this.velocityX<=0&&this.x<=this.target.x?this.setX(this.target.x):this.setX(this.x+this.velocityX),this.velocityY>=0&&this.y>=this.target.y||this.velocityY<=0&&this.y<=this.target.y?this.setY(this.target.y):this.setY(this.y+this.velocityY),!0)}fleeFromTarget(){return!!this.verifyTarget()&&(this.velocityX>=0&&this.x-this.width/2<=0?this.setX(this.width/2):this.velocityX<=0&&this.x+this.width/2>=WIDTH_MAP?this.setX(WIDTH_MAP-this.width/2):this.setX(this.x-this.velocityX),this.velocityY>=0&&this.y-this.width/2<=0?this.setY(this.height/2):this.velocityY<=0&&this.y+this.width/2>=WIDTH_MAP?this.setY(WIDTH_MAP-this.height/2):this.setY(this.y-this.velocityY),!0)}attackTarget(){return!!(this.verifyTarget()&&this.target.isAlive()&&this.isTargetInRange())&&(this.canAttack&&this.attack(this.target),!0)}verifyTarget(){return!!this.haveTarget()&&(!!this.target.isAlive()||(this.setTarget(null),!1))}attack(t){this.canAttack=!1,this.missile.setPosition(this.x,this.y).setVisible(!0),this.missile.setRotation(Math.atan2(this.y-this.target.y,this.x-this.target.x)-1.57),this.scene.tweens.add({targets:this.missile,x:t.x,y:t.y,ease:"Linear",duration:200,onComplete:()=>this.finishAttack(t)}),this.scene.time.addEvent({delay:Phaser.Math.Between(1e3,3e3),callback:this.reload,callbackScope:this})}finishAttack(t){t.beAttack(this.damage)&&this.setTarget(null),this.missile.setVisible(!1)}reload(){this.canAttack=!0}beAttack(t){let e=this.shield.decrease(t);return e>0&&(console.log("Shield Broken"),this.life.decrease(e)),this.die()}isTargetInRange(){return!!this.verifyTarget()&&this.calcDistance(this.target)0}die(){return 0===this.life.value&&(this.circle.destroy(),this.shield.destroy(),this.life.destroy(),!0)}haveTarget(){return null!=this.target}read(){for(let t=0;tt.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 AddAttack extends Phaser.Scene{constructor(t){super("addNode"),this.game=t}create(){this.add.rectangle(0,0,WIDTH_WINDOW,HEIGHT_WINDOW,0).setOrigin(0,0).setAlpha(.5),console.log("ATTACK"),this.createButton()}createButton(){let t=WIDTH_WINDOW/2,e=HEIGHT_WINDOW-100;this.cancelBtn=this.add.image(t,e,"cancel").setOrigin(.5,.5).setInteractive(),this.cancelBtn.on("pointerover",()=>this.cancelBtn.setFrame(1)),this.cancelBtn.on("pointerout",()=>this.cancelBtn.setFrame(0)),this.cancelBtn.on("pointerdown",()=>this.cancel())}cancel(){this.scene.resume("Game"),this.scene.stop("addNode"),this.game.scene.remove("addNode")}}class AddCondition extends Phaser.Scene{constructor(t){super("addNode"),this.game=t}create(){this.add.rectangle(0,0,WIDTH_WINDOW,HEIGHT_WINDOW,0).setOrigin(0,0).setAlpha(.5),console.log("CONDITION"),this.createButton()}createButton(){let t=WIDTH_WINDOW/2,e=HEIGHT_WINDOW-100;this.cancelBtn=this.add.image(t,e,"cancel").setOrigin(.5,.5).setInteractive(),this.cancelBtn.on("pointerover",()=>this.cancelBtn.setFrame(1)),this.cancelBtn.on("pointerout",()=>this.cancelBtn.setFrame(0)),this.cancelBtn.on("pointerdown",()=>this.cancel())}cancel(){this.scene.resume("Game"),this.scene.stop("addNode"),this.game.scene.remove("addNode")}}class AddMove extends Phaser.Scene{constructor(t){super("addNode"),this.game=t}create(){this.add.rectangle(0,0,WIDTH_WINDOW,HEIGHT_WINDOW,0).setOrigin(0,0).setAlpha(.5),console.log("MOVE"),this.createButton()}createButton(){let t=WIDTH_WINDOW/2,e=HEIGHT_WINDOW-100;this.cancelBtn=this.add.image(t,e,"cancel").setOrigin(.5,.5).setInteractive(),this.cancelBtn.on("pointerover",()=>this.cancelBtn.setFrame(1)),this.cancelBtn.on("pointerout",()=>this.cancelBtn.setFrame(0)),this.cancelBtn.on("pointerdown",()=>this.cancel())}cancel(){this.scene.resume("Game"),this.scene.stop("addNode"),this.game.scene.remove("addNode")}}class Attack{constructor(){}do(t){return!(!t.haveTarget()||!t.isTargetInRange())&&t.attackTarget()}}class Boot extends Phaser.Scene{constructor(){super("Boot")}preload(){let t=this.add.graphics(),e=this.add.graphics(),i=WIDTH_WINDOW/2-160,s=HEIGHT_WINDOW/2-25;e.fillStyle(2236962,.8),e.fillRect(i,s,320,50),this.load.on("progress",function(e){t.clear(),t.fillStyle(16777215,1),t.fillRect(i+10,s+10,300*e,30)}),this.load.on("complete",function(){t.destroy(),e.destroy()}),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.spritesheet("play","assets/play.png",{frameWidth:100,frameHeight:100}),this.load.image("background","assets/background.png"),this.load.image("bullet","assets/bullet.png"),this.load.image("logoWaria","assets/logoWaria.png"),this.load.spritesheet("attackN","assets/nodes/attackNode.png",{frameWidth:180,frameHeight:190}),this.load.spritesheet("moveN","assets/nodes/moveNode.png",{frameWidth:180,frameHeight:190}),this.load.spritesheet("conditionN","assets/nodes/conditionNode.png",{frameWidth:180,frameHeight:190}),this.load.image("attack","assets/nodes/attack.png"),this.load.image("move","assets/nodes/move.png"),this.load.image("condition","assets/nodes/condition.png"),this.load.spritesheet("bin","assets/buttons/bin.png",{frameWidth:100,frameHeight:100}),this.load.spritesheet("plus","assets/buttons/plus.png",{frameWidth:100,frameHeight:100}),this.load.spritesheet("pencil","assets/buttons/pencil.png",{frameWidth:100,frameHeight:100}),this.load.spritesheet("cancel","assets/buttons/cancel.png",{frameWidth:550,frameHeight:150})}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 Condition{constructor(t,e=!1,i=!1,s,a){this.shieldFilter=e,this.rangeFilter=i,this.shield=s,this.range=a,this.target=t,this.lNode=[]}addNode(t){this.lNode.push(t)}do(t){if(this.doCondition(t))for(let e=0;et.getX()-e.getX();this.tree.lRect.sort(t),this.tree.lRect.forEach(function(e){void 0!==e.lRect&&e.lRect.sort(t)}),this.gm.modifyNodes(this.tree.getNodes()),this.scene.resume("GamingBoard")}createButton(){let t=WIDTH_MAP+WIDTH_WINDOW/10,e=WIDTH_MAP+HEIGHT_WINDOW/10+5,i=HEIGHT_WINDOW/10,s=HEIGHT_WINDOW/15,a=this.add.sprite(t,e,"play").setOrigin(1,0).setInteractive();this.pencil=this.add.sprite(t-i,e,"pencil").setOrigin(1,0).setInteractive().setVisible(!1),this.bin=this.add.sprite(t-2*i,e,"bin").setOrigin(1,0).setInteractive().setVisible(!1),this.plus=this.add.sprite(t-3*i,e,"plus").setOrigin(1,0).setInteractive().setVisible(!1),this.line=0,a.displayHeight=a.displayWidth=s,this.pencil.displayHeight=this.pencil.displayWidth=s,this.bin.displayHeight=this.bin.displayWidth=s,this.plus.displayHeight=this.plus.displayWidth=s,this.creatBtnOutAndOver(a),this.creatBtnOutAndOver(this.pencil),this.creatBtnOutAndOver(this.bin),this.creatBtnOutAndOver(this.plus),a.on("pointerdown",()=>this.clickPlay(a)),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(a))}creatBtnOutAndOver(t){t.on("pointerout",()=>this.changeFrame(t,0)),t.on("pointerover",()=>this.changeFrame(t,1))}clickPlay(t){this.scene.isPaused("GamingBoard")?this.resume():this.pauseScene(t),this.changeFrame(t,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.scene.launch("PlusNode"),this.changeFrame(this.plus,0),this.scene.pause("Game")}}class GamingBoard extends Phaser.Scene{constructor(){super("GamingBoard"),this.listRobot=[]}preload(){this.cameras.main.setViewport(WIDTH_WINDOW/10,HEIGHT_WINDOW/10,WIDTH_MAP,WIDTH_MAP)}create(){this.add.image(0,0,"background").alpha=.1;for(let t=0;tthis.resume()),this.time.addEvent({delay:2e3,callback:this.upShield,callbackScope:this})}update(t,e){super.update(t,e),this.listRobot.forEach(function(t){t.read()});for(let t=0;tthis.listRobot[0].addNode(t))}chooseTarget(t){let e=2*WIDTH_MAP,i=[];this.listRobot.forEach(function(s){if(s!==t&&s.isAlive()){let a=Math.hypot(s.x-t.x,s.y-t.y);e>=a&&(e>a&&(e=a,i=[]),i.push(s))}}),this.listRobot.length>1?t.setTarget(i[Math.floor(Math.random()*(i.length+1))]):t.setTarget(i[0])}upShield(){this.listRobot.forEach(t=>t.addShield(SHIELD_PER_SECOND)),this.time.addEvent({delay:1e3,callback:this.upShield,callbackScope:this})}}class HealthBar{constructor(t,e,i,s,a,h,n){this.bar=new Phaser.GameObjects.Graphics(t),this.width=e,this.height=i,this.valueMax=h,this.value=h,this.color=n,this.draw(),this.setX(s),this.setY(a),t.add.existing(this.bar)}decrease(t){this.value-=t;let e=0;return this.value<0&&(e=-this.value,this.value=0),this.draw(),e}increase(t){this.value+=t,this.value>this.valueMax&&(this.value=this.valueMax),this.draw()}setX(t){this.bar.setX(t-this.width/2)}setY(t){this.bar.setY(t)}draw(){this.bar.clear(),this.bar.fillStyle(0),this.bar.fillRect(0,0,this.width,this.height),this.bar.fillStyle(16777215),this.bar.fillRect(2,2,this.width-4,this.height-4);let t=this.value/this.valueMax;t<1/3?this.bar.fillStyle(16711680):this.bar.fillStyle(this.color);let e=Math.floor(t*(this.width-4));this.bar.fillRect(2,2,e,this.height-4)}destroy(){this.bar.destroy()}}class Missile extends Phaser.GameObjects.Image{constructor(t,e,i,s){super(t,0,0,e),this.visible=!1,this.setOrigin(.5,.5),this.setScale(.02)}}class Move{constructor(t){this.toward=t}do(t){return!!t.haveTarget()&&(!0===this.toward?this.moveToward(t):this.fleeFrom(t))}moveToward(t){return t.advanceToTarget()}fleeFrom(t){return t.fleeFromTarget()}}class PlusNode extends Phaser.Scene{constructor(t){super("PlusNode"),this.game=t}create(){this.add.rectangle(0,0,WIDTH_WINDOW,HEIGHT_WINDOW,0).setOrigin(0,0).setAlpha(.5),this.add.rectangle(0,HEIGHT_WINDOW/2,WIDTH_WINDOW,HEIGHT_WINDOW/2,3487290).setOrigin(0,.5),this.createNode(),this.createButton()}createNode(){let t=WIDTH_WINDOW/2,e=HEIGHT_WINDOW/2,i=WIDTH_WINDOW/4,s=HEIGHT_WINDOW/10,a={font:s.toString()+"px stencil",fill:"#e2e2e2"};this.add.text(t-i,e-s,"ATTACK",a).setOrigin(.5,.5),this.add.text(t,e-s,"MOVE",a).setOrigin(.5,.5),this.add.text(t+i,e-s,"CONDITION",a).setOrigin(.5,.5),this.add.sprite(t-i,e+s,"attack").setOrigin(.5,.5).setInteractive().on("pointerdown",()=>this.click("attack")),this.add.sprite(t,e+s,"move").setOrigin(.5,.5).setInteractive().on("pointerdown",()=>this.click("move")),this.add.sprite(t+i,e+s,"condition").setOrigin(.5,.5).setInteractive().on("pointerdown",()=>this.click("condition"))}click(t){switch(t.toString()){case"attack":this.game.scene.add("addNode",new AddAttack(this.game));break;case"move":this.game.scene.add("addNode",new AddMove(this.game));break;case"condition":this.game.scene.add("addNode",new AddCondition(this.game))}this.scene.launch("addNode"),this.scene.stop("PlusNode"),console.log(t.toString())}createButton(){let t=WIDTH_WINDOW/2,e=HEIGHT_WINDOW-100;this.cancelBtn=this.add.image(t,e,"cancel").setOrigin(.5,.5).setInteractive(),this.cancelBtn.on("pointerover",()=>this.cancelBtn.setFrame(1)),this.cancelBtn.on("pointerout",()=>this.cancelBtn.setFrame(0)),this.cancelBtn.on("pointerdown",()=>this.cancel())}cancel(){this.scene.resume("Game"),this.scene.stop("PlusNode")}}class RectangleNode{constructor(t,e,i,s,...a){switch(s.toString().toLowerCase()){case"attack":this.rect=new Phaser.GameObjects.Image(i,t,e,"attackN"),this.node=new Attack,this.canAddNode=!1,this.line=i.add.graphics();break;case"move":this.rect=new Phaser.GameObjects.Image(i,t,e,"moveN"),this.node=new Move(a[0]),this.canAddNode=!1,this.line=i.add.graphics(),!0===a[0]?this.rect.setFrame(0):this.rect.setFrame(2);break;case"condition":let h;this.rect=new Phaser.GameObjects.Image(i,t,e,"conditionN"),this.node=new Condition(a[0],a[1],a[2],a[3],a[4]),this.canAddNode=!0,this.lRect=[],this.scene=i,this.line=i.add.graphics(),h="myself"===a[0].name.toString().toLowerCase()?0:1;let n=0;!0===a[1]&&(n=Math.floor(3*a[3])),a[2],this.rect.setFrame(4*h+n);break;case"waria":this.rect=new Phaser.GameObjects.Image(i,t,e,"logoWaria").setInteractive(),this.canAddNode=!0,this.lRect=[],this.scene=i,this.scene.add.existing(this.rect);break;default:return void console.log("Création d'un node echoué")}s.toString().toLowerCase(),this.rect.on("pointerdown",()=>this.click()),this.rect.setOrigin(.5,0),this.rect.displayHeight=HEIGHT_WINDOW/6,this.rect.scaleX=this.rect.scaleY}getSelected(){if(this.rect.isTinted)return this;if(this.canAddNode)for(let t=0;tthis.addLine(t))}addLine(t){t.setLine(this.rect.x,this.rect.y+.9*this.rect.displayHeight)}getNodes(){if(void 0===this.node){let t=[];return this.lRect.forEach(function(e){void 0!==e.node&&(void 0!==e.lRect&&(e.node.clearNodes(),e.lRect.forEach(t=>e.node.addNode(t.node))),t.push(e.node))}),t}}destroy(){this.line.destroy(),this.rect.destroy(),void 0!==this.lRect&&this.lRect.forEach(t=>t.destroy())}delete(t){let e=this.lRect.indexOf(t);if(-1!==e)return this.lRect.splice(e,1),t.destroy(),!0;for(let e=0;e=0&&this.x>=this.target.x||this.velocityX<=0&&this.x<=this.target.x?this.setX(this.target.x):this.setX(this.x+this.velocityX),this.velocityY>=0&&this.y>=this.target.y||this.velocityY<=0&&this.y<=this.target.y?this.setY(this.target.y):this.setY(this.y+this.velocityY),!0)}fleeFromTarget(){return!!this.verifyTarget()&&(this.velocityX>=0&&this.x-this.width/2<=0?this.setX(this.width/2):this.velocityX<=0&&this.x+this.width/2>=WIDTH_MAP?this.setX(WIDTH_MAP-this.width/2):this.setX(this.x-this.velocityX),this.velocityY>=0&&this.y-this.width/2<=0?this.setY(this.height/2):this.velocityY<=0&&this.y+this.width/2>=WIDTH_MAP?this.setY(WIDTH_MAP-this.height/2):this.setY(this.y-this.velocityY),!0)}attackTarget(){return!!(this.verifyTarget()&&this.target.isAlive()&&this.isTargetInRange())&&(this.canAttack&&this.attack(this.target),!0)}verifyTarget(){return!!this.haveTarget()&&(!!this.target.isAlive()||(this.setTarget(null),!1))}attack(t){this.canAttack=!1,this.missile.setPosition(this.x,this.y).setVisible(!0),this.missile.setRotation(Math.atan2(this.y-this.target.y,this.x-this.target.x)-1.57),this.scene.tweens.add({targets:this.missile,x:t.x,y:t.y,ease:"Linear",duration:200,onComplete:()=>this.finishAttack(t)}),this.scene.time.addEvent({delay:Phaser.Math.Between(1e3,3e3),callback:this.reload,callbackScope:this})}finishAttack(t){t.beAttack(this.damage)&&this.setTarget(null),this.missile.setVisible(!1)}reload(){this.canAttack=!0}beAttack(t){let e=this.shield.decrease(t);return e>0&&(console.log("Shield Broken"),this.life.decrease(e)),this.die()}isTargetInRange(){return!!this.verifyTarget()&&this.calcDistance(this.target)0}die(){return 0===this.life.value&&(this.circle.destroy(),this.shield.destroy(),this.life.destroy(),!0)}haveTarget(){return null!=this.target}read(){for(let t=0;tt.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 fab8a46..0218759 100644 --- a/Code/src/js/Init.js +++ b/Code/src/js/Init.js @@ -4,6 +4,7 @@ EnemyBots.push(new Robot(1, 1)); console.log(myself.height); */ +const SHIELD_PER_SECOND = 5; const COLOR_ATTACK = 0xff0000; const COLOR_MOVE = 0x0000ff; const COLOR_CONDITION = 0x0e0e0e; diff --git a/Code/src/js/classes/AddAttack.js b/Code/src/js/classes/AddAttack.js new file mode 100644 index 0000000..72784a5 --- /dev/null +++ b/Code/src/js/classes/AddAttack.js @@ -0,0 +1,29 @@ +class AddAttack extends Phaser.Scene { + constructor(game) { + super('addNode'); + this.game = game; + } + + create() { + this.add.rectangle(0, 0, WIDTH_WINDOW, HEIGHT_WINDOW, 0x000000).setOrigin(0, 0).setAlpha(0.5); + console.log("ATTACK"); + this.createButton(); + } + + + + createButton() { + let x = WIDTH_WINDOW / 2; + let y = HEIGHT_WINDOW - 100; + this.cancelBtn = this.add.image(x, y, 'cancel').setOrigin(0.5, 0.5).setInteractive(); + this.cancelBtn.on('pointerover', () => this.cancelBtn.setFrame(1)); + this.cancelBtn.on('pointerout', () => this.cancelBtn.setFrame(0)); + this.cancelBtn.on('pointerdown', () => this.cancel()); + } + + cancel() { + this.scene.resume('Game'); + this.scene.stop('addNode'); + this.game.scene.remove('addNode'); + } +} \ No newline at end of file diff --git a/Code/src/js/classes/AddCondition.js b/Code/src/js/classes/AddCondition.js new file mode 100644 index 0000000..8017613 --- /dev/null +++ b/Code/src/js/classes/AddCondition.js @@ -0,0 +1,28 @@ +class AddCondition extends Phaser.Scene { + constructor(game) { + super('addNode'); + this.game = game; + } + + create() { + this.add.rectangle(0, 0, WIDTH_WINDOW, HEIGHT_WINDOW, 0x000000).setOrigin(0, 0).setAlpha(0.5); + console.log("CONDITION"); + this.createButton(); + } + + + createButton() { + let x = WIDTH_WINDOW / 2; + let y = HEIGHT_WINDOW - 100; + this.cancelBtn = this.add.image(x, y, 'cancel').setOrigin(0.5, 0.5).setInteractive(); + this.cancelBtn.on('pointerover', () => this.cancelBtn.setFrame(1)); + this.cancelBtn.on('pointerout', () => this.cancelBtn.setFrame(0)); + this.cancelBtn.on('pointerdown', () => this.cancel()); + } + + cancel() { + this.scene.resume('Game'); + this.scene.stop('addNode'); + this.game.scene.remove('addNode'); + } +} \ No newline at end of file diff --git a/Code/src/js/classes/AddMove.js b/Code/src/js/classes/AddMove.js new file mode 100644 index 0000000..0995b5c --- /dev/null +++ b/Code/src/js/classes/AddMove.js @@ -0,0 +1,29 @@ +class AddMove extends Phaser.Scene { + constructor(game) { + super('addNode'); + this.game = game; + } + + create() { + this.add.rectangle(0, 0, WIDTH_WINDOW, HEIGHT_WINDOW, 0x000000).setOrigin(0, 0).setAlpha(0.5); + console.log("MOVE"); + this.createButton(); + } + + + + createButton() { + let x = WIDTH_WINDOW / 2; + let y = HEIGHT_WINDOW - 100; + this.cancelBtn = this.add.image(x, y, 'cancel').setOrigin(0.5, 0.5).setInteractive(); + this.cancelBtn.on('pointerover', () => this.cancelBtn.setFrame(1)); + this.cancelBtn.on('pointerout', () => this.cancelBtn.setFrame(0)); + this.cancelBtn.on('pointerdown', () => this.cancel()); + } + + cancel() { + this.scene.resume('Game'); + this.scene.stop('addNode'); + this.game.scene.remove('addNode'); + } +} \ No newline at end of file diff --git a/Code/src/js/classes/Game.js b/Code/src/js/classes/Game.js index d520c6f..93ebde2 100644 --- a/Code/src/js/classes/Game.js +++ b/Code/src/js/classes/Game.js @@ -8,7 +8,7 @@ class Game extends Phaser.Scene { this.gm = new GamingBoard(); this.game.scene.add('GamingBoard', this.gm); - this.game.scene.add('PlusNode', new PlusNode()); + this.game.scene.add('PlusNode', new PlusNode(this.game)); } create() { diff --git a/Code/src/js/classes/GamingBoard.js b/Code/src/js/classes/GamingBoard.js index 0635249..afe6419 100644 --- a/Code/src/js/classes/GamingBoard.js +++ b/Code/src/js/classes/GamingBoard.js @@ -15,7 +15,11 @@ class GamingBoard extends Phaser.Scene { this.chooseTarget(this.listRobot[i]); } + this.listRobot[0].drawRange(); + this.events.on('resume', () => this.resume()); + + this.time.addEvent({delay: 2000, callback: this.upShield, callbackScope: this}); } update(time, delta) { @@ -42,7 +46,7 @@ class GamingBoard extends Phaser.Scene { resume() { } - addRobot(robot){ + addRobot(robot) { this.listRobot.push(robot); } @@ -74,4 +78,9 @@ class GamingBoard extends Phaser.Scene { } + upShield() { + this.listRobot.forEach(robot => robot.addShield(SHIELD_PER_SECOND)); + this.time.addEvent({delay: 1000, callback: this.upShield, callbackScope: this}); + } + } \ No newline at end of file diff --git a/Code/src/js/classes/HealthBar.js b/Code/src/js/classes/HealthBar.js index 9c6a6b1..7fda8ce 100644 --- a/Code/src/js/classes/HealthBar.js +++ b/Code/src/js/classes/HealthBar.js @@ -29,6 +29,14 @@ class HealthBar { return diff; } + increase(amount) { + this.value += amount; + if (this.value > this.valueMax) { + this.value = this.valueMax; + } + this.draw(); + } + setX(x) { this.bar.setX(x - this.width / 2); } @@ -51,7 +59,7 @@ class HealthBar { let percent = this.value / this.valueMax; - if (percent < 0.3) { + if (percent < 1 / 3) { this.bar.fillStyle(0xff0000); } else { this.bar.fillStyle(this.color); diff --git a/Code/src/js/classes/PlusNode.js b/Code/src/js/classes/PlusNode.js index 820e425..765cdf5 100644 --- a/Code/src/js/classes/PlusNode.js +++ b/Code/src/js/classes/PlusNode.js @@ -1,6 +1,7 @@ class PlusNode extends Phaser.Scene { - constructor() { + constructor(game) { super('PlusNode'); + this.game = game; } create() { @@ -36,16 +37,17 @@ class PlusNode extends Phaser.Scene { click(action) { switch (action.toString()) { case 'attack': - + this.game.scene.add('addNode', new AddAttack(this.game)) break; case 'move': - + this.game.scene.add('addNode', new AddMove(this.game)) break; - case 'condition': - + this.game.scene.add('addNode', new AddCondition(this.game)) break; } + this.scene.launch('addNode'); + this.scene.stop('PlusNode'); console.log(action.toString()); } diff --git a/Code/src/js/classes/Robot.js b/Code/src/js/classes/Robot.js index 789368f..0d3b893 100644 --- a/Code/src/js/classes/Robot.js +++ b/Code/src/js/classes/Robot.js @@ -10,6 +10,7 @@ class Robot { this.damage = DAMAGE; this.life = new HealthBar(scene, this.width * 2, this.width / 3, this.x, this.y - this.width, LIFE, 0x008000); this.shield = new HealthBar(scene, this.width * 2, this.width / 3, this.x, this.y - this.width * 1.5, SHIELD, 0x0000FF); + this.circleRange = null; this.canAttack = true; this.missile = new Missile(scene, 'bullet', this.width / 5, this.width / 4); @@ -31,11 +32,16 @@ class Robot { this.circle = this.scene.add.circle(this.x, this.y, this.width / 2, this.color); } + addShield(shield) { + this.shield.increase(shield); + } + setX(x) { this.x = x; this.circle.setX(this.x); this.life.setX(this.x); this.shield.setX(this.x); + this.drawCircleRange(); } setY(y) { @@ -43,6 +49,7 @@ class Robot { this.life.setY(this.y - this.width); this.shield.setY(this.y - this.width * 1.5); this.circle.setY(this.y); + this.drawCircleRange(); } setTarget(target) { @@ -200,6 +207,27 @@ class Robot { this.lNode.push(node); } + drawRange() { + this.circleRange = this.scene.add.graphics(); + + this.drawCircleRange(); + } + + drawCircleRange() { + if (this.circleRange !== null) { + this.circleRange.clear(); + let color = 0xffff00; + let thickness = 4; + let alpha = 1; + + this.circleRange.lineStyle(thickness, color, alpha); + let a = new Phaser.Geom.Point(this.x, this.y); + let radius = this.range; + + this.circleRange.strokeCircle(a.x, a.y, radius); + } + } + cleanNodes() { this.lNode = []; }