diff --git a/Code/public/js/level2.min.js b/Code/public/js/level2.min.js index f15ba2a..6a50682 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,a,h,n,o=new CategoryBar,r=1,d){super(e,t,s,i,a,h,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,a){let h;switch(a){case 1:h="bonusAttack0";break;case 2:h="bonusAttack1";break;case 3:default:h="bonusAttack2"}super(e,t,s,i,h,a)}useOn(e){e.setAttackBonus(this.value+1),this.destroy()}}class BonusShield extends Bonus{constructor(e,t,s,i,a,h,n){let o;switch(a){case 75:o="bonusShield0";break;case 125:o="bonusShield1";break;case 200:default:o="bonusShield2"}super(e,t,s,i,o,a),this.time=h,this.color=n}useOn(e){let t=e.shield.color;e.shield.increaseValueMax(this.value,this.color),this.scene.time.addEvent({delay:this.time,callback:()=>e.shield.decreaseValueMax(this.value,t)}),this.destroy()}}class BonusSpeed extends Bonus{constructor(e="",t,s,i,a,h){let n;switch(a){case 1:n="bonusSpeed0";break;case 2:n="bonusSpeed1";break;case 3:default:n="bonusSpeed2"}super(e,t,s,i,n,a),this.time=h}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,a){this.text=t;let h={font:a.toString()+"px stencil",fill:"#e2e2e2"};this.textScene=e.add.text(s,i,this.text,h).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,a){this.shieldFilter=t,this.rangeFilter=s,this.shield=i,this.range=a,this.myself=e,this.lNode=[]}addNode(e){this.lNode.push(e)}do(e){if(this.doCondition(e))for(let t=0;t=a&&(s>a&&(s=a,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"),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")}create(){super.create();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.loadBonus(i),this.loadRobot(s),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 a=e.lRect.length,h=t-OFFX_TREE/2*(a-1),n=s+OFFY_TREE;e.lRect.forEach(e=>{i.addRect(this.loadTree(e,h,n)),h+=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);case"shield":return new BonusShield("",this.gm,WIDTH_MAP*e.x,WIDTH_MAP*e.y,e.value,e.time,e.color);default:return null}}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,a=this.add.sprite(10,10,"back").setOrigin(0,0).setInteractive();this.play=this.add.sprite(e,t,"play").setOrigin(1,0).setInteractive();let h=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(h,0,this.lineSpeed),this.father.sound.mute?this.lineMute=1:this.lineMute=0,this.changeFrame(o,0,this.lineMute),a.displayHeight=a.displayWidth=s,n.displayHeight=n.displayWidth=s,this.play.displayHeight=this.play.displayWidth=s,h.displayHeight=h.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)),h.on("pointerout",()=>this.changeFrame(h,0,this.lineSpeed)),h.on("pointerover",()=>this.changeFrame(h,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(a),this.creatBtnOutAndOver(this.pencil),this.creatBtnOutAndOver(this.bin),this.creatBtnOutAndOver(this.plus),this.play.on("pointerdown",()=>this.clickPlay()),h.on("pointerdown",()=>this.clickSpeed(h)),a.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(){let e=this.add.image(0,0,"background").setOrigin(0,0);e.alpha=.3,e.displayWidth=WIDTH_MAP,e.displayHeight=WIDTH_MAP,this.time.addEvent({delay:2e3,callback:this.upShield,callbackScope:this})}update(e,t){super.update(e,t),this.listRobot.forEach(function(e){e.read()});for(let e=0;et.addNode(e)),!0)}modifyValue(e,t,s,i){let a=this.getMyRobot();return void 0!==a&&(a.setSpeed(s),a.setRange(i),a.setSpeedReload(t),a.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,a,h){this.scene=e,this.posX=t,this.posY=s,this.width=i,this.height=a,this.category=new CategoryBar(h),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("bonusAttack0","bonus/",!0),this.loadImage("bonusAttack1","bonus/",!0),this.loadImage("bonusAttack2","bonus/",!0),this.loadImage("bonusShield0","bonus/",!0),this.loadImage("bonusShield1","bonus/",!0),this.loadImage("bonusShield2","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","others/",!0),this.loadImage("bullet","others/",!0),this.loadImage("logoWaria","others/",!0),this.loadImage("attack","nodes/",!0),this.loadImage("move","nodes/",!0),this.loadImage("condition","nodes/",!0)}loadSprite(e,t,s,i="",a=!1){this.deleteLoad(e),a?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),e.target=null),!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,a={font:(i/1.5).toString()+"px stencil",fill:"#e2e2e2"};this.add.text(e-s,t-i,selectWord("ATTACK","ATTAQUE"),a).setOrigin(.5,.5),this.add.text(e,t-i,selectWord("MOVE","DEPLACEMENT"),a).setOrigin(.5,.5),this.add.text(e+s,t-i,selectWord("CONDITION","CONDITION"),a).setOrigin(.5,.5);let h=this.add.sprite(e-s,t+i,"attack").setOrigin(.5,.5).setInteractive().on("pointerdown",()=>this.click("attack"));h.displayHeight=2*i,h.scaleX=h.scaleY,(h=this.add.sprite(e,t+i,"move").setOrigin(.5,.5).setInteractive().on("pointerdown",()=>this.click("move"))).displayHeight=2*i,h.scaleX=h.scaleY,(h=this.add.sprite(e+s,t+i,"condition").setOrigin(.5,.5).setInteractive().on("pointerdown",()=>this.click("condition"))).displayHeight=2*i,h.scaleX=h.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,a=[]){switch(i.toString().toLowerCase()){case"attack":this.rect=new Phaser.GameObjects.Image(s,e,t,"attackNode"),this.node=new Attack(a[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(a[0],a[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(a[0],a[1],a[2],a[3],a[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,a,h="enemy",n=SPEED_BEGIN,o=SPEED_RELOAD_BEGIN,r=RANGE_BEGIN,d=DAMAGE_BEGIN,l=[]){this.speedBonus=1,this.attackBonus=1,this.name=h,this.height=e,this.width=t,this.x=s,this.y=i,this.life=new HealthBar(a,selectWord("LIFE","VIE"),2*this.width,this.width/3,this.x,this.y-this.width,LIFE,32768),this.shield=new HealthBar(a,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(a,"bullet",this.width/5,this.width/4),a.add.existing(this.missile),this.addScene(a),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}setAttackBonus(e){this.attackBonus=e}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),a=i[0]+this.x,h=i[1]+this.y;return i[0]>=0&&a>=e.x||i[0]<=0&&a<=e.x?(this.setX(e.x),t=!0):this.setX(this.x+i[0]),i[1]>=0&&h>=e.y||i[1]<=0&&h<=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,a=e.y-this.y,h=Math.hypot(i,a);return s[0]=i/h*SPEED*this.speed*this.speedBonus*SPEED_GAME,s[1]=a/h*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*this.attackBonus*DAMAGE*t)&&this.setTarget(null),this.missile.setVisible(!1),1!==this.attackBonus&&this.setAttackBonus(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,a,h,n,o=new CategoryBar,r=1,d){super(e,t,s,i,a,h,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,a){let h;switch(a){case 1:h="bonusAttack0";break;case 2:h="bonusAttack1";break;case 3:default:h="bonusAttack2"}super(e,t,s,i,h,a)}useOn(e){e.setAttackBonus(this.value+1),this.destroy()}}class BonusShield extends Bonus{constructor(e,t,s,i,a,h,n){let o;switch(a){case 75:o="bonusShield0";break;case 125:o="bonusShield1";break;case 200:default:o="bonusShield2"}super(e,t,s,i,o,a),this.time=h,this.color=n}useOn(e){let t=e.shield.color;e.shield.increaseValueMax(this.value,this.color),this.scene.time.addEvent({delay:this.time,callback:()=>e.shield.decreaseValueMax(this.value,t)}),this.destroy()}}class BonusSpeed extends Bonus{constructor(e="",t,s,i,a,h){let n;switch(a){case 1:n="bonusSpeed0";break;case 2:n="bonusSpeed1";break;case 3:default:n="bonusSpeed2"}super(e,t,s,i,n,a),this.time=h}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,a){this.text=t;let h={font:a.toString()+"px stencil",fill:"#e2e2e2"};this.textScene=e.add.text(s,i,this.text,h).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,a){this.shieldFilter=t,this.rangeFilter=s,this.shield=i,this.range=a,this.myself=e,this.lNode=[]}addNode(e){this.lNode.push(e)}do(e){if(this.doCondition(e))for(let t=0;ts.setFrame(1)),s.on("pointerout",()=>s.setFrame(0)),s.on("pointerdown",()=>this.return()),s.displayHeight=HEIGHT_WINDOW/10,s.scaleX=s.scaleY;let i=WIDTH_WINDOW/3-20,a=HEIGHT_WINDOW/4*3;e=0,t=0,this.createCategoryBonus(e,0,i,a),this.createBonusDescription(e,0,i,a/3,"bonusShield0","BOUCLIER BRONZE","BONUS : +75 - TIME : 15"),this.createBonusDescription(e,a/3,i,a/3,"bonusShield1","BOUCLIER ARGENT","BONUS : +125 - TIME : 10"),this.createBonusDescription(e,a/1.5,i,a/3,"bonusShield2","BOUCLIER OR","BONUS : +200 - TIME : 5"),e=WIDTH_WINDOW/3,this.createCategoryBonus(e,0,i,a),this.createBonusDescription(e,0,i,a/3,"bonusSpeed0","VITESSE BRONZE","BONUS : x2 - TIME : 8"),this.createBonusDescription(e,a/3,i,a/3,"bonusSpeed1","VITESSE ARGENT","BONUS : x3 - TIME : 4"),this.createBonusDescription(e,a/1.5,i,a/3,"bonusSpeed2","VITESSE OR","BONUS : x4 - TIME : 2"),e=WIDTH_WINDOW/1.5,this.createCategoryBonus(e,0,i,a),this.createBonusDescription(e,0,i,a/3,"bonusAttack0","ATTAQUE BRONZE","BONUS : x2"),this.createBonusDescription(e,a/3,i,a/3,"bonusAttack1","ATTAQUE ARGENT","BONUS : x3"),this.createBonusDescription(e,a/1.5,i,a/3,"bonusAttack2","ATTAQUE OR","BONUS : x4")}createCategoryBonus(e,t,s,i){e+=10,t+=10,this.add.rectangle(e,t,s,i,8816262).setOrigin(0,0)}createBonusDescription(e,t,s,i,a,h,n){e+=20,t+=20,s-=20,i-=20,this.add.rectangle(e,t,s,i,16777215).setOrigin(0,0);let o=this.add.image(e,t,a).setOrigin(0,0);o.displayHeight=100,o.scaleX=o.scaleY;let r={font:o.displayHeight/2-h.length+"px stencil",fill:"#000000"};this.add.text(e+o.displayWidth+10,t+o.displayHeight/2,h.toString(),r).setOrigin(0,.5),r.font=i/6+"px stencil",this.add.text(e,t+o.displayHeight+(i-o.displayHeight)/2,n.toString(),r).setOrigin(0,.5)}return(){this.father.scene.start("Game"),this.father.scene.remove("Description")}}function selectWord(e,t){switch(LANG){case"fr":return t;default:return e}}function newGame(e,t,s=new Game(e,t)){-1!==e.scene.getIndex("Game")&&e.scene.remove("Game"),e.scene.add("Game",s)}function chooseTarget(e,t){let s=2*WIDTH_MAP,i=[];return t.forEach(function(t){if(t!==e){let a=Math.hypot(t.x-e.x,t.y-e.y);s>=a&&(s>a&&(s=a,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}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"),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")}create(){super.create();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.loadBonus(i),this.loadRobot(s),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 a=e.lRect.length,h=t-OFFX_TREE/2*(a-1),n=s+OFFY_TREE;e.lRect.forEach(e=>{i.addRect(this.loadTree(e,h,n)),h+=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);case"shield":return new BonusShield("",this.gm,WIDTH_MAP*e.x,WIDTH_MAP*e.y,e.value,e.time,e.color);default:return null}}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,a=this.add.sprite(10,10,"back").setOrigin(0,0).setInteractive();this.play=this.add.sprite(e,t,"play").setOrigin(1,0).setInteractive();let h=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(h,0,this.lineSpeed),this.father.sound.mute?this.lineMute=1:this.lineMute=0,this.changeFrame(o,0,this.lineMute),a.displayHeight=a.displayWidth=s,n.displayHeight=n.displayWidth=s,this.play.displayHeight=this.play.displayWidth=s,h.displayHeight=h.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)),h.on("pointerout",()=>this.changeFrame(h,0,this.lineSpeed)),h.on("pointerover",()=>this.changeFrame(h,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(a),this.creatBtnOutAndOver(this.pencil),this.creatBtnOutAndOver(this.bin),this.creatBtnOutAndOver(this.plus),this.play.on("pointerdown",()=>this.clickPlay()),h.on("pointerdown",()=>this.clickSpeed(h)),a.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.father.scene.stop("GamingBoard"),this.father.scene.remove("GamingBoard"),this.father.scene.add("Description",new Description(this.father,this)),this.scene.start("Description")}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(){let e=this.add.image(0,0,"background").setOrigin(0,0);e.alpha=.3,e.displayWidth=WIDTH_MAP,e.displayHeight=WIDTH_MAP,this.time.addEvent({delay:2e3,callback:this.upShield,callbackScope:this})}update(e,t){super.update(e,t),this.listRobot.forEach(function(e){e.read()});for(let e=0;et.addNode(e)),!0)}modifyValue(e,t,s,i){let a=this.getMyRobot();return void 0!==a&&(a.setSpeed(s),a.setRange(i),a.setSpeedReload(t),a.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,a,h){this.scene=e,this.posX=t,this.posY=s,this.width=i,this.height=a,this.category=new CategoryBar(h),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("bonusAttack0","bonus/",!0),this.loadImage("bonusAttack1","bonus/",!0),this.loadImage("bonusAttack2","bonus/",!0),this.loadImage("bonusShield0","bonus/",!0),this.loadImage("bonusShield1","bonus/",!0),this.loadImage("bonusShield2","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","others/",!0),this.loadImage("bullet","others/",!0),this.loadImage("logoWaria","others/",!0),this.loadImage("attack","nodes/",!0),this.loadImage("move","nodes/",!0),this.loadImage("condition","nodes/",!0)}loadSprite(e,t,s,i="",a=!1){this.deleteLoad(e),a?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),e.target=null),!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,a={font:(i/1.5).toString()+"px stencil",fill:"#e2e2e2"};this.add.text(e-s,t-i,selectWord("ATTACK","ATTAQUE"),a).setOrigin(.5,.5),this.add.text(e,t-i,selectWord("MOVE","DEPLACEMENT"),a).setOrigin(.5,.5),this.add.text(e+s,t-i,selectWord("CONDITION","CONDITION"),a).setOrigin(.5,.5);let h=this.add.sprite(e-s,t+i,"attack").setOrigin(.5,.5).setInteractive().on("pointerdown",()=>this.click("attack"));h.displayHeight=2*i,h.scaleX=h.scaleY,(h=this.add.sprite(e,t+i,"move").setOrigin(.5,.5).setInteractive().on("pointerdown",()=>this.click("move"))).displayHeight=2*i,h.scaleX=h.scaleY,(h=this.add.sprite(e+s,t+i,"condition").setOrigin(.5,.5).setInteractive().on("pointerdown",()=>this.click("condition"))).displayHeight=2*i,h.scaleX=h.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,a=[]){switch(i.toString().toLowerCase()){case"attack":this.rect=new Phaser.GameObjects.Image(s,e,t,"attackNode"),this.node=new Attack(a[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(a[0],a[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(a[0],a[1],a[2],a[3],a[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,a,h="enemy",n=SPEED_BEGIN,o=SPEED_RELOAD_BEGIN,r=RANGE_BEGIN,d=DAMAGE_BEGIN,l=[]){this.speedBonus=1,this.attackBonus=1,this.name=h,this.height=e,this.width=t,this.x=s,this.y=i,this.life=new HealthBar(a,selectWord("LIFE","VIE"),2*this.width,this.width/3,this.x,this.y-this.width,LIFE,32768),this.shield=new HealthBar(a,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(a,"bullet",this.width/5,this.width/4),a.add.existing(this.missile),this.addScene(a),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),this.setX(this.x),this.setY(this.y)}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.life.setX(this.x),this.shield.setX(this.x),this.circle.setX(this.x),this.drawCircleRange()}setY(e){this.y=e;let t=this.y-this.width,s=this.y-1.5*this.width;t<0?(s=this.y+this.width-this.shield.height,t=this.y+1.5*this.width-this.shield.height):s<0&&(s=t,t=this.y+this.width-this.shield.height),this.life.setY(t),this.shield.setY(s),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}setAttackBonus(e){this.attackBonus=e}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),a=i[0]+this.x,h=i[1]+this.y;return i[0]>=0&&a>=e.x||i[0]<=0&&a<=e.x?(this.setX(e.x),t=!0):this.setX(this.x+i[0]),i[1]>=0&&h>=e.y||i[1]<=0&&h<=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,a=e.y-this.y,h=Math.hypot(i,a);return s[0]=i/h*SPEED*this.speed*this.speedBonus*SPEED_GAME,s[1]=a/h*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*this.attackBonus*DAMAGE*t)&&this.setTarget(null),this.missile.setVisible(!1),1!==this.attackBonus&&this.setAttackBonus(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 returnBtn.setFrame(1)); + returnBtn.on('pointerout', () => returnBtn.setFrame(0)); + returnBtn.on('pointerdown', () => this.return()); + returnBtn.displayHeight = HEIGHT_WINDOW / 10; + returnBtn.scaleX = returnBtn.scaleY; + + let width = WIDTH_WINDOW / 3 - 20; + let height = HEIGHT_WINDOW / 4 * 3; + x = 0; + y = 0; + this.createCategoryBonus(x, 0, width, height); + this.createBonusDescription(x, 0, width, height / 3, 'bonusShield0', 'BOUCLIER BRONZE', 'BONUS : +75 - TIME : 15'); + this.createBonusDescription(x, height / 3, width, height / 3, 'bonusShield1', 'BOUCLIER ARGENT', 'BONUS : +125 - TIME : 10'); + this.createBonusDescription(x, height / 1.5, width, height / 3, 'bonusShield2', 'BOUCLIER OR', 'BONUS : +200 - TIME : 5'); + x = WIDTH_WINDOW / 3; + this.createCategoryBonus(x, 0, width, height); + this.createBonusDescription(x, 0, width, height / 3, 'bonusSpeed0', 'VITESSE BRONZE', 'BONUS : x2 - TIME : 8'); + this.createBonusDescription(x, height / 3, width, height / 3, 'bonusSpeed1', 'VITESSE ARGENT', 'BONUS : x3 - TIME : 4'); + this.createBonusDescription(x, height / 1.5, width, height / 3, 'bonusSpeed2', 'VITESSE OR', 'BONUS : x4 - TIME : 2'); + x = WIDTH_WINDOW / 1.5; + this.createCategoryBonus(x, 0, width, height); + this.createBonusDescription(x, 0, width, height / 3, 'bonusAttack0', 'ATTAQUE BRONZE', 'BONUS : x2'); + this.createBonusDescription(x, height / 3, width, height / 3, 'bonusAttack1', 'ATTAQUE ARGENT', 'BONUS : x3'); + this.createBonusDescription(x, height / 1.5, width, height / 3, 'bonusAttack2', 'ATTAQUE OR', 'BONUS : x4'); + + } + + createCategoryBonus(x, y, width, height) { + x += 10; + y += 10; + this.add.rectangle(x, y, width, height, 0x868686).setOrigin(0, 0); + } + + createBonusDescription(x, y, width, height, texture, name, text) { + x += 20; + y += 20; + width -= 20; + height -= 20; + this.add.rectangle(x, y, width, height, 0xFFFFFF).setOrigin(0, 0); + let image = this.add.image(x, y, texture).setOrigin(0, 0); + image.displayHeight = 100; + image.scaleX = image.scaleY; + let style = {font: (image.displayHeight / 2 - name.length) + 'px stencil', fill: "#000000"}; + this.add.text(x + image.displayWidth + 10, y + image.displayHeight / 2, name.toString(), style).setOrigin(0, 0.5); + style.font = (height / 6) + 'px stencil'; + this.add.text(x, y + image.displayHeight + (height - image.displayHeight) / 2, text.toString(), style).setOrigin(0, 0.5); + } + + return() { + this.father.scene.start('Game'); + this.father.scene.remove('Description'); + } +} \ No newline at end of file diff --git a/Code/src/js/level2/Game.js b/Code/src/js/level2/Game.js index 0309f1b..237f251 100644 --- a/Code/src/js/level2/Game.js +++ b/Code/src/js/level2/Game.js @@ -1,5 +1,3 @@ -var tree = undefined; - class Game extends ManageLang { constructor(father, level = "level1") { super('Game', father); @@ -316,12 +314,20 @@ class Game extends ManageLang { } clickSave() { + this.father.scene.stop('GamingBoard'); + this.father.scene.remove('GamingBoard'); + this.father.scene.add('Description', new Description(this.father, this)); + + this.scene.start('Description'); + + /* let sortDesc = (a, b) => a.getX() - b.getX(); this.tree.sort(sortDesc); let tree = this.tree.getJson(); let initStat = this.initStat.getJson(); let json = '{' + '"tree":' + tree + ',"initStat":' + initStat + '}'; console.log(json); + */ } clickPlay() { diff --git a/Code/src/js/level2/Robot.js b/Code/src/js/level2/Robot.js index 9f4cf44..20f9c43 100644 --- a/Code/src/js/level2/Robot.js +++ b/Code/src/js/level2/Robot.js @@ -29,6 +29,9 @@ class Robot { this.setSpeedReload(speedReload); this.setRange(range); this.setDamage(damage); + + this.setX(this.x); + this.setY(this.y); } addScene(scene) { @@ -56,16 +59,27 @@ class Robot { setX(x) { this.x = x; - this.circle.setX(this.x); this.life.setX(this.x); this.shield.setX(this.x); + this.circle.setX(this.x); this.drawCircleRange(); } setY(y) { this.y = y; - this.life.setY(this.y - this.width); - this.shield.setY(this.y - this.width * 1.5); + let yLife = this.y - this.width; + let yShield = this.y - this.width * 1.5; + if (yLife < 0) { + yShield = this.y + this.width - this.shield.height; + yLife = this.y + this.width * 1.5 - this.shield.height; + } else { + if (yShield < 0) { + yShield = yLife; + yLife = this.y + this.width - this.shield.height; + } + } + this.life.setY(yLife); + this.shield.setY(yShield); this.circle.setY(this.y); this.drawCircleRange(); } diff --git a/Code/src/json/level4.json b/Code/src/json/level4.json index 1397281..41866a2 100644 --- a/Code/src/json/level4.json +++ b/Code/src/json/level4.json @@ -207,7 +207,7 @@ "x": 0.6, "y": 0.9, "value": 2, - "time": 3000 + "time": 4000 } ] } \ No newline at end of file