From 312342600702a8e3b6cf610c5ad30ee64656d88f Mon Sep 17 00:00:00 2001 From: clmaisonha Date: Fri, 10 Jul 2020 20:26:11 +0200 Subject: [PATCH] =?UTF-8?q?Cr=C3=A9ation=20du=20chargement=20en=20json=20d?= =?UTF-8?q?es=20robots=20-=20Cr=C3=A9ation=20du=20chargement=20en=20json?= =?UTF-8?q?=20des=20bonus=20-=20Ajout=20d'une=20page=20de=20chargement=20l?= =?UTF-8?q?e=20temps=20que=20le=20niveau=20se=20charge=20-=20Les=205=20mod?= =?UTF-8?q?es=20de=20jeux=20ont=20maintenant=20un=20dispositif=20de=20robo?= =?UTF-8?q?t=20et=20de=20bonus=20qui=20leur=20est=20propre=20-=20Modificat?= =?UTF-8?q?ion=20du=20constructor=20de=20Robot=20pour=20pouvoir=20passer?= =?UTF-8?q?=20en=20param=C3=A8tre=20la=20vitesse,=20vitesse=20de=20recharg?= =?UTF-8?q?ement=20...=20et=20les=20actions=20qui=20lui=20sont=20associ?= =?UTF-8?q?=C3=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Code/public/js/level2.min.js | 2 +- Code/public/json/level1.json | 2 +- Code/public/json/level2.json | 2 +- Code/public/json/level3.json | 2 +- Code/public/json/level4.json | 2 +- Code/public/json/level5.json | 2 +- Code/src/js/level2/BonusSpeed.js | 2 +- Code/src/js/level2/Game.js | 105 ++++++++++++++++++++------- Code/src/js/level2/GamingBoard.js | 6 +- Code/src/js/level2/Robot.js | 17 +++-- Code/src/js/level2/Variable.js | 3 +- Code/src/json/level1.json | 111 +++++++++++++++++++++++++++- Code/src/json/level2.json | 110 +++++++++++++++++++++++++++- Code/src/json/level3.json | 110 +++++++++++++++++++++++++++- Code/src/json/level4.json | 117 +++++++++++++++++++++++++++++- Code/src/json/level5.json | 99 ++++++++++++++++++++++++- 16 files changed, 640 insertions(+), 52 deletions(-) diff --git a/Code/public/js/level2.min.js b/Code/public/js/level2.min.js index 34a9e7f..860878c 100644 --- a/Code/public/js/level2.min.js +++ b/Code/public/js/level2.min.js @@ -1 +1 @@ -class AddAttack extends AddNode{constructor(e,t,s,...i){super(e,t,s,i)}create(){console.log("ATTACK"),super.create(),super.addTitle(WIDTH_WINDOW/2,HEIGHT_WINDOW/16,selectWord("ADD NODE : ATTACK","AJOUTER ACTION : ATTAQUE")),super.addTitle(WIDTH_WINDOW/2,HEIGHT_WINDOW/(16/3),selectWord("WHO ?","QUI ?")),super.addTitle(WIDTH_WINDOW/2,HEIGHT_WINDOW/(16/7),selectWord("TARGET FILTERS (OPTIONAL)","FILTRES CIBLES (FACULTATIF)")),super.addButton(WIDTH_WINDOW/2,HEIGHT_WINDOW/3.2,"enemyBot",super.newCategory("target",!0,!0),!1);let e=super.newCategory("range",!0,!0);super.addButton(WIDTH_WINDOW/3,HEIGHT_WINDOW/(16/9),"shortRange",e,1/3),super.addButton(WIDTH_WINDOW/1.5,HEIGHT_WINDOW/(16/9),"mediumRange",e,2/3),super.addButton(WIDTH_WINDOW/2,HEIGHT_WINDOW/(16/12),"longRange",e,1)}addNode(){super.verifyCategory()&&(this.selected.addRect(new RectangleNode(this.selected.getX(),this.selected.getY()+200,this.gameR,"attack",[this.lCategory[1].getValue()])),super.cancel())}modifyNode(){super.verifyCategory()&&(this.selected.node.percentRange=this.lCategory[1].getValue(),this.selected.rect.setFrame(this.selected.node.getFrame()),super.cancel())}}class AddCondition extends AddNode{constructor(e,t,s,...i){super(e,t,s,i)}create(){super.create(),console.log("CONDITION"),super.addTitle(WIDTH_WINDOW/2,HEIGHT_WINDOW/16,selectWord("ADD NODE : CONDITION","AJOUTER ACTION : CONDITION")),super.addTitle(WIDTH_WINDOW/2,HEIGHT_WINDOW/(16/3),selectWord("WHO ?","QUI ?")),super.addTitle(WIDTH_WINDOW/2,HEIGHT_WINDOW/(16/7),selectWord("TARGET FILTERS (OPTIONAL)","FILTRES CIBLES (FACULTATIF)"));let e=super.newCategory("target",!0,!0);super.addButton(WIDTH_WINDOW/3,HEIGHT_WINDOW/3.2,"enemyBot",e,!1),super.addButton(WIDTH_WINDOW/1.5,HEIGHT_WINDOW/3.2,"myself",e,!0);let t=super.newCategory("shield",!0,!0);super.addButton(WIDTH_WINDOW/8,HEIGHT_WINDOW/(16/9),"shortRange",t,[1/3,"range"]),super.addButton(WIDTH_WINDOW/4*1.5,HEIGHT_WINDOW/(16/9),"mediumRange",t,[2/3,"range"]),super.addButton(WIDTH_WINDOW/4,HEIGHT_WINDOW/(16/12),"longRange",t,[1,"range"]);let s=this.add.graphics();s.lineStyle(10,16777215,1),s.lineBetween(WIDTH_WINDOW/2,HEIGHT_WINDOW/2,WIDTH_WINDOW/2,HEIGHT_WINDOW/(16/13)),super.addButton(WIDTH_WINDOW/8*5,HEIGHT_WINDOW/(16/9),"shield0",t,[0,"shield"]),super.addButton(WIDTH_WINDOW/8*7,HEIGHT_WINDOW/(16/9),"shield33",t,[1/3,"shield"]),super.addButton(WIDTH_WINDOW/8*5,HEIGHT_WINDOW/(16/12),"shield66",t,[2/3,"shield"]),super.addButton(WIDTH_WINDOW/8*7,HEIGHT_WINDOW/(16/12),"shield100",t,[1,"shield"])}addNode(){super.verifyCategory()&&("range"===this.lCategory[1].getValue()[1]?this.selected.addRect(new RectangleNode(this.selected.getX(),this.selected.getY()+200,this.gameR,"condition",[this.lCategory[0].getValue(),!1,!0,0,this.lCategory[1].getValue()[0]])):this.selected.addRect(new RectangleNode(this.selected.getX(),this.selected.getY()+200,this.gameR,"condition",[this.lCategory[0].getValue(),!0,!1,this.lCategory[1].getValue()[0],0])),super.cancel())}modifyNode(){super.verifyCategory()&&(this.selected.node.shieldFilter=!1,this.selected.node.rangeFilter=!1,"range"===this.lCategory[1].getValue()[1]?(this.selected.node.rangeFilter=!0,this.selected.node.range=this.lCategory[1].getValue()[0]):(this.selected.node.shieldFilter=!0,this.selected.node.shield=this.lCategory[1].getValue()[0]),this.selected.node.myself=this.lCategory[0].getValue(),this.selected.rect.setFrame(this.selected.node.getFrame()),super.cancel())}}class AddMove extends AddNode{constructor(e,t,s,...i){super(e,t,s,i)}create(){console.log("MOVE"),super.create(),super.addTitle(WIDTH_WINDOW/2,HEIGHT_WINDOW/16,selectWord("ADD NODE : MOVE","AJOUTER ACTION : DEPLACEMENT")),super.addTitle(WIDTH_WINDOW/4,HEIGHT_WINDOW/(16/3),selectWord("FLEE OR MOVE ?","RECULER OU AVANCER ?"));let e=super.newCategory("direction",!0,!0);super.addButton(WIDTH_WINDOW/6,HEIGHT_WINDOW/3.2,"fleeFrom",e,!1),super.addButton(WIDTH_WINDOW/3,HEIGHT_WINDOW/3.2,"moveToward",e,!0),super.addTitle(WIDTH_WINDOW/4*3,HEIGHT_WINDOW/(16/3),selectWord("WHO ?","QUI ?"));let t=super.newCategory("target",!0,!0);super.addButton(WIDTH_WINDOW/6*4,HEIGHT_WINDOW/3.2,"enemyBot",t,!0),super.addButton(WIDTH_WINDOW/6*5,HEIGHT_WINDOW/3.2,"bonus",t,!1)}addNode(){super.verifyCategory()&&(this.selected.addRect(new RectangleNode(this.selected.getX(),this.selected.getY()+200,this.gameR,"move",[this.lCategory[0].getValue(),this.lCategory[1].getValue()])),super.cancel())}modifyNode(){super.verifyCategory()&&(this.selected.node.toward=this.lCategory[0].getValue(),this.selected.node.enemyBot=this.lCategory[1].getValue(),this.selected.rect.setFrame(this.selected.node.getFrame()),super.cancel())}}class Attack{constructor(e=1){e>1/3?e>2/3?(e=1,this.percentBonus=1):(e=2/3,this.percentBonus=1.5):(e=1/3,this.percentBonus=2),this.percentRange=e}do(e){return!(!e.haveTarget()||!e.isTargetInRange(this.percentRange))&&e.attackTarget(this.percentBonus)}getFrame(){return 3*this.percentRange-1}getOptionJson(){return this.percentRange}}class Bar extends HealthBar{constructor(e,t="",s,i,h,a,n,r=new CategoryBar,o=1,d){super(e,t,s,i,h,a,void 0!==d?d:r.valueMax,n,n,!1),this.name=t,this.scene=e,this.scene.input.on("pointerdown",this.doDrag,this);let l={font:i.toString()+"px stencil",fill:"#e2e2e2"};this.text=this.scene.add.text(this.bar.x+this.width+10,this.bar.y,this.value.toString(),l).setOrigin(0,0),this.categoryBar=r,this.setValue(0),this.categoryBar.setValueOf(this,o)}doDrag(){let e=this.scene.input;e.x>=this.bar.x-10&&e.x<=this.bar.x+this.width+10&&e.y>=this.bar.y&&e.y<=this.bar.y+this.height&&(this.scene.pauseScene(),this.clickOn())}clickOn(){this.onMove(),this.scene.input.on("pointermove",()=>this.onMove()),this.scene.input.on("pointerup",()=>this.stopClick())}stopClick(){this.scene.input.off("pointermove"),this.scene.input.off("pointerup")}onMove(){this.setValWithX(this.scene.input.x)}setValWithX(e){this.categoryBar.setValueOf(this,Math.round((e-this.bar.x)/this.width*this.valueMax))}draw(){super.draw();let e=this.value/this.valueMax*this.width-5;this.bar.fillStyle(9868950),this.bar.fillRect(e,0,10,this.height),void 0!==this.text&&this.text.setText(this.value+1)}}class BonusAttack extends Bonus{constructor(e,t,s,i,h){super(e,t,s,i,"bonusAttack",h)}useOn(e){let t=e.speed;e.setSpeed(t+this.value),this.scene.time.addEvent({delay:this.time,callback:e.setSpeed(t)}),this.destroy()}}class BonusShield extends Bonus{constructor(e,t,s,i,h){super(e,t,s,i,"bonusShield",h)}useOn(e){e.shield.valueMax=e.shield.valueMax+this.value,e.shield.value=e.shield.value+this.val,this.destroy()}}class BonusSpeed extends Bonus{constructor(e,t,s,i,h,a){let n;switch(h){case 1:n="bonusSpeed0";break;case 2:n="bonusSpeed1";break;case 3:default:n="bonusSpeed2"}super(e,t,s,i,n,h),this.time=a}useOn(e){e.increaseSpeedBonus(this.value),this.scene.time.addEvent({delay:this.time,callback:()=>e.decreaseSpeedBonus(this.value)}),this.destroy()}}class Boot extends ManageLang{constructor(e){super("Boot",e)}create(){super.create();this.add.text(WIDTH_WINDOW/2,HEIGHT_WINDOW/3,"WARIA",{font:"200px stencil",fill:"#e2e2e2"}).setOrigin(.5,.5);let e=this.add.sprite(WIDTH_WINDOW/2,HEIGHT_WINDOW/3*2,"playLetter").setInteractive();e.on("pointerout",()=>e.setFrame(0)),e.on("pointerover",()=>e.setFrame(1)),e.on("pointerdown",()=>this.clickPlay(e))}clickPlay(e){console.log("Play"),this.father.scene.add("Type",new Type(this.father)),this.scene.start("Type")}}class Category{constructor(e="undefined",t=!0,s=!0){this.name=e,this.single=t,this.lBtn=[],this.lValue=[],this.obligatory=s}add(e,t){0!==this.lBtn.length&&this.single&&(this.lBtn[0].clearTint(),this.lValue=[],this.lBtn=[]),this.lValue.push(t),this.lBtn.push(e),e.tint=15718407}getValue(){return this.single?this.lValue[0]:this.lValue}validate(){return!(0===this.lBtn.length&&this.obligatory)}remove(e){let t=this.lBtn.indexOf(e);-1!==t&&(this.lBtn.splice(t,1),this.lValue.splice(t,1)),e.clearTint()}}class CategoryBar{constructor(e=VALUE_MAX_BAR,t=1){this.startValue=t,this.valueMax=e,this.point=this.valueMax}addPoint(e){if(this.point+=e,this.point<0){let e=this.point;return this.point=0,e}return this.point>this.valueMax&&(this.point=this.valueMax),0}setValueOf(e,t){let s=t-e.value,i=e.value;this.point>=s?e.setValue(t):e.setValue(e.value+this.point),this.addPoint(i-e.value),this.draw()}addText(e,t,s,i,h){this.text=t;let a={font:h.toString()+"px stencil",fill:"#e2e2e2"};this.textScene=e.add.text(s,i,this.text,a).setOrigin(0,0),this.draw()}setTextPos(e,t){this.textScene.setX(e),this.textScene.setY(t)}setText(e){this.text=e,this.draw()}draw(){this.textScene.setText(this.text+this.point)}}class Condition{constructor(e,t=!1,s=!1,i,h){this.shieldFilter=t,this.rangeFilter=s,this.shield=i,this.range=h,this.myself=e,this.lNode=[]}addNode(e){this.lNode.push(e)}do(e){if(this.doCondition(e))for(let t=0;t=h&&(s>h&&(s=h,i=[]),i.push(t))}}),i.length>1?i[Math.floor(Math.random()*(i.length+1))]:i[0]}function toJson(e,t,s=!1){let i;switch(typeof t){case"string":i='"'+e.toString()+'":"'+t+'"';break;default:i='"'+e.toString()+'":'+t}return s||(i+=","),i}function endLineJson(e){return e.length>0&&","===e[e.length-1]&&(e=e.substr(0,e.length-1)),e}var tree=void 0;class Game extends ManageLang{constructor(e,t="level1"){super("Game",e),super.addOtherScenes("GamingBoard"),SPEED_GAME=1,this.level=t}preload(){this.cache.json.exists("level")&&this.cache.json.remove("level"),this.load.json("level","public/json/"+this.level+".json")}create(){if(super.create(),void 0!==this.tree&&void 0!==this.initStat){let e=this.tree.getJson(!0);console.log(e),e=JSON.parse(e);let t=this.initStat.getJson(!0);t=JSON.parse(t),this.loadSave(e,t)}else{let e=this.cache.json.get("level");void 0!==e&&this.loadSave(e.tree,e.initStat)}this.doLine=!1,this.gm=new GamingBoard(this),-1!==this.father.scene.getIndex("GamingBoard")&&this.father.scene.remove("GamingBoard"),this.father.scene.add("GamingBoard",this.gm),this.scene.launch("GamingBoard"),this.scene.pause("GamingBoard"),this.selected=null;this.createButton();this.gm.addRobot(new Robot(.1*WIDTH_MAP,.1*WIDTH_MAP,.9*WIDTH_MAP,.9*WIDTH_MAP,this.gm,MYSELF)),this.gm.addRobot(new Robot(.1*WIDTH_MAP,.1*WIDTH_MAP,.2*WIDTH_MAP,.1*WIDTH_MAP,this.gm)),this.gm.addRobot(new Robot(.1*WIDTH_MAP,.1*WIDTH_MAP,.1*WIDTH_MAP,.9*WIDTH_MAP,this.gm)),this.input.keyboard.on("keydown-DELETE",()=>{this.clickBin()}),this.input.keyboard.on("keydown-E",()=>{this.clickPencil()}),this.input.keyboard.on("keydown-ENTER",()=>{this.clickPlus()})}update(e,t){super.update(e,t),this.doLine&&this.tree.updateLine()}loadSave(e,t){this.initStat=this.loadInitSave(t),this.tree=this.loadTree(e)}loadTree(e,t=CENTERX_TREE,s=OFFY_TREE/2){if(void 0!==e.x&&void 0!==e.y){let t=new RectangleNode(e.x,e.y,this,e.type,e.option);return void 0!==e.lRect&&e.lRect.length>0&&e.lRect.forEach(e=>t.addRect(this.loadTree(e))),t}{let i=new RectangleNode(t,s,this,e.type,e.option);if(void 0!==e.lRect&&e.lRect.length>0){let h=e.lRect.length,a=t-OFFX_TREE/2*(h-1),n=s+OFFY_TREE;e.lRect.forEach(e=>{i.addRect(this.loadTree(e,a,n)),a+=OFFX_TREE})}return i}}loadInitSave(e){let t=new InitStat(this,OFFX_MAP+WIDTH_MAP+5,OFFY_MAP,200,30,10);for(let s=0;se.getX()-t.getX()),this.gm.modifyNodes(this.tree.getNode()),this.gm.modifyValue(this.initStat.lBar[0].value,this.initStat.lBar[1].value,this.initStat.lBar[2].value,this.initStat.lBar[3].value),this.gm.resume()}changeFrame(e,t=0,s=0){e.setFrame(t+2*s)}createButton(){let e=WIDTH_MAP+OFFX_MAP,t=WIDTH_MAP+OFFY_MAP+5,s=OFFY_MAP/1.5,i=1.1*s,h=this.add.sprite(10,10,"back").setOrigin(0,0).setInteractive();this.play=this.add.sprite(e,t,"play").setOrigin(1,0).setInteractive();let a=this.add.sprite(e-i,t,"speed").setOrigin(1,0).setInteractive(),n=this.add.sprite(WIDTH_WINDOW,t,"save").setOrigin(1,0).setInteractive();this.pencil=this.add.sprite(e-2*i,t,"pencil").setOrigin(1,0).setInteractive().setVisible(!1),this.bin=this.add.sprite(e-3*i,t,"bin").setOrigin(1,0).setInteractive().setVisible(!1),this.plus=this.add.sprite(e-4*i,t,"plus").setOrigin(1,0).setInteractive().setVisible(!1);let r=this.add.sprite(e-5*i,t,"mute").setOrigin(1,0).setInteractive();this.linePlay=0,this.lineSpeed=1===SPEED_GAME?0:1,this.changeFrame(a,0,this.lineSpeed),this.father.sound.mute?this.lineMute=1:this.lineMute=0,this.changeFrame(r,0,this.lineMute),h.displayHeight=h.displayWidth=s,n.displayHeight=n.displayWidth=s,this.play.displayHeight=this.play.displayWidth=s,a.displayHeight=a.displayWidth=s,r.displayHeight=r.displayWidth=s,this.pencil.displayHeight=this.pencil.displayWidth=s,this.bin.displayHeight=this.bin.displayWidth=s,this.plus.displayHeight=this.plus.displayWidth=s,this.play.on("pointerout",()=>this.changeFrame(this.play,0,this.linePlay)),this.play.on("pointerover",()=>this.changeFrame(this.play,1,this.linePlay)),a.on("pointerout",()=>this.changeFrame(a,0,this.lineSpeed)),a.on("pointerover",()=>this.changeFrame(a,1,this.lineSpeed)),r.on("pointerout",()=>this.changeFrame(r,0,this.lineMute)),r.on("pointerover",()=>this.changeFrame(r,1,this.lineMute)),this.creatBtnOutAndOver(n),this.creatBtnOutAndOver(h),this.creatBtnOutAndOver(this.pencil),this.creatBtnOutAndOver(this.bin),this.creatBtnOutAndOver(this.plus),this.play.on("pointerdown",()=>this.clickPlay()),a.on("pointerdown",()=>this.clickSpeed(a)),h.on("pointerdown",()=>this.clickBack()),r.on("pointerdown",()=>this.clickMute(r)),n.on("pointerdown",()=>this.clickSave()),this.pencil.on("pointerdown",()=>this.clickPencil()),this.bin.on("pointerdown",()=>this.clickBin()),this.plus.on("pointerdown",()=>this.clickPlus()),this.input.on("pointerdown",()=>this.clickNode()),this.input.on("drag",this.doDrag),this.input.on("dragstart",()=>this.dragStart()),this.input.on("dragend",()=>this.dragEnd())}creatBtnOutAndOver(e){e.on("pointerout",()=>this.changeFrame(e,0)),e.on("pointerover",()=>this.changeFrame(e,1))}clickSave(){this.tree.sort((e,t)=>e.getX()-t.getX());let e='{"tree":'+this.tree.getJson()+',"initStat":'+this.initStat.getJson()+"}";console.log(e)}clickPlay(){this.scene.isPaused("GamingBoard")?this.resume():this.pauseScene(),this.changeFrame(this.play,1,this.linePlay)}clickSpeed(e){1===SPEED_GAME?(SPEED_GAME=2,this.lineSpeed=1):(SPEED_GAME=1,this.lineSpeed=0),this.changeFrame(e,1,this.lineSpeed)}clickPencil(){if(null!==this.selected){switch(console.log("PENCIL"),this.changeFrame(this.pencil,0),this.selected.type){case"attack":this.father.scene.add("AddNode",new AddAttack(this.father,this,this.selected,!1,this.selected.node.percentRange));break;case"move":this.father.scene.add("AddNode",new AddMove(this.father,this,this.selected,this.selected.node.toward,this.selected.node.enemyBot));break;case"condition":this.selected.node.shieldFilter?this.father.scene.add("AddNode",new AddCondition(this.father,this,this.selected,this.selected.node.myself,[this.selected.node.shield,"shield"])):this.father.scene.add("AddNode",new AddCondition(this.father,this,this.selected,this.selected.node.myself,[this.selected.node.range,"range"]));break;default:return}this.scene.pause("Game"),this.scene.launch("AddNode")}}clickBin(){null!==this.selected&&(console.log("BIN"),this.tree.delete(this.selected),this.changeFrame(this.bin,0),this.tryClick())}clickPlus(){null!==this.selected&&this.selected.canAddNode&&(console.log("PLUS"),this.father.scene.add("PlusNode",new PlusNode(this.father,this,this.selected)),this.scene.launch("PlusNode"),this.changeFrame(this.plus,0),this.scene.pause("Game"))}clickBack(){console.log("BACK"),this.father.scene.stop("GamingBoard"),this.father.scene.remove("GamingBoard"),this.father.scene.stop("Game"),this.father.scene.start("Type")}clickMute(e){console.log("MUTE"),this.father.sound.mute?(this.father.sound.mute=!1,this.lineMute=0):(this.father.sound.mute=!0,this.lineMute=1),this.changeFrame(e,1,this.lineMute)}tryClick(){this.pencil.setVisible(!1),this.bin.setVisible(!1),this.plus.setVisible(!1),null!=this.selected&&(this.selected.deselect(),this.selected=null)}}class GamingBoard extends Phaser.Scene{constructor(e){super("GamingBoard"),this.listRobot=[],listBonus=[],this.father=e,this.end=!1}preload(){this.cameras.main.setViewport(OFFX_MAP,OFFY_MAP,WIDTH_MAP,WIDTH_MAP),this.sound.add("shot"),this.sound.add("hit")}create(){listBonus.push(new BonusSpeed("Fusée",this,WIDTH_MAP/2,WIDTH_MAP/2,5,2e3)),this.add.image(0,0,"background").alpha=.1;for(let e=0;et.addNode(e)),!0)}modifyValue(e,t,s,i){let h=this.getMyRobot();return void 0!==h&&(h.setSpeed(s),h.setRange(i),h.setSpeedReload(t),h.setDamage(e),!0)}getMyRobot(){for(let e=0;ee.addShield(SHIELD_PER_SECOND)),this.time.addEvent({delay:1e3/SPEED_GAME,callback:this.upShield,callbackScope:this})}}class InitStat{constructor(e,t,s,i,h,a){this.scene=e,this.posX=t,this.posY=s,this.width=i,this.height=h,this.category=new CategoryBar(a),this.lBar=[],this.lText=[],this.category.addText(this.scene,selectWord("TOKENS : ","JETONS : "),this.posX,this.posY,this.height)}addBar(e,t,s,i){this.lText.push(i),this.lBar.push(new Bar(this.scene,selectWord(i[0],i[1]),this.width,this.height,this.posX,this.posY,s,this.category,e,t)),this.posY+=1.5*this.height,this.category.setTextPos(this.posX,this.posY)}getJson(){let e="{";return e+='"lBar":[',this.lBar.forEach(t=>e+=t.getJson()+","),e=endLineJson(e)+"],",e+='"lText":[',this.lText.forEach(t=>{e+="[",t.forEach(t=>{e+='"'+t+'",'}),e=endLineJson(e),e+="],"}),e=endLineJson(e),e+="]",e+="}"}}class LoadFile extends Phaser.Scene{constructor(e,t,s){super("LoadFile"),this.father=e,this.son=s,this.nameSon=t,this.father.scene.pause(this.nameSon),this.father.scene.stop(this.nameSon),this.father.scene.remove("LoadFile")}preload(){let e=this.add.graphics(),t=this.add.graphics(),s=WIDTH_WINDOW/2-160,i=HEIGHT_WINDOW/2-25;t.fillStyle(2236962,.8),t.fillRect(s,i,320,50),this.load.on("progress",function(t){e.clear(),e.fillStyle(16777215,1),e.fillRect(s+10,i+10,300*t,30)}),this.load.on("complete",()=>{e.destroy(),t.destroy(),-1===this.father.scene.getIndex(this.nameSon)&&this.father.scene.add(this.nameSon,this.son),this.father.scene.start(this.nameSon)}),this.load.audio("shot","assets/sounds/shot.ogg"),this.load.audio("hit","assets/sounds/hit.ogg"),this.loadImage("en","flags/",!0),this.loadImage("fr","flags/",!0),this.loadImage("bonusSpeed0","bonus/",!0),this.loadImage("bonusSpeed1","bonus/",!0),this.loadImage("bonusSpeed2","bonus/",!0),this.loadImage("enemy","robots/"),this.loadSprite("playLetter",550,150,"buttons/"),this.loadSprite("cancel",550,150,"buttons/"),this.loadSprite("add",550,150,"buttons/"),this.loadSprite("modify",550,150,"buttons/"),this.loadSprite("home",550,150,"buttons/"),this.loadSprite("next",550,150,"buttons/"),this.loadSprite("retry",550,150,"buttons/"),this.loadSprite("duel",269,262,"buttons/"),this.loadSprite("last",269,262,"buttons/"),this.loadSprite("team",269,262,"buttons/"),this.loadSprite("flag",269,262,"buttons/"),this.loadSprite("map",269,262,"buttons/"),this.loadSprite("play",100,100,"buttons/"),this.loadSprite("bin",100,100,"buttons/"),this.loadSprite("plus",100,100,"buttons/"),this.loadSprite("pencil",100,100,"buttons/"),this.loadSprite("speed",100,100,"buttons/"),this.loadSprite("mute",100,100,"buttons/"),this.loadSprite("save",100,100,"buttons/"),this.loadSprite("back",200,200,"buttons/"),this.loadSprite("shortRange",300,150,"buttons/"),this.loadSprite("mediumRange",300,150,"buttons/"),this.loadSprite("longRange",300,150,"buttons/"),this.loadSprite("shield0",300,150,"buttons/"),this.loadSprite("shield33",300,150,"buttons/"),this.loadSprite("shield66",300,150,"buttons/"),this.loadSprite("shield100",300,150,"buttons/"),this.loadSprite("myself",300,150,"buttons/"),this.loadSprite("enemyBot",300,150,"buttons/"),this.loadSprite("bonus",300,150,"buttons/"),this.loadSprite("moveToward",300,150,"buttons/"),this.loadSprite("fleeFrom",300,150,"buttons/"),this.loadSprite("attackNode",180,190,"nodes/",!0),this.loadSprite("moveNode",180,190,"nodes/",!0),this.loadSprite("conditionNode",180,190,"nodes/",!0),this.loadImage("background"),this.loadImage("bullet"),this.loadImage("logoWaria"),this.loadImage("attack","nodes/",!0),this.loadImage("move","nodes/",!0),this.loadImage("condition","nodes/",!0)}loadSprite(e,t,s,i="",h=!1){this.deleteLoad(e),h?this.load.spritesheet(e,"assets/"+i+e+".png",{frameWidth:t,frameHeight:s}):this.load.spritesheet(e,"assets/"+LANG+"/"+i+e+".png",{frameWidth:t,frameHeight:s})}loadImage(e,t="",s=!1){this.deleteLoad(e),s?this.load.image(e,"assets/"+t+e+".png"):this.load.image(e,"assets/"+LANG+"/"+t+e+".png")}deleteLoad(e){this.textures.exists(e)&&this.textures.remove(e)}}class Looser extends Finish{constructor(e,t){super(e,t)}create(){super.create(),super.addTitle(selectWord("GAME OVER","PARTIE PERDUE")),super.btnRetry(super.createButton(WIDTH_WINDOW/3,"retry")),super.btnHome(super.createButton(WIDTH_WINDOW/1.5,"home"))}}class Missile extends Phaser.GameObjects.Image{constructor(e,t,s,i){super(e,0,0,t),this.visible=!1,this.setOrigin(.5,.5),this.setScale(.02)}}class Move{constructor(e,t=!0){this.toward=e,this.enemyBot=t}do(e){if(this.enemyBot){if(e.verifyTarget())return!0===this.toward?this.moveToward(e):this.fleeFrom(e)}else{let t=chooseTarget(e,listBonus);if(void 0!==t){let s;return(s=!0===this.toward?this.moveToward(e,t):this.fleeFrom(e,t))||(t.useOn(e),listBonus.splice(listBonus.indexOf(t),1)),!0}}return!1}moveToward(e,t=e.target){return e.advanceTo(t)}fleeFrom(e,t=e.target){return e.fleeFrom(t)}getFrame(){let e;return e=this.toward?0:2,this.enemyBot||(e+=1),e}getOptionJson(){return this.toward+","+this.enemyBot}}class PlusNode extends Phaser.Scene{constructor(e,t,s){super("PlusNode"),this.father=e,this.gameR=t,this.selected=s}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 e=WIDTH_WINDOW/2,t=HEIGHT_WINDOW/2,s=WIDTH_WINDOW/3,i=HEIGHT_WINDOW/10,h={font:(i/1.5).toString()+"px stencil",fill:"#e2e2e2"};this.add.text(e-s,t-i,selectWord("ATTACK","ATTAQUE"),h).setOrigin(.5,.5),this.add.text(e,t-i,selectWord("MOVE","DEPLACEMENT"),h).setOrigin(.5,.5),this.add.text(e+s,t-i,selectWord("CONDITION","CONDITION"),h).setOrigin(.5,.5);let a=this.add.sprite(e-s,t+i,"attack").setOrigin(.5,.5).setInteractive().on("pointerdown",()=>this.click("attack"));a.displayHeight=2*i,a.scaleX=a.scaleY,(a=this.add.sprite(e,t+i,"move").setOrigin(.5,.5).setInteractive().on("pointerdown",()=>this.click("move"))).displayHeight=2*i,a.scaleX=a.scaleY,(a=this.add.sprite(e+s,t+i,"condition").setOrigin(.5,.5).setInteractive().on("pointerdown",()=>this.click("condition"))).displayHeight=2*i,a.scaleX=a.scaleY}click(e){switch(e.toString()){case"attack":this.father.scene.add("AddNode",new AddAttack(this.father,this.gameR,this.selected));break;case"move":this.father.scene.add("AddNode",new AddMove(this.father,this.gameR,this.selected));break;case"condition":this.father.scene.add("AddNode",new AddCondition(this.father,this.gameR,this.selected))}this.scene.launch("AddNode"),this.scene.stop("PlusNode"),this.father.scene.remove("PlusNode")}createButton(){let e=WIDTH_WINDOW/2,t=HEIGHT_WINDOW-100,s=this.add.image(e,t,"cancel").setOrigin(.5,.5).setInteractive();s.on("pointerover",()=>s.setFrame(1)),s.on("pointerout",()=>s.setFrame(0)),s.on("pointerdown",()=>this.cancel()),s.displayHeight=HEIGHT_WINDOW/10,s.scaleX=s.scaleY}cancel(){this.scene.resume("Game"),this.scene.stop("PlusNode"),this.father.scene.remove("PlusNode")}}class RectangleNode{constructor(e,t,s,i,h=[]){switch(i.toString().toLowerCase()){case"attack":this.rect=new Phaser.GameObjects.Image(s,e,t,"attackNode"),this.node=new Attack(h[0]),this.canAddNode=!1,this.line=s.add.graphics();break;case"move":this.rect=new Phaser.GameObjects.Image(s,e,t,"moveNode"),this.node=new Move(h[0],h[1]),this.canAddNode=!1,this.line=s.add.graphics();break;case"condition":this.rect=new Phaser.GameObjects.Image(s,e,t,"conditionNode"),this.node=new Condition(h[0],h[1],h[2],h[3],h[4]),this.canAddNode=!0,this.lRect=[],this.scene=s,this.line=s.add.graphics();break;case"waria":this.rect=new Phaser.GameObjects.Image(s,e,t,"logoWaria").setInteractive(),this.canAddNode=!0,this.lRect=[],this.scene=s,this.scene.add.existing(this.rect),this.scene.input.setDraggable(this.rect);break;default:return void console.log("Création d'un node echoué")}"waria"!==i.toString().toLowerCase()&&this.rect.setFrame(this.node.getFrame()),this.type=i,this.rect.on("pointerdown",()=>this.click()),this.rect.setOrigin(.5,0),this.rect.displayHeight=HEIGHT_NODE,this.rect.scaleX=this.rect.scaleY}getSelected(){if(this.rect.isTinted)return this;if(this.canAddNode)for(let e=0;ethis.addLine(e))}addLine(e){e.setLine(this.rect.x,this.rect.y+.9*this.rect.displayHeight)}getNode(){if(void 0===this.node){let e=[];return this.lRect.forEach(function(t){e.push(t.getNode())}),e}return this.canAddNode&&(this.node.clearNodes(),this.lRect.forEach(e=>this.node.addNode(e.getNode()))),this.node}sort(e){this.canAddNode&&(this.lRect.sort(e),this.lRect.forEach(function(t){t.canAddNode&&t.sort(e)}))}destroy(){this.line.destroy(),this.rect.destroy(),void 0!==this.lRect&&this.lRect.forEach(e=>e.destroy())}delete(e){let t=this.lRect.indexOf(e);if(-1!==t)return this.lRect.splice(t,1),e.destroy(),!0;for(let t=0;tt+=s.getJson(e)+","),t=endLineJson(t)+"]"),t=endLineJson(t),t+="}"}}class Robot{constructor(e,t,s,i,h,a="enemy"){this.speed=SPEED_BASE+SPEED_BEGIN,this.speedReload=SPEED_RELOAD_BASE+SPEED_RELOAD_BEGIN,this.range=RANGE_BASE+RANGE_BEGIN,this.damage=DAMAGE_BASE+DAMAGE_BEGIN,this.speedBonus=1,this.name=a,this.height=e,this.width=t,this.x=s,this.y=i,this.life=new HealthBar(h,selectWord("LIFE","VIE"),2*this.width,this.width/3,this.x,this.y-this.width,LIFE,32768),this.shield=new HealthBar(h,selectWord("SHIELD","BOUCLIER"),2*this.width,this.width/3,this.x,this.y-1.5*this.width,SHIELD,255),this.circleRange=null,this.canAttack=!0,this.missile=new Missile(h,"bullet",this.width/5,this.width/4),h.add.existing(this.missile),this.addScene(h),this.lNode=[];let n=new Condition(!0,!0,!1,.5,0);n.addNode(new Move(!1)),this.addNode(n),this.addNode(new Attack),this.addNode(new Move(!0))}addScene(e){this.scene=e,"enemy"===this.name?(this.circle=this.scene.add.image(this.x,this.y,"enemy").setOrigin(.5,.5).setInteractive(),this.circle.displayWidth=this.circle.displayHeight=this.width):this.circle=this.scene.add.circle(this.x,this.y,this.width/2,COLOR_MYSELF).setInteractive(),this.circle.on("pointerdown",()=>this.click())}click(){null===this.circleRange?this.drawRange():this.eraseRange()}addShield(e){this.shield.increase(e)}setX(e){this.x=e,this.circle.setX(this.x),this.life.setX(this.x),this.shield.setX(this.x),this.drawCircleRange()}setY(e){this.y=e,this.life.setY(this.y-this.width),this.shield.setY(this.y-1.5*this.width),this.circle.setY(this.y),this.drawCircleRange()}setTarget(e){this.target=e}updateTarget(){this.verifyTarget()&&this.setTargetPos(this.target.x,this.target.y)}setTargetPos(e,t){}setDamage(e=this.damage){this.damage=e+DAMAGE_BASE}setRange(e=this.range){this.range=e+RANGE_BASE,this.drawCircleRange()}setSpeed(e=this.speed){this.speed=e+SPEED_BASE}setSpeedReload(e=this.speedReload){this.speedReload=e+SPEED_RELOAD_BASE}increaseSpeedBonus(e){this.speedBonus+=e}decreaseSpeedBonus(e){this.speedBonus-=e,console.log(this.speed)}advanceToTarget(){return this.verifyTarget()&&this.advanceTo(this.target),!1}advanceTo(e){if(e.x!==this.x||e.y!==this.y){let t=!1,s=!1,i=this.getVelocity(e),h=i[0]+this.x,a=i[1]+this.y;return i[0]>=0&&h>=e.x||i[0]<=0&&h<=e.x?(this.setX(e.x),t=!0):this.setX(this.x+i[0]),i[1]>=0&&a>=e.y||i[1]<=0&&a<=e.y?(this.setY(e.y),s=!0):this.setY(this.y+i[1]),!(t&&s)}return!1}fleeFromTarget(){return!!this.verifyTarget()&&this.fleeFrom(this.target)}fleeFrom(e){if(this.target.x!==this.x||this.target.y!==this.y){let t=this.getVelocity(e,!0);return t[0]>=0&&this.x-this.width/2<=0?this.setX(this.width/2):t[0]<=0&&this.x+this.width/2>=WIDTH_MAP?this.setX(WIDTH_MAP-this.width/2):this.setX(this.x-t[0]),t[1]>=0&&this.y-this.width/2<=0?this.setY(this.height/2):t[1]<=0&&this.y+this.width/2>=WIDTH_MAP?this.setY(WIDTH_MAP-this.height/2):this.setY(this.y-t[1]),!0}return!1}getVelocity(e,t=!1){let s=[],i=e.x-this.x,h=e.y-this.y,a=Math.hypot(i,h);return s[0]=i/a*SPEED*this.speed*this.speedBonus*SPEED_GAME,s[1]=h/a*SPEED*this.speed*this.speedBonus*SPEED_GAME,t&&(this.x+this.width/2+s[0]>WIDTH_MAP||this.x-this.width/2-s[0]<0?(s[1]+=s[0]*Math.sign(s[1]),s[0]=0):(this.y+this.width/2-s[1]>WIDTH_MAP||this.y-this.width/2+s[1]<0)&&(s[0]+=s[1]*Math.sign(-s[0]),s[1]=0)),s}attackTarget(e=0){return!!this.verifyTarget()&&(this.canAttack&&this.attack(this.target,e),!0)}verifyTarget(){return!!this.haveTarget()&&(!!this.target.isAlive()||(this.setTarget(null),!1))}attack(e,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.sound.play("shot");let s=this.calcDistance(this.target)*WIDTH_MAP/1e3/SPEED_GAME;this.scene.tweens.add({targets:this.missile,x:e.x,y:e.y,ease:"Linear",duration:s,onComplete:()=>this.finishAttack(e,t)}),this.scene.time.addEvent({delay:SPEED_RELOAD/this.speedReload/SPEED_GAME,callback:this.reload,callbackScope:this})}finishAttack(e,t){e.beAttack(this.damage*DAMAGE*t)&&this.setTarget(null),this.missile.setVisible(!1)}reload(){this.canAttack=!0}beAttack(e){let t=this.shield.decrease(e),s={font:HEIGHT_DAMAGE.toString()+"px stencil",fill:"#ffff00"},i=this.scene.add.text(this.x,this.y,e.toString(),s).setOrigin(0,1);return this.scene.tweens.add({targets:i,x:this.x+30,y:this.y-50,alpha:0,duration:DURATION_DAMAGE,ease:"Sine.easeOut",onComplete:()=>i.destroy()}),this.scene.sound.play("hit"),console.log("HIT"),t>0&&(console.log("Shield Broken"),this.life.decrease(t)),this.die()}isTargetInRange(e=1){return!!this.haveTarget()&&this.calcDistance(this.target)<=this.range*RANGE*e}calcDistance(e){return Math.hypot(e.x-this.x,e.y-this.y)}isAlive(){return this.life.value>0}die(){return 0===this.life.value&&(null!==this.circleRange&&this.circleRange.destroy(),this.circle.destroy(),this.shield.destroy(),this.life.destroy(),!0)}haveTarget(){return null!=this.target}read(){this.verifyTarget();for(let e=0;ee.setFrame(0)),e.on("pointerover",()=>e.setFrame(1)),e.on("pointerdown",()=>this.clickPlay(t))}clickPlay(e){newGame(this.father,e),this.scene.start("Game")}}var listBonus=[],LANG=navigator.language.substr(0,2).toLowerCase(),SPEED_GAME=1;const MYSELF="myself",SHIELD_PER_SECOND=5,COLOR_ATTACK=16711680,COLOR_MOVE=255,COLOR_CONDITION=921102,COLOR_RED=16711680,COLOR_ORANGE=16744192,COLOR_GREEN=32768,COLOR_RANGE=32768,COLOR_SPEED_RELOAD=8323327,COLOR_MYSELF=6711039,WIDTH_WINDOW=$(document).width()-20,HEIGHT_WINDOW=$(document).height()-20,WIDTH_MAP=WIDTH_WINDOW1/3?e>2/3?(e=1,this.percentBonus=1):(e=2/3,this.percentBonus=1.5):(e=1/3,this.percentBonus=2),this.percentRange=e}do(e){return!(!e.haveTarget()||!e.isTargetInRange(this.percentRange))&&e.attackTarget(this.percentBonus)}getFrame(){return 3*this.percentRange-1}getOptionJson(){return this.percentRange}}class Bar extends HealthBar{constructor(e,t="",s,i,h,a,n,o=new CategoryBar,r=1,d){super(e,t,s,i,h,a,void 0!==d?d:o.valueMax,n,n,!1),this.name=t,this.scene=e,this.scene.input.on("pointerdown",this.doDrag,this);let l={font:i.toString()+"px stencil",fill:"#e2e2e2"};this.text=this.scene.add.text(this.bar.x+this.width+10,this.bar.y,this.value.toString(),l).setOrigin(0,0),this.categoryBar=o,this.setValue(0),this.categoryBar.setValueOf(this,r)}doDrag(){let e=this.scene.input;e.x>=this.bar.x-10&&e.x<=this.bar.x+this.width+10&&e.y>=this.bar.y&&e.y<=this.bar.y+this.height&&(this.scene.pauseScene(),this.clickOn())}clickOn(){this.onMove(),this.scene.input.on("pointermove",()=>this.onMove()),this.scene.input.on("pointerup",()=>this.stopClick())}stopClick(){this.scene.input.off("pointermove"),this.scene.input.off("pointerup")}onMove(){this.setValWithX(this.scene.input.x)}setValWithX(e){this.categoryBar.setValueOf(this,Math.round((e-this.bar.x)/this.width*this.valueMax))}draw(){super.draw();let e=this.value/this.valueMax*this.width-5;this.bar.fillStyle(9868950),this.bar.fillRect(e,0,10,this.height),void 0!==this.text&&this.text.setText(this.value+1)}}class BonusAttack extends Bonus{constructor(e,t,s,i,h){super(e,t,s,i,"bonusAttack",h)}useOn(e){let t=e.speed;e.setSpeed(t+this.value),this.scene.time.addEvent({delay:this.time,callback:e.setSpeed(t)}),this.destroy()}}class BonusShield extends Bonus{constructor(e,t,s,i,h){super(e,t,s,i,"bonusShield",h)}useOn(e){e.shield.valueMax=e.shield.valueMax+this.value,e.shield.value=e.shield.value+this.val,this.destroy()}}class BonusSpeed extends Bonus{constructor(e="",t,s,i,h,a){let n;switch(h){case 1:n="bonusSpeed0";break;case 2:n="bonusSpeed1";break;case 3:default:n="bonusSpeed2"}super(e,t,s,i,n,h),this.time=a}useOn(e){e.increaseSpeedBonus(this.value),this.scene.time.addEvent({delay:this.time,callback:()=>e.decreaseSpeedBonus(this.value)}),this.destroy()}}class Boot extends ManageLang{constructor(e){super("Boot",e)}create(){super.create();this.add.text(WIDTH_WINDOW/2,HEIGHT_WINDOW/3,"WARIA",{font:"200px stencil",fill:"#e2e2e2"}).setOrigin(.5,.5);let e=this.add.sprite(WIDTH_WINDOW/2,HEIGHT_WINDOW/3*2,"playLetter").setInteractive();e.on("pointerout",()=>e.setFrame(0)),e.on("pointerover",()=>e.setFrame(1)),e.on("pointerdown",()=>this.clickPlay(e))}clickPlay(e){console.log("Play"),this.father.scene.add("Type",new Type(this.father)),this.scene.start("Type")}}class Category{constructor(e="undefined",t=!0,s=!0){this.name=e,this.single=t,this.lBtn=[],this.lValue=[],this.obligatory=s}add(e,t){0!==this.lBtn.length&&this.single&&(this.lBtn[0].clearTint(),this.lValue=[],this.lBtn=[]),this.lValue.push(t),this.lBtn.push(e),e.tint=15718407}getValue(){return this.single?this.lValue[0]:this.lValue}validate(){return!(0===this.lBtn.length&&this.obligatory)}remove(e){let t=this.lBtn.indexOf(e);-1!==t&&(this.lBtn.splice(t,1),this.lValue.splice(t,1)),e.clearTint()}}class CategoryBar{constructor(e=VALUE_MAX_BAR,t=1){this.startValue=t,this.valueMax=e,this.point=this.valueMax}addPoint(e){if(this.point+=e,this.point<0){let e=this.point;return this.point=0,e}return this.point>this.valueMax&&(this.point=this.valueMax),0}setValueOf(e,t){let s=t-e.value,i=e.value;this.point>=s?e.setValue(t):e.setValue(e.value+this.point),this.addPoint(i-e.value),this.draw()}addText(e,t,s,i,h){this.text=t;let a={font:h.toString()+"px stencil",fill:"#e2e2e2"};this.textScene=e.add.text(s,i,this.text,a).setOrigin(0,0),this.draw()}setTextPos(e,t){this.textScene.setX(e),this.textScene.setY(t)}setText(e){this.text=e,this.draw()}draw(){this.textScene.setText(this.text+this.point)}}class Condition{constructor(e,t=!1,s=!1,i,h){this.shieldFilter=t,this.rangeFilter=s,this.shield=i,this.range=h,this.myself=e,this.lNode=[]}addNode(e){this.lNode.push(e)}do(e){if(this.doCondition(e))for(let t=0;t=h&&(s>h&&(s=h,i=[]),i.push(t))}}),i.length>1?i[Math.floor(Math.random()*(i.length+1))]:i[0]}function toJson(e,t,s=!1){let i;switch(typeof t){case"string":i='"'+e.toString()+'":"'+t+'"';break;default:i='"'+e.toString()+'":'+t}return s||(i+=","),i}function endLineJson(e){return e.length>0&&","===e[e.length-1]&&(e=e.substr(0,e.length-1)),e}var tree=void 0;class Game extends ManageLang{constructor(e,t="level1"){super("Game",e),super.addOtherScenes("GamingBoard"),SPEED_GAME=1,this.level=t}preload(){let e,t={font:"100px stencil",fill:"#e2e2e2"};this.load.on("start",()=>{(e=this.add.text(.5*WIDTH_WINDOW,.5*HEIGHT_WINDOW,selectWord("LEVEL LOADING ...","CHARGEMENT DU NIVEAU ..."),t).setOrigin(.5,.5)).alpha=.5}),this.load.on("complete",()=>{e.destroy()}),this.cache.json.exists("level")&&this.cache.json.remove("level"),this.load.json("level","public/json/"+this.level+".json")}create(){super.create(),this.gm=new GamingBoard(this),-1!==this.father.scene.getIndex("GamingBoard")&&this.father.scene.remove("GamingBoard"),this.father.scene.add("GamingBoard",this.gm),this.scene.launch("GamingBoard"),this.scene.pause("GamingBoard");let e=this.cache.json.get("level");if(void 0!==e){if(void 0!==this.tree&&void 0!==this.initStat){let t=this.tree.getJson(!0);t=JSON.parse(t);let s=this.initStat.getJson(!0);s=JSON.parse(s),this.loadSave(t,s,e.robots,e.lBonus)}else this.loadSave(e.tree,e.initStat,e.robots,e.lBonus);this.doLine=!1,this.selected=null,this.createButton(),this.input.keyboard.on("keydown-DELETE",()=>{this.clickBin()}),this.input.keyboard.on("keydown-E",()=>{this.clickPencil()}),this.input.keyboard.on("keydown-ENTER",()=>{this.clickPlus()})}else console.log("ERROR : LEVEL UNDEFINED")}update(e,t){super.update(e,t),this.doLine&&this.tree.updateLine()}loadSave(e,t,s,i){this.loadRobot(s),this.loadBonus(i),this.initStat=this.loadInitSave(t),this.tree=this.loadTree(e)}loadTree(e,t=CENTERX_TREE,s=OFFY_TREE/2){if(void 0!==e.x&&void 0!==e.y){let t=new RectangleNode(e.x,e.y,this,e.type,e.option);return void 0!==e.lRect&&e.lRect.length>0&&e.lRect.forEach(e=>t.addRect(this.loadTree(e))),t}{let i=new RectangleNode(t,s,this,e.type,e.option);if(void 0!==e.lRect&&e.lRect.length>0){let h=e.lRect.length,a=t-OFFX_TREE/2*(h-1),n=s+OFFY_TREE;e.lRect.forEach(e=>{i.addRect(this.loadTree(e,a,n)),a+=OFFX_TREE})}return i}}loadInitSave(e){let t=new InitStat(this,OFFX_MAP+WIDTH_MAP+5,OFFY_MAP,200,30,10);for(let s=0;s{let t=[];e.lNode.forEach(e=>t.push(this.loadNode(e))),this.gm.addRobot(new Robot(WIDTH_MAP*e.height,WIDTH_MAP*e.width,WIDTH_MAP*e.x,WIDTH_MAP*e.y,this.gm,e.name,e.speed,e.speedReload,e.range,e.damage,t))})}loadNode(e){let t;switch(e.name){case"condition":t=new Condition(e.option[0],e.option[1],e.option[2],e.option[3],e.option[4]);break;case"move":t=new Move(e.option[0],e.option[1]);break;case"attack":t=new Attack(e.option[0]);break;default:return}return void 0!==e.lNode&&e.lNode.forEach(e=>t.addNode(this.loadNode(e))),t}loadBonus(e=[]){e.forEach(e=>{this.gm.addBonus(this.loadB(e))})}loadB(e){switch(e.style){case"speed":return new BonusSpeed("",this.gm,WIDTH_MAP*e.x,WIDTH_MAP*e.y,e.value,e.time);case"attack":return new BonusAttack("",this.gm,WIDTH_MAP*e.x,WIDTH_MAP*e.y,e.value);default:return}}finish(){let e;console.log("FINISH"),e=this.gm.winner()?new Winner(this.father,this):new Looser(this.father,this),this.father.scene.add("Finish",e),this.scene.pause("Game"),this.scene.launch("Finish")}clickNode(){this.tryClick(),this.selected=this.tree.getSelected(),null!==this.selected&&(this.selected!==this.tree&&(this.pencil.setVisible(!0),this.bin.setVisible(!0)),this.selected.canAddNode&&this.plus.setVisible(!0))}doDrag(e,t,s,i){t.setX(s),t.setY(i)}dragStart(){console.log("START DRAG"),this.doLine=!0,this.pauseScene()}dragEnd(){console.log("END DRAG"),this.doLine=!1}pauseScene(){this.linePlay=0,this.changeFrame(this.play,0),this.gm.pause()}resume(){this.linePlay=1;this.tree.sort((e,t)=>e.getX()-t.getX()),this.gm.modifyNodes(this.tree.getNode()),this.gm.modifyValue(this.initStat.lBar[0].value,this.initStat.lBar[1].value,this.initStat.lBar[2].value,this.initStat.lBar[3].value),this.gm.resume()}changeFrame(e,t=0,s=0){e.setFrame(t+2*s)}createButton(){let e=WIDTH_MAP+OFFX_MAP,t=WIDTH_MAP+OFFY_MAP+5,s=WIDTH_BUTTON,i=1.1*s,h=this.add.sprite(10,10,"back").setOrigin(0,0).setInteractive();this.play=this.add.sprite(e,t,"play").setOrigin(1,0).setInteractive();let a=this.add.sprite(e-i,t,"speed").setOrigin(1,0).setInteractive(),n=this.add.sprite(WIDTH_WINDOW,t,"save").setOrigin(1,0).setInteractive();this.pencil=this.add.sprite(e-2*i,t,"pencil").setOrigin(1,0).setInteractive().setVisible(!1),this.bin=this.add.sprite(e-3*i,t,"bin").setOrigin(1,0).setInteractive().setVisible(!1),this.plus=this.add.sprite(e-4*i,t,"plus").setOrigin(1,0).setInteractive().setVisible(!1);let o=this.add.sprite(e-5*i,t,"mute").setOrigin(1,0).setInteractive();this.linePlay=0,this.lineSpeed=1===SPEED_GAME?0:1,this.changeFrame(a,0,this.lineSpeed),this.father.sound.mute?this.lineMute=1:this.lineMute=0,this.changeFrame(o,0,this.lineMute),h.displayHeight=h.displayWidth=s,n.displayHeight=n.displayWidth=s,this.play.displayHeight=this.play.displayWidth=s,a.displayHeight=a.displayWidth=s,o.displayHeight=o.displayWidth=s,this.pencil.displayHeight=this.pencil.displayWidth=s,this.bin.displayHeight=this.bin.displayWidth=s,this.plus.displayHeight=this.plus.displayWidth=s,this.play.on("pointerout",()=>this.changeFrame(this.play,0,this.linePlay)),this.play.on("pointerover",()=>this.changeFrame(this.play,1,this.linePlay)),a.on("pointerout",()=>this.changeFrame(a,0,this.lineSpeed)),a.on("pointerover",()=>this.changeFrame(a,1,this.lineSpeed)),o.on("pointerout",()=>this.changeFrame(o,0,this.lineMute)),o.on("pointerover",()=>this.changeFrame(o,1,this.lineMute)),this.creatBtnOutAndOver(n),this.creatBtnOutAndOver(h),this.creatBtnOutAndOver(this.pencil),this.creatBtnOutAndOver(this.bin),this.creatBtnOutAndOver(this.plus),this.play.on("pointerdown",()=>this.clickPlay()),a.on("pointerdown",()=>this.clickSpeed(a)),h.on("pointerdown",()=>this.clickBack()),o.on("pointerdown",()=>this.clickMute(o)),n.on("pointerdown",()=>this.clickSave()),this.pencil.on("pointerdown",()=>this.clickPencil()),this.bin.on("pointerdown",()=>this.clickBin()),this.plus.on("pointerdown",()=>this.clickPlus()),this.input.on("pointerdown",()=>this.clickNode()),this.input.on("drag",this.doDrag),this.input.on("dragstart",()=>this.dragStart()),this.input.on("dragend",()=>this.dragEnd())}creatBtnOutAndOver(e){e.on("pointerout",()=>this.changeFrame(e,0)),e.on("pointerover",()=>this.changeFrame(e,1))}clickSave(){this.tree.sort((e,t)=>e.getX()-t.getX());let e='{"tree":'+this.tree.getJson()+',"initStat":'+this.initStat.getJson()+"}";console.log(e)}clickPlay(){this.scene.isPaused("GamingBoard")?this.resume():this.pauseScene(),this.changeFrame(this.play,1,this.linePlay)}clickSpeed(e){1===SPEED_GAME?(SPEED_GAME=2,this.lineSpeed=1):(SPEED_GAME=1,this.lineSpeed=0),this.changeFrame(e,1,this.lineSpeed)}clickPencil(){if(null!==this.selected){switch(console.log("PENCIL"),this.changeFrame(this.pencil,0),this.selected.type){case"attack":this.father.scene.add("AddNode",new AddAttack(this.father,this,this.selected,!1,this.selected.node.percentRange));break;case"move":this.father.scene.add("AddNode",new AddMove(this.father,this,this.selected,this.selected.node.toward,this.selected.node.enemyBot));break;case"condition":this.selected.node.shieldFilter?this.father.scene.add("AddNode",new AddCondition(this.father,this,this.selected,this.selected.node.myself,[this.selected.node.shield,"shield"])):this.father.scene.add("AddNode",new AddCondition(this.father,this,this.selected,this.selected.node.myself,[this.selected.node.range,"range"]));break;default:return}this.scene.pause("Game"),this.scene.launch("AddNode")}}clickBin(){null!==this.selected&&(console.log("BIN"),this.tree.delete(this.selected),this.changeFrame(this.bin,0),this.tryClick())}clickPlus(){null!==this.selected&&this.selected.canAddNode&&(console.log("PLUS"),this.father.scene.add("PlusNode",new PlusNode(this.father,this,this.selected)),this.scene.launch("PlusNode"),this.changeFrame(this.plus,0),this.scene.pause("Game"))}clickBack(){console.log("BACK"),this.father.scene.stop("GamingBoard"),this.father.scene.remove("GamingBoard"),this.father.scene.stop("Game"),this.father.scene.start("Type")}clickMute(e){console.log("MUTE"),this.father.sound.mute?(this.father.sound.mute=!1,this.lineMute=0):(this.father.sound.mute=!0,this.lineMute=1),this.changeFrame(e,1,this.lineMute)}tryClick(){this.pencil.setVisible(!1),this.bin.setVisible(!1),this.plus.setVisible(!1),null!=this.selected&&(this.selected.deselect(),this.selected=null)}}class GamingBoard extends Phaser.Scene{constructor(e){super("GamingBoard"),this.listRobot=[],listBonus=[],this.father=e,this.end=!1}preload(){this.cameras.main.setViewport(OFFX_MAP,OFFY_MAP,WIDTH_MAP,WIDTH_MAP),this.sound.add("shot"),this.sound.add("hit")}create(){this.add.image(0,0,"background").alpha=.1;for(let e=0;et.addNode(e)),!0)}modifyValue(e,t,s,i){let h=this.getMyRobot();return void 0!==h&&(h.setSpeed(s),h.setRange(i),h.setSpeedReload(t),h.setDamage(e),!0)}getMyRobot(){for(let e=0;ee.addShield(SHIELD_PER_SECOND)),this.time.addEvent({delay:1e3/SPEED_GAME,callback:this.upShield,callbackScope:this})}}class InitStat{constructor(e,t,s,i,h,a){this.scene=e,this.posX=t,this.posY=s,this.width=i,this.height=h,this.category=new CategoryBar(a),this.lBar=[],this.lText=[],this.category.addText(this.scene,selectWord("TOKENS : ","JETONS : "),this.posX,this.posY,this.height)}addBar(e,t,s,i){this.lText.push(i),this.lBar.push(new Bar(this.scene,selectWord(i[0],i[1]),this.width,this.height,this.posX,this.posY,s,this.category,e,t)),this.posY+=1.5*this.height,this.category.setTextPos(this.posX,this.posY)}getJson(){let e="{";return e+='"lBar":[',this.lBar.forEach(t=>e+=t.getJson()+","),e=endLineJson(e)+"],",e+='"lText":[',this.lText.forEach(t=>{e+="[",t.forEach(t=>{e+='"'+t+'",'}),e=endLineJson(e),e+="],"}),e=endLineJson(e),e+="]",e+="}"}}class LoadFile extends Phaser.Scene{constructor(e,t,s){super("LoadFile"),this.father=e,this.son=s,this.nameSon=t,this.father.scene.pause(this.nameSon),this.father.scene.stop(this.nameSon),this.father.scene.remove("LoadFile")}preload(){let e=this.add.graphics(),t=this.add.graphics(),s=WIDTH_WINDOW/2-160,i=HEIGHT_WINDOW/2-25;t.fillStyle(2236962,.8),t.fillRect(s,i,320,50),this.load.on("progress",function(t){e.clear(),e.fillStyle(16777215,1),e.fillRect(s+10,i+10,300*t,30)}),this.load.on("complete",()=>{e.destroy(),t.destroy(),-1===this.father.scene.getIndex(this.nameSon)&&this.father.scene.add(this.nameSon,this.son),this.father.scene.start(this.nameSon)}),this.load.audio("shot","assets/sounds/shot.ogg"),this.load.audio("hit","assets/sounds/hit.ogg"),this.loadImage("en","flags/",!0),this.loadImage("fr","flags/",!0),this.loadImage("bonusSpeed0","bonus/",!0),this.loadImage("bonusSpeed1","bonus/",!0),this.loadImage("bonusSpeed2","bonus/",!0),this.loadImage("enemy","robots/"),this.loadSprite("playLetter",550,150,"buttons/"),this.loadSprite("cancel",550,150,"buttons/"),this.loadSprite("add",550,150,"buttons/"),this.loadSprite("modify",550,150,"buttons/"),this.loadSprite("home",550,150,"buttons/"),this.loadSprite("next",550,150,"buttons/"),this.loadSprite("retry",550,150,"buttons/"),this.loadSprite("duel",269,262,"buttons/"),this.loadSprite("last",269,262,"buttons/"),this.loadSprite("team",269,262,"buttons/"),this.loadSprite("flag",269,262,"buttons/"),this.loadSprite("map",269,262,"buttons/"),this.loadSprite("play",100,100,"buttons/"),this.loadSprite("bin",100,100,"buttons/"),this.loadSprite("plus",100,100,"buttons/"),this.loadSprite("pencil",100,100,"buttons/"),this.loadSprite("speed",100,100,"buttons/"),this.loadSprite("mute",100,100,"buttons/"),this.loadSprite("save",100,100,"buttons/"),this.loadSprite("back",200,200,"buttons/"),this.loadSprite("shortRange",300,150,"buttons/"),this.loadSprite("mediumRange",300,150,"buttons/"),this.loadSprite("longRange",300,150,"buttons/"),this.loadSprite("shield0",300,150,"buttons/"),this.loadSprite("shield33",300,150,"buttons/"),this.loadSprite("shield66",300,150,"buttons/"),this.loadSprite("shield100",300,150,"buttons/"),this.loadSprite("myself",300,150,"buttons/"),this.loadSprite("enemyBot",300,150,"buttons/"),this.loadSprite("bonus",300,150,"buttons/"),this.loadSprite("moveToward",300,150,"buttons/"),this.loadSprite("fleeFrom",300,150,"buttons/"),this.loadSprite("attackNode",180,190,"nodes/",!0),this.loadSprite("moveNode",180,190,"nodes/",!0),this.loadSprite("conditionNode",180,190,"nodes/",!0),this.loadImage("background"),this.loadImage("bullet"),this.loadImage("logoWaria"),this.loadImage("attack","nodes/",!0),this.loadImage("move","nodes/",!0),this.loadImage("condition","nodes/",!0)}loadSprite(e,t,s,i="",h=!1){this.deleteLoad(e),h?this.load.spritesheet(e,"assets/"+i+e+".png",{frameWidth:t,frameHeight:s}):this.load.spritesheet(e,"assets/"+LANG+"/"+i+e+".png",{frameWidth:t,frameHeight:s})}loadImage(e,t="",s=!1){this.deleteLoad(e),s?this.load.image(e,"assets/"+t+e+".png"):this.load.image(e,"assets/"+LANG+"/"+t+e+".png")}deleteLoad(e){this.textures.exists(e)&&this.textures.remove(e)}}class Looser extends Finish{constructor(e,t){super(e,t)}create(){super.create(),super.addTitle(selectWord("GAME OVER","PARTIE PERDUE")),super.btnRetry(super.createButton(WIDTH_WINDOW/3,"retry")),super.btnHome(super.createButton(WIDTH_WINDOW/1.5,"home"))}}class Missile extends Phaser.GameObjects.Image{constructor(e,t,s,i){super(e,0,0,t),this.visible=!1,this.setOrigin(.5,.5),this.setScale(.02)}}class Move{constructor(e,t=!0){this.toward=e,this.enemyBot=t}do(e){if(this.enemyBot){if(e.verifyTarget())return!0===this.toward?this.moveToward(e):this.fleeFrom(e)}else{let t=chooseTarget(e,listBonus);if(void 0!==t){let s;return(s=!0===this.toward?this.moveToward(e,t):this.fleeFrom(e,t))||(t.useOn(e),listBonus.splice(listBonus.indexOf(t),1)),!0}}return!1}moveToward(e,t=e.target){return e.advanceTo(t)}fleeFrom(e,t=e.target){return e.fleeFrom(t)}getFrame(){let e;return e=this.toward?0:2,this.enemyBot||(e+=1),e}getOptionJson(){return this.toward+","+this.enemyBot}}class PlusNode extends Phaser.Scene{constructor(e,t,s){super("PlusNode"),this.father=e,this.gameR=t,this.selected=s}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 e=WIDTH_WINDOW/2,t=HEIGHT_WINDOW/2,s=WIDTH_WINDOW/3,i=HEIGHT_WINDOW/10,h={font:(i/1.5).toString()+"px stencil",fill:"#e2e2e2"};this.add.text(e-s,t-i,selectWord("ATTACK","ATTAQUE"),h).setOrigin(.5,.5),this.add.text(e,t-i,selectWord("MOVE","DEPLACEMENT"),h).setOrigin(.5,.5),this.add.text(e+s,t-i,selectWord("CONDITION","CONDITION"),h).setOrigin(.5,.5);let a=this.add.sprite(e-s,t+i,"attack").setOrigin(.5,.5).setInteractive().on("pointerdown",()=>this.click("attack"));a.displayHeight=2*i,a.scaleX=a.scaleY,(a=this.add.sprite(e,t+i,"move").setOrigin(.5,.5).setInteractive().on("pointerdown",()=>this.click("move"))).displayHeight=2*i,a.scaleX=a.scaleY,(a=this.add.sprite(e+s,t+i,"condition").setOrigin(.5,.5).setInteractive().on("pointerdown",()=>this.click("condition"))).displayHeight=2*i,a.scaleX=a.scaleY}click(e){switch(e.toString()){case"attack":this.father.scene.add("AddNode",new AddAttack(this.father,this.gameR,this.selected));break;case"move":this.father.scene.add("AddNode",new AddMove(this.father,this.gameR,this.selected));break;case"condition":this.father.scene.add("AddNode",new AddCondition(this.father,this.gameR,this.selected))}this.scene.launch("AddNode"),this.scene.stop("PlusNode"),this.father.scene.remove("PlusNode")}createButton(){let e=WIDTH_WINDOW/2,t=HEIGHT_WINDOW-100,s=this.add.image(e,t,"cancel").setOrigin(.5,.5).setInteractive();s.on("pointerover",()=>s.setFrame(1)),s.on("pointerout",()=>s.setFrame(0)),s.on("pointerdown",()=>this.cancel()),s.displayHeight=HEIGHT_WINDOW/10,s.scaleX=s.scaleY}cancel(){this.scene.resume("Game"),this.scene.stop("PlusNode"),this.father.scene.remove("PlusNode")}}class RectangleNode{constructor(e,t,s,i,h=[]){switch(i.toString().toLowerCase()){case"attack":this.rect=new Phaser.GameObjects.Image(s,e,t,"attackNode"),this.node=new Attack(h[0]),this.canAddNode=!1,this.line=s.add.graphics();break;case"move":this.rect=new Phaser.GameObjects.Image(s,e,t,"moveNode"),this.node=new Move(h[0],h[1]),this.canAddNode=!1,this.line=s.add.graphics();break;case"condition":this.rect=new Phaser.GameObjects.Image(s,e,t,"conditionNode"),this.node=new Condition(h[0],h[1],h[2],h[3],h[4]),this.canAddNode=!0,this.lRect=[],this.scene=s,this.line=s.add.graphics();break;case"waria":this.rect=new Phaser.GameObjects.Image(s,e,t,"logoWaria").setInteractive(),this.canAddNode=!0,this.lRect=[],this.scene=s,this.scene.add.existing(this.rect),this.scene.input.setDraggable(this.rect);break;default:return void console.log("Création d'un node echoué")}"waria"!==i.toString().toLowerCase()&&this.rect.setFrame(this.node.getFrame()),this.type=i,this.rect.on("pointerdown",()=>this.click()),this.rect.setOrigin(.5,0),this.rect.displayHeight=HEIGHT_NODE,this.rect.scaleX=this.rect.scaleY}getSelected(){if(this.rect.isTinted)return this;if(this.canAddNode)for(let e=0;ethis.addLine(e))}addLine(e){e.setLine(this.rect.x,this.rect.y+.9*this.rect.displayHeight)}getNode(){if(void 0===this.node){let e=[];return this.lRect.forEach(function(t){e.push(t.getNode())}),e}return this.canAddNode&&(this.node.clearNodes(),this.lRect.forEach(e=>this.node.addNode(e.getNode()))),this.node}sort(e){this.canAddNode&&(this.lRect.sort(e),this.lRect.forEach(function(t){t.canAddNode&&t.sort(e)}))}destroy(){this.line.destroy(),this.rect.destroy(),void 0!==this.lRect&&this.lRect.forEach(e=>e.destroy())}delete(e){let t=this.lRect.indexOf(e);if(-1!==t)return this.lRect.splice(t,1),e.destroy(),!0;for(let t=0;tt+=s.getJson(e)+","),t=endLineJson(t)+"]"),t=endLineJson(t),t+="}"}}class Robot{constructor(e,t,s,i,h,a="enemy",n=SPEED_BEGIN,o=SPEED_RELOAD_BEGIN,r=RANGE_BEGIN,d=DAMAGE_BEGIN,l=[]){this.speedBonus=1,this.name=a,this.height=e,this.width=t,this.x=s,this.y=i,this.life=new HealthBar(h,selectWord("LIFE","VIE"),2*this.width,this.width/3,this.x,this.y-this.width,LIFE,32768),this.shield=new HealthBar(h,selectWord("SHIELD","BOUCLIER"),2*this.width,this.width/3,this.x,this.y-1.5*this.width,SHIELD,255),this.circleRange=null,this.canAttack=!0,this.missile=new Missile(h,"bullet",this.width/5,this.width/4),h.add.existing(this.missile),this.addScene(h),this.lNode=l;let c=new Condition(!0,!0,!1,.5,0);c.addNode(new Move(!1)),this.addNode(c),this.addNode(new Attack),this.addNode(new Move(!0)),this.setSpeed(n),this.setSpeedReload(o),this.setRange(r),this.setDamage(d)}addScene(e){this.scene=e,"enemy"===this.name?(this.circle=this.scene.add.image(this.x,this.y,"enemy").setOrigin(.5,.5).setInteractive(),this.circle.displayWidth=this.circle.displayHeight=this.width):this.circle=this.scene.add.circle(this.x,this.y,this.width/2,COLOR_MYSELF).setInteractive(),this.circle.on("pointerdown",()=>this.click())}click(){null===this.circleRange?this.drawRange():this.eraseRange()}addShield(e){this.shield.increase(e)}setX(e){this.x=e,this.circle.setX(this.x),this.life.setX(this.x),this.shield.setX(this.x),this.drawCircleRange()}setY(e){this.y=e,this.life.setY(this.y-this.width),this.shield.setY(this.y-1.5*this.width),this.circle.setY(this.y),this.drawCircleRange()}setTarget(e){this.target=e}updateTarget(){this.verifyTarget()&&this.setTargetPos(this.target.x,this.target.y)}setTargetPos(e,t){}setDamage(e=this.damage){this.damage=e+DAMAGE_BASE}setRange(e=this.range){this.range=e+RANGE_BASE,this.drawCircleRange()}setSpeed(e=this.speed){this.speed=e+SPEED_BASE}setSpeedReload(e=this.speedReload){this.speedReload=e+SPEED_RELOAD_BASE}increaseSpeedBonus(e){this.speedBonus+=e}decreaseSpeedBonus(e){this.speedBonus-=e,console.log(this.speed)}advanceToTarget(){return this.verifyTarget()&&this.advanceTo(this.target),!1}advanceTo(e){if(e.x!==this.x||e.y!==this.y){let t=!1,s=!1,i=this.getVelocity(e),h=i[0]+this.x,a=i[1]+this.y;return i[0]>=0&&h>=e.x||i[0]<=0&&h<=e.x?(this.setX(e.x),t=!0):this.setX(this.x+i[0]),i[1]>=0&&a>=e.y||i[1]<=0&&a<=e.y?(this.setY(e.y),s=!0):this.setY(this.y+i[1]),!(t&&s)}return!1}fleeFromTarget(){return!!this.verifyTarget()&&this.fleeFrom(this.target)}fleeFrom(e){if(this.target.x!==this.x||this.target.y!==this.y){let t=this.getVelocity(e,!0);return t[0]>=0&&this.x-this.width/2<=0?this.setX(this.width/2):t[0]<=0&&this.x+this.width/2>=WIDTH_MAP?this.setX(WIDTH_MAP-this.width/2):this.setX(this.x-t[0]),t[1]>=0&&this.y-this.width/2<=0?this.setY(this.height/2):t[1]<=0&&this.y+this.width/2>=WIDTH_MAP?this.setY(WIDTH_MAP-this.height/2):this.setY(this.y-t[1]),!0}return!1}getVelocity(e,t=!1){let s=[],i=e.x-this.x,h=e.y-this.y,a=Math.hypot(i,h);return s[0]=i/a*SPEED*this.speed*this.speedBonus*SPEED_GAME,s[1]=h/a*SPEED*this.speed*this.speedBonus*SPEED_GAME,t&&(this.x+this.width/2+s[0]>WIDTH_MAP||this.x-this.width/2-s[0]<0?(s[1]+=s[0]*Math.sign(s[1]),s[0]=0):(this.y+this.width/2-s[1]>WIDTH_MAP||this.y-this.width/2+s[1]<0)&&(s[0]+=s[1]*Math.sign(-s[0]),s[1]=0)),s}attackTarget(e=0){return!!this.verifyTarget()&&(this.canAttack&&this.attack(this.target,e),!0)}verifyTarget(){return!!this.haveTarget()&&(!!this.target.isAlive()||(this.setTarget(null),!1))}attack(e,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.sound.play("shot");let s=this.calcDistance(this.target)*WIDTH_MAP/1e3/SPEED_GAME;this.scene.tweens.add({targets:this.missile,x:e.x,y:e.y,ease:"Linear",duration:s,onComplete:()=>this.finishAttack(e,t)}),this.scene.time.addEvent({delay:SPEED_RELOAD/this.speedReload/SPEED_GAME,callback:this.reload,callbackScope:this})}finishAttack(e,t){e.beAttack(this.damage*DAMAGE*t)&&this.setTarget(null),this.missile.setVisible(!1)}reload(){this.canAttack=!0}beAttack(e){let t=this.shield.decrease(e),s={font:HEIGHT_DAMAGE.toString()+"px stencil",fill:"#ffff00"},i=this.scene.add.text(this.x,this.y,e.toString(),s).setOrigin(0,1);return this.scene.tweens.add({targets:i,x:this.x+30,y:this.y-50,alpha:0,duration:DURATION_DAMAGE,ease:"Sine.easeOut",onComplete:()=>i.destroy()}),this.scene.sound.play("hit"),console.log("HIT"),t>0&&(console.log("Shield Broken"),this.life.decrease(t)),this.die()}isTargetInRange(e=1){return!!this.haveTarget()&&this.calcDistance(this.target)<=this.range*RANGE*e}calcDistance(e){return Math.hypot(e.x-this.x,e.y-this.y)}isAlive(){return this.life.value>0}die(){return 0===this.life.value&&(null!==this.circleRange&&this.circleRange.destroy(),this.circle.destroy(),this.shield.destroy(),this.life.destroy(),!0)}haveTarget(){return null!=this.target}read(){this.verifyTarget();for(let e=0;ee.setFrame(0)),e.on("pointerover",()=>e.setFrame(1)),e.on("pointerdown",()=>this.clickPlay(t))}clickPlay(e){newGame(this.father,e),this.scene.start("Game")}}var listBonus=[],LANG=navigator.language.substr(0,2).toLowerCase(),SPEED_GAME=1;const MYSELF="myself",SHIELD_PER_SECOND=5,COLOR_ATTACK=16711680,COLOR_MOVE=255,COLOR_CONDITION=921102,COLOR_RED=16711680,COLOR_ORANGE=16744192,COLOR_GREEN=32768,COLOR_RANGE=32768,COLOR_SPEED_RELOAD=8323327,COLOR_MYSELF=6711039,WIDTH_WINDOW=$(document).width()-20,HEIGHT_WINDOW=$(document).height()-20,WIDTH_MAP=WIDTH_WINDOW { + text = this.add.text(0.5 * WIDTH_WINDOW, 0.5 * HEIGHT_WINDOW, selectWord("LEVEL LOADING ...", "CHARGEMENT DU NIVEAU ..."), style).setOrigin(0.5, 0.5); + text.alpha = 0.5; + }); + this.load.on('complete', () => { + text.destroy(); + }); + if (this.cache.json.exists('level')) { this.cache.json.remove('level'); } @@ -18,47 +28,38 @@ class Game extends ManageLang { create() { super.create(); + this.gm = new GamingBoard(this); + if (this.father.scene.getIndex('GamingBoard') !== -1) { + this.father.scene.remove('GamingBoard'); + } + this.father.scene.add('GamingBoard', this.gm); + this.scene.launch('GamingBoard'); + this.scene.pause('GamingBoard'); + + let level = this.cache.json.get('level'); + if (level === undefined) { + console.log("ERROR : LEVEL UNDEFINED"); + return; + } + if (this.tree !== undefined && this.initStat !== undefined) { let tree = this.tree.getJson(true); - console.log(tree); tree = JSON.parse(tree); let initStat = this.initStat.getJson(true); initStat = JSON.parse(initStat); - this.loadSave(tree, initStat); + this.loadSave(tree, initStat, level.robots, level.lBonus); } else { - let level = this.cache.json.get('level'); - if (level !== undefined) { - this.loadSave(level.tree, level.initStat); - } + this.loadSave(level.tree, level.initStat, level.robots, level.lBonus); } this.doLine = false; - this.gm = new GamingBoard(this); - if (this.father.scene.getIndex('GamingBoard') !== -1) { - this.father.scene.remove('GamingBoard'); - } - this.father.scene.add('GamingBoard', this.gm); - this.scene.launch('GamingBoard'); - this.scene.pause('GamingBoard'); this.selected = null; - let width = 200; - let height = 30; - this.createButton(); - let centerX = WIDTH_WINDOW / 4 * 3; - let diffX = WIDTH_WINDOW / 10; - - - this.gm.addRobot(new Robot(WIDTH_MAP * 0.1, WIDTH_MAP * 0.1, WIDTH_MAP * 0.9, WIDTH_MAP * 0.9, this.gm, MYSELF)); - this.gm.addRobot(new Robot(WIDTH_MAP * 0.1, WIDTH_MAP * 0.1, WIDTH_MAP * 0.2, WIDTH_MAP * 0.1, this.gm)); - this.gm.addRobot(new Robot(WIDTH_MAP * 0.1, WIDTH_MAP * 0.1, WIDTH_MAP * 0.1, WIDTH_MAP * 0.9, this.gm)); - - this.input.keyboard.on('keydown-DELETE', () => { this.clickBin(); }); @@ -77,7 +78,9 @@ class Game extends ManageLang { } - loadSave(tree, initStat) { + loadSave(tree, initStat, robot, lBonus) { + this.loadRobot(robot); + this.loadBonus(lBonus); this.initStat = this.loadInitSave(initStat); this.tree = this.loadTree(tree); } @@ -112,9 +115,56 @@ class Game extends ManageLang { for (let i = 0; i < element.lBar.length; i++) { initStat.addBar(element.lBar[i].value, element.lBar[i].valueMax, element.lBar[i].color, element.lText[i]); } + this.gm.modifyValue(initStat.lBar[0].value, initStat.lBar[1].value, initStat.lBar[2].value, initStat.lBar[3].value); return initStat; } + loadRobot(element = []) { + element.forEach(robot => { + let lNode = []; + robot.lNode.forEach(node => lNode.push(this.loadNode(node))); + this.gm.addRobot(new Robot(WIDTH_MAP * robot.height, WIDTH_MAP * robot.width, WIDTH_MAP * robot.x, WIDTH_MAP * robot.y, this.gm, robot.name, robot.speed, robot.speedReload, robot.range, robot.damage, lNode)); + }) + } + + loadNode(element) { + let node; + switch (element.name) { + case "condition": + node = new Condition(element.option[0], element.option[1], element.option[2], element.option[3], element.option[4]); + break; + case "move": + node = new Move(element.option[0], element.option[1]); + break; + case "attack": + node = new Attack(element.option[0]); + break; + default: + return; + } + if (element.lNode !== undefined) { + element.lNode.forEach(n => node.addNode(this.loadNode(n))); + } + return node; + } + + loadBonus(element = []) { + element.forEach(bonus => { + this.gm.addBonus(this.loadB(bonus)); + }) + } + + loadB(bonus) { + switch (bonus.style) { + case "speed": + return new BonusSpeed("", this.gm, WIDTH_MAP * bonus.x, WIDTH_MAP * bonus.y, bonus.value, bonus.time); + case "attack": + return new BonusAttack("", this.gm, WIDTH_MAP * bonus.x, WIDTH_MAP * bonus.y, bonus.value); + default: + return; + } + } + finish() { console.log("FINISH"); let winner; @@ -132,7 +182,6 @@ class Game extends ManageLang { clickNode() { - console.log("NODE"); this.tryClick(); this.selected = this.tree.getSelected(); @@ -193,7 +242,7 @@ class Game extends ManageLang { createButton() { let x = WIDTH_MAP + OFFX_MAP; let y = WIDTH_MAP + OFFY_MAP + 5; - let width = OFFY_MAP / 1.5; + let width = WIDTH_BUTTON; let diffX = width * 1.1; let back = this.add.sprite(10, 10, 'back').setOrigin(0, 0).setInteractive(); diff --git a/Code/src/js/level2/GamingBoard.js b/Code/src/js/level2/GamingBoard.js index 98cf18e..49ab3db 100644 --- a/Code/src/js/level2/GamingBoard.js +++ b/Code/src/js/level2/GamingBoard.js @@ -14,8 +14,6 @@ class GamingBoard extends Phaser.Scene { } create() { - listBonus.push(new BonusSpeed('Fusée', this, WIDTH_MAP / 2, WIDTH_MAP / 2, 5, 2000)); - this.add.image(0, 0, 'background').alpha = 0.1; for (let i = 0; i < this.listRobot.length; i++) { @@ -74,6 +72,10 @@ class GamingBoard extends Phaser.Scene { this.listRobot.push(robot); } + addBonus(bonus) { + listBonus.push(bonus); + } + modifyNodes(lNodes) { let myRobot = this.getMyRobot(); if (myRobot !== undefined) { diff --git a/Code/src/js/level2/Robot.js b/Code/src/js/level2/Robot.js index 42e3c1a..21f4ce3 100644 --- a/Code/src/js/level2/Robot.js +++ b/Code/src/js/level2/Robot.js @@ -1,15 +1,11 @@ class Robot { - constructor(height, width, posX, posY, scene, name = 'enemy') { - this.speed = SPEED_BASE + SPEED_BEGIN; - this.speedReload = SPEED_RELOAD_BASE + SPEED_RELOAD_BEGIN; - this.range = RANGE_BASE + RANGE_BEGIN; - this.damage = DAMAGE_BASE + DAMAGE_BEGIN; + constructor(height, width, x, y, scene, name = 'enemy', speed = SPEED_BEGIN, speedReload = SPEED_RELOAD_BEGIN, range = RANGE_BEGIN, damage = DAMAGE_BEGIN, lNode = []) { this.speedBonus = 1; this.name = name; this.height = height; this.width = width; - this.x = posX; - this.y = posY; + this.x = x; + this.y = y; this.life = new HealthBar(scene, selectWord("LIFE", "VIE"), this.width * 2, this.width / 3, this.x, this.y - this.width, LIFE, 0x008000); this.shield = new HealthBar(scene, selectWord("SHIELD", "BOUCLIER"), this.width * 2, this.width / 3, this.x, this.y - this.width * 1.5, SHIELD, 0x0000FF); this.circleRange = null; @@ -20,13 +16,18 @@ class Robot { this.addScene(scene); - this.lNode = []; + this.lNode = lNode; let condition = new Condition(true, true, false, 0.5, 0); condition.addNode(new Move(false)); this.addNode(condition); this.addNode(new Attack()); this.addNode(new Move(true)); + + this.setSpeed(speed); + this.setSpeedReload(speedReload); + this.setRange(range); + this.setDamage(damage); } addScene(scene) { diff --git a/Code/src/js/level2/Variable.js b/Code/src/js/level2/Variable.js index 8c44f85..6876b58 100644 --- a/Code/src/js/level2/Variable.js +++ b/Code/src/js/level2/Variable.js @@ -20,7 +20,8 @@ const OFFX_MAP = WIDTH_WINDOW / 20; const OFFY_MAP = (HEIGHT_WINDOW - WIDTH_MAP) / 2; const CENTERX_TREE = WIDTH_WINDOW / 4 * 3; const OFFX_TREE = WIDTH_WINDOW / 10; -const OFFY_TREE = HEIGHT_WINDOW / 6 +const OFFY_TREE = HEIGHT_WINDOW / 6; +const WIDTH_BUTTON = WIDTH_MAP / 10; const HEIGHT_NODE = HEIGHT_WINDOW / 6; diff --git a/Code/src/json/level1.json b/Code/src/json/level1.json index 02c96ac..d0630a4 100644 --- a/Code/src/json/level1.json +++ b/Code/src/json/level1.json @@ -9,7 +9,6 @@ false ] }, - { "type": "attack", "option": [ @@ -95,5 +94,113 @@ "PORTEE" ] ] - } + }, + "robots": [ + { + "height": 0.1, + "width": 0.1, + "x": 0.9, + "y": 0.9, + "name": "myself", + "speed": 3, + "speedReload": 1, + "range": 3, + "damage": 5, + "lNode": [ + ] + }, + { + "height": 0.1, + "width": 0.1, + "x": 0.1, + "y": 0.1, + "name": "enemy", + "speed": 3, + "speedReload": 1, + "range": 3, + "damage": 5, + "lNode": [ + { + "name": "condition", + "option": [ + true, + true, + false, + 0.5, + 0 + ], + "lNode": [ + { + "name": "move", + "option": [ + false + ] + } + ] + }, + { + "name": "attack", + "option": [ + ] + }, + { + "name": "move", + "option": [ + true + ] + } + ] + }, + { + "height": 0.1, + "width": 0.1, + "x": 0.1, + "y": 0.9, + "name": "enemy", + "speed": 3, + "speedReload": 1, + "range": 3, + "damage": 5, + "lNode": [ + { + "name": "condition", + "option": [ + true, + true, + false, + 0.5, + 0 + ], + "lNode": [ + { + "name": "move", + "option": [ + false + ] + } + ] + }, + { + "name": "attack", + "option": [ + ] + }, + { + "name": "move", + "option": [ + true + ] + } + ] + } + ], + "lBonus": [ + { + "style": "speed", + "x": 0.5, + "y": 0.5, + "value": 3, + "time": 2000 + } + ] } \ No newline at end of file diff --git a/Code/src/json/level2.json b/Code/src/json/level2.json index b1396fa..47c5289 100644 --- a/Code/src/json/level2.json +++ b/Code/src/json/level2.json @@ -94,5 +94,113 @@ "PORTEE" ] ] - } + }, + "robots": [ + { + "height": 0.1, + "width": 0.1, + "x": 0.6, + "y": 0.6, + "name": "myself", + "speed": 3, + "speedReload": 1, + "range": 3, + "damage": 5, + "lNode": [ + ] + }, + { + "height": 0.1, + "width": 0.1, + "x": 0.1, + "y": 0.1, + "name": "enemy", + "speed": 3, + "speedReload": 1, + "range": 3, + "damage": 5, + "lNode": [ + { + "name": "condition", + "option": [ + true, + true, + false, + 0.5, + 0 + ], + "lNode": [ + { + "name": "move", + "option": [ + false + ] + } + ] + }, + { + "name": "attack", + "option": [ + ] + }, + { + "name": "move", + "option": [ + true + ] + } + ] + }, + { + "height": 0.1, + "width": 0.1, + "x": 0.1, + "y": 0.9, + "name": "enemy", + "speed": 3, + "speedReload": 1, + "range": 3, + "damage": 5, + "lNode": [ + { + "name": "condition", + "option": [ + true, + true, + false, + 0.5, + 0 + ], + "lNode": [ + { + "name": "move", + "option": [ + false + ] + } + ] + }, + { + "name": "attack", + "option": [ + ] + }, + { + "name": "move", + "option": [ + true + ] + } + ] + } + ], + "lBonus": [ + { + "style": "speed", + "x": 0.5, + "y": 0.5, + "value": 2, + "time": 2000 + } + ] } \ No newline at end of file diff --git a/Code/src/json/level3.json b/Code/src/json/level3.json index d03af5f..4672296 100644 --- a/Code/src/json/level3.json +++ b/Code/src/json/level3.json @@ -94,5 +94,113 @@ "PORTEE" ] ] - } + }, + "robots": [ + { + "height": 0.1, + "width": 0.1, + "x": 0.9, + "y": 0.9, + "name": "myself", + "speed": 3, + "speedReload": 1, + "range": 3, + "damage": 5, + "lNode": [ + ] + }, + { + "height": 0.1, + "width": 0.1, + "x": 0.5, + "y": 0.1, + "name": "enemy", + "speed": 3, + "speedReload": 1, + "range": 3, + "damage": 5, + "lNode": [ + { + "name": "condition", + "option": [ + true, + true, + false, + 0.5, + 0 + ], + "lNode": [ + { + "name": "move", + "option": [ + false + ] + } + ] + }, + { + "name": "attack", + "option": [ + ] + }, + { + "name": "move", + "option": [ + true + ] + } + ] + }, + { + "height": 0.1, + "width": 0.1, + "x": 0.1, + "y": 0.9, + "name": "enemy", + "speed": 3, + "speedReload": 1, + "range": 3, + "damage": 5, + "lNode": [ + { + "name": "condition", + "option": [ + true, + true, + false, + 0.5, + 0 + ], + "lNode": [ + { + "name": "move", + "option": [ + false + ] + } + ] + }, + { + "name": "attack", + "option": [ + ] + }, + { + "name": "move", + "option": [ + true + ] + } + ] + } + ], + "lBonus": [ + { + "style": "speed", + "x": 0.5, + "y": 0.5, + "value": 1, + "time": 2000 + } + ] } \ No newline at end of file diff --git a/Code/src/json/level4.json b/Code/src/json/level4.json index 708f86f..1397281 100644 --- a/Code/src/json/level4.json +++ b/Code/src/json/level4.json @@ -94,5 +94,120 @@ "PORTEE" ] ] - } + }, + "robots": [ + { + "height": 0.1, + "width": 0.1, + "x": 0.9, + "y": 0.9, + "name": "myself", + "speed": 3, + "speedReload": 1, + "range": 3, + "damage": 5, + "lNode": [ + ] + }, + { + "height": 0.1, + "width": 0.1, + "x": 0.1, + "y": 0.1, + "name": "enemy", + "speed": 3, + "speedReload": 1, + "range": 3, + "damage": 5, + "lNode": [ + { + "name": "condition", + "option": [ + true, + true, + false, + 0.5, + 0 + ], + "lNode": [ + { + "name": "move", + "option": [ + false + ] + } + ] + }, + { + "name": "attack", + "option": [ + ] + }, + { + "name": "move", + "option": [ + true + ] + } + ] + }, + { + "height": 0.1, + "width": 0.1, + "x": 0.3, + "y": 0.5, + "name": "enemy", + "speed": 3, + "speedReload": 1, + "range": 3, + "damage": 5, + "lNode": [ + { + "name": "condition", + "option": [ + true, + true, + false, + 0.5, + 0 + ], + "lNode": [ + { + "name": "move", + "option": [ + false + ] + } + ] + }, + { + "name": "attack", + "option": [ + ] + }, + { + "name": "move", + "option": [ + true + ] + } + ] + } + ], + "lBonus": [ + { + "style": "speed", + "x": 0.5, + "y": 0.5, + "value": 3, + "time": 2000 + }, + { + "style": "speed", + "x": 0.6, + "y": 0.9, + "value": 2, + "time": 3000 + } + ] } \ No newline at end of file diff --git a/Code/src/json/level5.json b/Code/src/json/level5.json index e5f93d0..cddbf3a 100644 --- a/Code/src/json/level5.json +++ b/Code/src/json/level5.json @@ -75,5 +75,102 @@ "PORTEE" ] ] - } + }, + "robots": [ + { + "height": 0.1, + "width": 0.1, + "x": 0.9, + "y": 0.9, + "name": "myself", + "speed": 3, + "speedReload": 1, + "range": 3, + "damage": 5, + "lNode": [ + ] + }, + { + "height": 0.1, + "width": 0.1, + "x": 0.1, + "y": 0.1, + "name": "enemy", + "speed": 1, + "speedReload": 1, + "range": 5, + "damage": 5, + "lNode": [ + { + "name": "attack", + "option": [ + ] + }, + { + "name": "move", + "option": [ + true + ] + } + ] + }, + { + "height": 0.1, + "width": 0.1, + "x": 0.2, + "y": 0.2, + "name": "enemy", + "speed": 3, + "speedReload": 1, + "range": 3, + "damage": 5, + "lNode": [ + { + "name": "condition", + "option": [ + true, + true, + false, + 0.5, + 0 + ], + "lNode": [ + { + "name": "move", + "option": [ + false + ] + } + ] + }, + { + "name": "attack", + "option": [ + ] + }, + { + "name": "move", + "option": [ + true + ] + } + ] + } + ], + "lBonus": [ + { + "style": "speed", + "x": 0.5, + "y": 0.5, + "value": 1, + "time": 8000 + }, + { + "style": "speed", + "x": 0.2, + "y": 0.9, + "value": 3, + "time": 3000 + } + ] } \ No newline at end of file