diff --git a/Code/assets/en/buttons/modify.png b/Code/assets/en/buttons/modify.png new file mode 100644 index 0000000..21bdca4 Binary files /dev/null and b/Code/assets/en/buttons/modify.png differ diff --git a/Code/assets/fr/buttons/modify.png b/Code/assets/fr/buttons/modify.png new file mode 100644 index 0000000..2783a2d Binary files /dev/null and b/Code/assets/fr/buttons/modify.png differ diff --git a/Code/public/js/level2.min.js b/Code/public/js/level2.min.js index c07935f..bc9239a 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){super(e,t,s)}create(){console.log("ATTACK"),super.create(this),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())}}class AddCondition extends AddNode{constructor(e,t,s){super(e,t,s)}create(){super.create(this),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/3,HEIGHT_WINDOW/(16/9),"shield0",t,0),super.addButton(WIDTH_WINDOW/1.5,HEIGHT_WINDOW/(16/9),"shield33",t,1/3),super.addButton(WIDTH_WINDOW/3,HEIGHT_WINDOW/(16/12),"shield66",t,2/3),super.addButton(WIDTH_WINDOW/1.5,HEIGHT_WINDOW/(16/12),"shield100",t,1)}addNode(){super.verifyCategory()&&(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)),super.cancel())}}class AddMove extends AddNode{constructor(e,t,s){super(e,t,s)}create(){console.log("MOVE"),super.create(this),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())}}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}}class Bar extends HealthBar{constructor(e,t="",s,i,h,a,n,r=new CategoryBar,o=1,d){super(e,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),l={font:i.toString()+"px stencil",fill:"#000000"},this.scene.add.text(h+5,a,this.name,l).setOrigin(0,0).alpha=.5,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)}}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,t,s,i,h,a=VALUE_MAX_BAR,n=1){this.startValue=n,this.valueMax=a,this.point=this.valueMax,this.text=t;let r={font:h.toString()+"px stencil",fill:"#e2e2e2"};this.textScene=e.add.text(s,i,this.text,r).setOrigin(0,0),this.draw()}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()}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]}var tree=void 0;class Game extends ManageLang{constructor(e,t){super("Game",e),super.addOtherScenes("GamingBoard"),SPEED_GAME=1,void 0!==t&&(this.tree=JSON.parse(t),this.loadSave(this.tree))}create(){super.create(),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;let e=new CategoryBar(this,selectWord("TOKEN : ","JETON : "),OFFX_MAP+WIDTH_MAP+5,OFFY_MAP+180,30,10);this.damageRobot=new Bar(this,selectWord("DAMAGE","DEGAT"),200,30,OFFX_MAP+WIDTH_MAP+5,OFFY_MAP,COLOR_ATTACK,e,DAMAGE_BEGIN,5),this.speedReloadRobot=new Bar(this,selectWord("R.S","V.R."),200,30,OFFX_MAP+WIDTH_MAP+5,OFFY_MAP+45,COLOR_SPEED_RELOAD,e,SPEED_RELOAD_BEGIN,5),this.speedRobot=new Bar(this,selectWord("SPEED","VITESSE"),200,30,OFFX_MAP+WIDTH_MAP+5,OFFY_MAP+90,COLOR_MOVE,e,SPEED_BEGIN,5),this.rangeRobot=new Bar(this,selectWord("RANGE","PORTEE"),200,30,OFFX_MAP+WIDTH_MAP+5,OFFY_MAP+135,COLOR_RANGE,e,RANGE_BEGIN,5),this.createButton();let t=WIDTH_WINDOW/4*3,s=WIDTH_WINDOW/10;if(void 0===this.tree){this.tree=new RectangleNode(t,HEIGHT_WINDOW/10,this,"waria"),this.tree.addRect(new RectangleNode(t-2*s,HEIGHT_WINDOW/3,this,"move",!0,!1)),this.tree.addRect(new RectangleNode(t+s,HEIGHT_WINDOW/3,this,"move",!0)),this.tree.addRect(new RectangleNode(t,HEIGHT_WINDOW/3,this,"attack",1/3));let e=new RectangleNode(t-s,HEIGHT_WINDOW/3,this,"condition",!0,!0,!1,1/3,0);this.tree.addRect(e),e.addRect(new RectangleNode(t,HEIGHT_WINDOW/1.5,this,"move",!1)),e.addRect(new RectangleNode(t-s,HEIGHT_WINDOW/1.5,this,"attack"))}else{let e=this.tree.save();e=JSON.parse(e),this.loadSave(e)}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()})}update(e,t){super.update(e,t),this.doLine&&this.tree.updateLine()}loadSave(e){this.tree=this.loadTree(e)}loadTree(e){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}finish(){let e;console.log("FINISH"),e=this.gm.winner()?new Winner(this.father):new Looser(this.father),this.father.scene.add("Finish",e),this.scene.pause("Game"),this.scene.launch("Finish")}clickNode(){console.log("NODE"),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.speedRobot.value,this.rangeRobot.value,this.speedReloadRobot.value,this.damageRobot.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();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 n=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(n,0,this.lineMute),h.displayHeight=h.displayWidth=s,this.play.displayHeight=this.play.displayWidth=s,a.displayHeight=a.displayWidth=s,n.displayHeight=n.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)),n.on("pointerout",()=>this.changeFrame(n,0,this.lineMute)),n.on("pointerover",()=>this.changeFrame(n,1,this.lineMute)),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()),n.on("pointerdown",()=>this.clickMute(n)),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))}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(){console.log("PENCIL"),this.changeFrame(this.pencil,0)}clickBin(){null!==this.selected&&(console.log("BIN"),this.tree.delete(this.selected),this.changeFrame(this.bin,0),this.tryClick())}clickPlus(){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(e),h.setRange(t),h.setSpeedReload(s),h.setDamage(i),!0)}getMyRobot(){for(let e=0;ee.addShield(SHIELD_PER_SECOND)),this.time.addEvent({delay:1e3/SPEED_GAME,callback:this.upShield,callbackScope:this})}}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("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("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){super(e)}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}}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.option=h,this.type=i,this.rect.on("pointerdown",()=>this.click()),this.rect.setOrigin(.5,0),this.rect.displayHeight=HEIGHT_WINDOW/6,this.rect.scaleX=this.rect.scaleY}getSelected(){if(this.rect.isTinted)return this;if(this.canAddNode)for(let e=0;e0&&","===e[e.length-1]&&(e=e.substr(0,e.length-1)),e}save(){let e="{";return e+=this.toJson("x",this.rect.x)+this.toJson("y",this.rect.y)+this.toJson("type",this.type),e+='"option":[',this.option.forEach(t=>e+=t+","),e=this.endLineJson(e)+"],",this.canAddNode&&(e+='"lRect":[',this.lRect.forEach(t=>e+=t.save()+","),e=this.endLineJson(e)+"]"),e=this.endLineJson(e),e+="}",console.log(e),e}setLine(e,t){this.xOrigin=e,this.yOrigin=t,this.updateLine(!0)}updateLine(e=!1){!0!==e&&this.xLine===this.rect.x&&this.yLine===this.rect.y||void 0===this.line||(this.xLine=this.rect.x,this.yLine=this.rect.y,this.line.clear(),this.line.lineStyle(10,16777215,1),this.line.lineBetween(this.xOrigin,this.yOrigin,this.rect.x,this.rect.y+this.rect.displayHeight/10)),!0===this.canAddNode&&this.lRect.forEach(e=>this.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;tthis.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(){for(let e=0;ee.setFrame(0)),e.on("pointerover",()=>e.setFrame(1)),e.on("pointerdown",()=>this.clickPlay(e))}clickPlay(e){newGame(this.father),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}}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){super("Game",e),super.addOtherScenes("GamingBoard"),SPEED_GAME=1,void 0!==t&&(this.tree=JSON.parse(t),this.loadSave(this.tree))}create(){super.create(),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();let e=WIDTH_WINDOW/4*3,t=WIDTH_WINDOW/10;if(void 0===this.tree){this.initStat=new InitStat(this,OFFX_MAP+WIDTH_MAP+5,OFFY_MAP,200,30,10),this.initStat.addBar(DAMAGE_BEGIN,5,COLOR_ATTACK,["DAMAGE","DEGATS"]),this.initStat.addBar(SPEED_RELOAD_BEGIN,5,COLOR_SPEED_RELOAD,["R.S","RECHARGEMENT"]),this.initStat.addBar(SPEED_BEGIN,5,COLOR_MOVE,["SPEED","VITESSE"]),this.initStat.addBar(RANGE_BEGIN,5,COLOR_RANGE,["RANGE","PORTEE"]),this.tree=new RectangleNode(e,HEIGHT_WINDOW/10,this,"waria"),this.tree.addRect(new RectangleNode(e-2*t,HEIGHT_WINDOW/3,this,"move",[!0,!1])),this.tree.addRect(new RectangleNode(e+t,HEIGHT_WINDOW/3,this,"move",[!0])),this.tree.addRect(new RectangleNode(e,HEIGHT_WINDOW/3,this,"attack",[1/3]));let s=new RectangleNode(e-t,HEIGHT_WINDOW/3,this,"condition",[!0,!0,!1,1/3,0]);this.tree.addRect(s),s.addRect(new RectangleNode(e,HEIGHT_WINDOW/1.5,this,"move",[!1])),s.addRect(new RectangleNode(e-t,HEIGHT_WINDOW/1.5,this,"attack",[1]))}else{let e=this.tree.getJson();e=JSON.parse(e);let t=this.initStat.getJson();t=JSON.parse(t),this.loadSave(e,t)}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()})}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){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}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();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 n=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(n,0,this.lineMute),h.displayHeight=h.displayWidth=s,this.play.displayHeight=this.play.displayWidth=s,a.displayHeight=a.displayWidth=s,n.displayHeight=n.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)),n.on("pointerout",()=>this.changeFrame(n,0,this.lineMute)),n.on("pointerover",()=>this.changeFrame(n,1,this.lineMute)),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()),n.on("pointerdown",()=>this.clickMute(n)),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))}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(){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.father.scene.add("AddNode",new AddCondition(this.father,this,this.selected,this.selected.node.myself,this.selected.node.shield));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(){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("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}}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.option=h,this.type=i,this.rect.on("pointerdown",()=>this.click()),this.rect.setOrigin(.5,0),this.rect.displayHeight=HEIGHT_WINDOW/6,this.rect.scaleX=this.rect.scaleY}getSelected(){if(this.rect.isTinted)return this;if(this.canAddNode)for(let e=0;ee+=t+","),e=endLineJson(e)+"],",this.canAddNode&&(e+='"lRect":[',this.lRect.forEach(t=>e+=t.getJson()+","),e=endLineJson(e)+"]"),e=endLineJson(e),e+="}"}setLine(e,t){this.xOrigin=e,this.yOrigin=t,this.updateLine(!0)}updateLine(e=!1){!0!==e&&this.xLine===this.rect.x&&this.yLine===this.rect.y||void 0===this.line||(this.xLine=this.rect.x,this.yLine=this.rect.y,this.line.clear(),this.line.lineStyle(10,16777215,1),this.line.lineBetween(this.xOrigin,this.yOrigin,this.rect.x,this.rect.y+this.rect.displayHeight/10)),!0===this.canAddNode&&this.lRect.forEach(e=>this.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;tthis.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(){for(let e=0;ee.setFrame(0)),e.on("pointerover",()=>e.setFrame(1)),e.on("pointerdown",()=>this.clickPlay(e))}clickPlay(e){newGame(this.father),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_WINDOWthis.click(h,i,a)),h}createButton(t,e,s,i=this.heightButton,a=null){let h=this.add.image(t,e,s).setOrigin(.5,.5).setInteractive();return h.on("pointerover",()=>h.setFrame(1)),h.on("pointerout",()=>h.setFrame(0)),h.displayHeight=i,null===a?h.scaleX=h.scaleY:h.displayWidth=a,h}click(t,e,s){t.isTinted?e.remove(t):e.add(t,s)}newCategory(t,e,s){let i=new Category(t,e,s);return this.lCategory.push(i),i}addTitle(t,e,s){this.add.text(t,e,s,this.style).setOrigin(.5,.5)}createButtonCancel(){this.createButton(WIDTH_WINDOW/3,HEIGHT_WINDOW/(16/15),"cancel",HEIGHT_WINDOW/9).on("pointerdown",()=>this.cancel())}createButtonAdd(t){this.createButton(WIDTH_WINDOW/1.5,HEIGHT_WINDOW/(16/15),"add",HEIGHT_WINDOW/9).on("pointerdown",()=>t.addNode())}verifyCategory(){for(let t=0;ts.setFrame(1)),s.on("pointerout",()=>s.setFrame(0)),s.displayHeight=HEIGHT_WINDOW/9,s.scaleX=s.scaleY,s}btnRetry(t){t.on("pointerdown",()=>this.retry())}retry(){console.log("RETRY"),this.close(),newGame(this.father),this.father.scene.start("Game")}btnHome(t){t.on("pointerdown",()=>this.home())}home(){console.log("HOME"),this.close(),this.father.scene.start("Type")}btnNext(t){t.on("pointerdown",()=>this.next())}next(){console.log("NEXT")}close(){this.sound.stopAll(),this.father.scene.remove("GamingBoard"),this.father.scene.remove("Game"),this.father.scene.remove("Finish")}}class HealthBar{constructor(t,e,s,i,a,h,r,n=COLOR_RED,l=!0){this.bar=new Phaser.GameObjects.Graphics(t),this.width=Math.floor(e),this.height=Math.floor(s),this.valueMax=h,this.value=h,this.color=r,this.colorMin=n,this.draw(),this.setX(i,l),this.setY(a),t.add.existing(this.bar)}setValue(t){t<0&&(t=0),t>this.valueMax&&(t=this.valueMax),t!==this.value&&(this.value=t,this.draw())}decrease(t){this.value-=t;let e=0;return this.value<0&&(e=-this.value,this.value=0),this.draw(),e}getBar(){return this.bar}increase(t){this.value+=t,this.value>this.valueMax&&(this.value=this.valueMax),this.draw()}setX(t,e=!0){e?this.bar.setX(t-this.width/2):this.bar.setX(t)}setY(t){this.bar.setY(t)}draw(){this.bar.clear(),this.bar.fillStyle(0),this.bar.fillRect(0,0,this.width,this.height),this.bar.fillStyle(16777215),this.bar.fillRect(2,2,this.width-4,this.height-4);let t=this.value/this.valueMax;t<1/3?this.bar.fillStyle(this.colorMin):this.bar.fillStyle(this.color);let e=Math.floor(t*(this.width-4));this.bar.fillRect(2,2,e,this.height-4)}destroy(){this.bar.destroy()}}class ManageLang extends Phaser.Scene{constructor(t,e){super(t),this.name=t,this.father=e,this.otherScenes=[]}addOtherScenes(t){this.otherScenes.push(t)}create(){this.createFlags()}createFlags(){this.diffXFlag=0,this.createFlag("fr"),this.createFlag("en")}createFlag(t){let e=this.add.image(WIDTH_WINDOW-10-this.diffXFlag,10,t).setOrigin(1,0).setInteractive();e.displayHeight=40,e.scaleX=e.scaleY,this.diffXFlag=this.diffXFlag+e.displayWidth+10,e.on("pointerdown",()=>this.setLang(t))}setLang(t){t!==LANG&&(LANG=t,this.father.scene.add("LoadFile",new LoadFile(this.father,this.name)),this.father.scene.start("LoadFile"),this.otherScenes.forEach(t=>this.father.scene.stop(t)))}} \ No newline at end of file +class AddNode extends Phaser.Scene{constructor(t,e,s,i=[]){super("AddNode"),this.father=t,this.gameR=e,this.selected=s,this.lCategory=[];let a=HEIGHT_WINDOW/14;this.style={font:a.toString()+"px stencil",fill:"#e2e2e2"},this.heightButton=HEIGHT_WINDOW/8,this.lastCategory=null,this.option=i}create(){let t=HEIGHT_WINDOW/(4/3);this.add.rectangle(0,0,WIDTH_WINDOW,HEIGHT_WINDOW,0).setOrigin(0,0).setAlpha(.5),this.add.rectangle(0,HEIGHT_WINDOW/2,WIDTH_WINDOW,t,3487290).setOrigin(0,.5),this.createButtonCancel(),this.option.length>0?this.createButtonModify():this.createButtonAdd()}addButton(t,e,s,i=new Category,a){let h=this.createButton(t,e,s);return h.on("pointerdown",()=>this.click(h,i,a)),i!==this.lastCategory&&this.option.length>0&&this.option[0]===a&&(this.option.splice(0,1),this.lastCategory=i,this.click(h,i,a)),h}createButton(t,e,s,i=this.heightButton,a=null){let h=this.add.image(t,e,s).setOrigin(.5,.5).setInteractive();return h.on("pointerover",()=>h.setFrame(1)),h.on("pointerout",()=>h.setFrame(0)),h.displayHeight=i,null===a?h.scaleX=h.scaleY:h.displayWidth=a,h}click(t,e,s){t.isTinted?e.remove(t):e.add(t,s)}newCategory(t,e,s){let i=new Category(t,e,s);return this.lCategory.push(i),i}addTitle(t,e,s){this.add.text(t,e,s,this.style).setOrigin(.5,.5)}createButtonCancel(){this.createButton(WIDTH_WINDOW/3,HEIGHT_WINDOW/(16/15),"cancel",HEIGHT_WINDOW/9).on("pointerdown",()=>this.cancel())}createButtonAdd(){this.createButton(WIDTH_WINDOW/1.5,HEIGHT_WINDOW/(16/15),"add",HEIGHT_WINDOW/9).on("pointerdown",()=>this.addNode())}createButtonModify(){this.createButton(WIDTH_WINDOW/1.5,HEIGHT_WINDOW/(16/15),"modify",HEIGHT_WINDOW/9).on("pointerdown",()=>this.modifyNode())}verifyCategory(){for(let t=0;ts.setFrame(1)),s.on("pointerout",()=>s.setFrame(0)),s.displayHeight=HEIGHT_WINDOW/9,s.scaleX=s.scaleY,s}btnRetry(t){t.on("pointerdown",()=>this.retry())}retry(){this.close(),console.log("RETRY"),-1===this.father.scene.getIndex("Game")&&newGame(this.father),this.father.scene.start("Game")}btnHome(t){t.on("pointerdown",()=>this.home())}home(){console.log("HOME"),this.close(),this.father.scene.remove("Game"),this.father.scene.start("Type")}btnNext(t){t.on("pointerdown",()=>this.next())}next(){console.log("NEXT")}close(){this.sound.stopAll(),this.father.scene.remove("GamingBoard"),this.father.scene.remove("Finish")}}class HealthBar{constructor(t,e="",s,i,a,h,r,n,o=COLOR_RED,l=!0){this.bar=new Phaser.GameObjects.Graphics(t),this.width=Math.floor(s),this.height=Math.floor(i),this.valueMax=r,this.value=r,this.color=n,this.colorMin=o,this.draw(),t.add.existing(this.bar);let c={font:(i-=4).toString()+"px stencil",fill:"#000000"};this.nameText=t.add.text(a,h,e,c).setOrigin(0,0),this.nameText.alpha=.5,this.setX(a,l),this.setY(h)}setValue(t){t<0&&(t=0),t>this.valueMax&&(t=this.valueMax),t!==this.value&&(this.value=t,this.draw())}decrease(t){this.value-=t;let e=0;return this.value<0&&(e=-this.value,this.value=0),this.draw(),e}getBar(){return this.bar}increase(t){this.value+=t,this.value>this.valueMax&&(this.value=this.valueMax),this.draw()}setX(t,e=!0){e&&(t-=this.width/2),this.bar.setX(t),this.nameText.setX(t+5)}setY(t){this.bar.setY(t),this.nameText.setY(t)}draw(){this.bar.clear(),this.bar.fillStyle(0),this.bar.fillRect(0,0,this.width,this.height),this.bar.fillStyle(16777215),this.bar.fillRect(2,2,this.width-4,this.height-4);let t=this.value/this.valueMax;t<1/3?this.bar.fillStyle(this.colorMin):this.bar.fillStyle(this.color);let e=Math.floor(t*(this.width-4));this.bar.fillRect(2,2,e,this.height-4)}destroy(){this.bar.destroy(),this.nameText.destroy()}getJson(){let t="{";return t+=toJson("value",this.value)+toJson("valueMax",this.valueMax)+toJson("color",this.color)+toJson("colorMin",this.colorMin),t=endLineJson(t),t+="}"}}class ManageLang extends Phaser.Scene{constructor(t,e){super(t),this.name=t,this.father=e,this.otherScenes=[]}addOtherScenes(t){this.otherScenes.push(t)}create(){this.createFlags()}createFlags(){this.diffXFlag=0,this.createFlag("fr"),this.createFlag("en")}createFlag(t){let e=this.add.image(WIDTH_WINDOW-10-this.diffXFlag,10,t).setOrigin(1,0).setInteractive();e.displayHeight=40,e.scaleX=e.scaleY,this.diffXFlag=this.diffXFlag+e.displayWidth+10,e.on("pointerdown",()=>this.setLang(t))}setLang(t){t!==LANG&&(LANG=t,this.father.scene.add("LoadFile",new LoadFile(this.father,this.name)),this.father.scene.start("LoadFile"),this.otherScenes.forEach(t=>this.father.scene.stop(t)))}} \ No newline at end of file diff --git a/Code/src/js/level2/AddAttack.js b/Code/src/js/level2/AddAttack.js index 45e960d..04703df 100644 --- a/Code/src/js/level2/AddAttack.js +++ b/Code/src/js/level2/AddAttack.js @@ -1,11 +1,11 @@ class AddAttack extends AddNode { - constructor(father, game, selected) { - super(father, game, selected); + constructor(father, game, selected, ...option) { + super(father, game, selected, option); } create() { console.log("ATTACK"); - super.create(this); + 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)")); @@ -19,9 +19,16 @@ class AddAttack extends AddNode { addNode() { if (super.verifyCategory()) { - this.selected.addRect(new RectangleNode(this.selected.getX(), this.selected.getY() + 200, this.gameR, 'attack', this.lCategory[1].getValue())); + this.selected.addRect(new RectangleNode(this.selected.getX(), this.selected.getY() + 200, this.gameR, 'attack', [this.lCategory[1].getValue()])); super.cancel(); } } + modifyNode() { + if (super.verifyCategory()) { + this.selected.node.percentRange = this.lCategory[1].getValue(); + this.selected.rect.setFrame(this.selected.node.getFrame()); + super.cancel(); + } + } } \ No newline at end of file diff --git a/Code/src/js/level2/AddCondition.js b/Code/src/js/level2/AddCondition.js index edbea5d..9af1d5f 100644 --- a/Code/src/js/level2/AddCondition.js +++ b/Code/src/js/level2/AddCondition.js @@ -1,10 +1,10 @@ class AddCondition extends AddNode { - constructor(father, game, selected) { - super(father, game, selected); + constructor(father, game, selected, ...option) { + super(father, game, selected, option); } create() { - super.create(this); + 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 ?")); @@ -21,9 +21,17 @@ class AddCondition extends AddNode { addNode() { if (super.verifyCategory()) { - this.selected.addRect(new RectangleNode(this.selected.getX(), this.selected.getY() + 200, this.gameR, 'condition', this.lCategory[0].getValue(), true, false, this.lCategory[1].getValue(), 0)); + this.selected.addRect(new RectangleNode(this.selected.getX(), this.selected.getY() + 200, this.gameR, 'condition', [this.lCategory[0].getValue(), true, false, this.lCategory[1].getValue(), 0])); super.cancel(); } } + modifyNode() { + if (super.verifyCategory()) { + this.selected.node.myself = this.lCategory[0].getValue(); + this.selected.node.shield = this.lCategory[1].getValue(); + this.selected.rect.setFrame(this.selected.node.getFrame()); + super.cancel(); + } + } } \ No newline at end of file diff --git a/Code/src/js/level2/AddMove.js b/Code/src/js/level2/AddMove.js index f851471..fba7c55 100644 --- a/Code/src/js/level2/AddMove.js +++ b/Code/src/js/level2/AddMove.js @@ -1,11 +1,11 @@ class AddMove extends AddNode { - constructor(father, game, selected) { - super(father, game, selected); + constructor(father, game, selected, ...option) { + super(father, game, selected, option); } create() { console.log("MOVE"); - super.create(this); + 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 c1 = super.newCategory('direction', true, true); @@ -19,7 +19,16 @@ class AddMove extends AddNode { addNode() { if (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())); + 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() { + if (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(); } } diff --git a/Code/src/js/level2/Bar.js b/Code/src/js/level2/Bar.js index c3e2356..d230e55 100644 --- a/Code/src/js/level2/Bar.js +++ b/Code/src/js/level2/Bar.js @@ -1,9 +1,9 @@ class Bar extends HealthBar { constructor(scene, name = "", width, height, x, y, color, categoryBar = new CategoryBar(), value = 1, valueMax) { if (valueMax !== undefined) { - super(scene, width, height, x, y, valueMax, color, color, false); + super(scene, name, width, height, x, y, valueMax, color, color, false); } else { - super(scene, width, height, x, y, categoryBar.valueMax, color, color, false); + super(scene, name, width, height, x, y, categoryBar.valueMax, color, color, false); } this.name = name; this.scene = scene; @@ -11,9 +11,6 @@ class Bar extends HealthBar { let style = {font: height.toString() + 'px stencil', fill: "#e2e2e2"}; this.text = this.scene.add.text(this.bar.x + this.width + 10, this.bar.y, this.value.toString(), style).setOrigin(0, 0); - style = {font: height.toString() + 'px stencil', fill: "#000000"}; - let nameText = this.scene.add.text(x + 5, y, this.name, style).setOrigin(0, 0); - nameText.alpha = 0.5; this.categoryBar = categoryBar; this.setValue(0); this.categoryBar.setValueOf(this, value); @@ -52,7 +49,7 @@ class Bar extends HealthBar { this.bar.fillStyle(0x969696); this.bar.fillRect(posX, 0, 10, this.height); if (this.text !== undefined) { - this.text.setText(this.value); + this.text.setText(this.value + 1); } } } \ No newline at end of file diff --git a/Code/src/js/level2/CategoryBar.js b/Code/src/js/level2/CategoryBar.js index 666aab1..aa22c61 100644 --- a/Code/src/js/level2/CategoryBar.js +++ b/Code/src/js/level2/CategoryBar.js @@ -1,12 +1,8 @@ class CategoryBar { - constructor(scene, text, posX, posY, height, valueMax = VALUE_MAX_BAR, startValue = 1) { + constructor(valueMax = VALUE_MAX_BAR, startValue = 1) { this.startValue = startValue; this.valueMax = valueMax; this.point = this.valueMax; - this.text = text; - let style = {font: height.toString() + 'px stencil', fill: "#e2e2e2"}; - this.textScene = scene.add.text(posX, posY, this.text, style).setOrigin(0, 0); - this.draw(); } addPoint(point) { @@ -34,7 +30,24 @@ class CategoryBar { this.draw(); } - draw(){ + addText(scene, text, posX, posY, height) { + this.text = text; + let style = {font: height.toString() + 'px stencil', fill: "#e2e2e2"}; + this.textScene = scene.add.text(posX, posY, this.text, style).setOrigin(0, 0); + this.draw(); + } + + setTextPos(posX, posY) { + this.textScene.setX(posX); + this.textScene.setY(posY); + } + + setText(text) { + this.text = text; + this.draw(); + } + + draw() { this.textScene.setText(this.text + this.point); } } \ No newline at end of file diff --git a/Code/src/js/level2/Function.js b/Code/src/js/level2/Function.js index 71e59b7..694344a 100644 --- a/Code/src/js/level2/Function.js +++ b/Code/src/js/level2/Function.js @@ -7,11 +7,11 @@ function selectWord(en, fr) { } } -function newGame(father) { +function newGame(father, game = new Game(father)) { if (father.scene.getIndex('Game') !== -1) { father.scene.remove('Game'); } - father.scene.add('Game', new Game(father)); + father.scene.add('Game', game); } function chooseTarget(robot, list) { @@ -34,4 +34,29 @@ function chooseTarget(robot, list) { } else { return l[0]; } +} + +function toJson(name, value, end = false) { + let val; + switch (typeof value) { + case "string": + val = '"' + name.toString() + '":"' + value + '"'; + break; + default: + //console.log(typeof value); + val = '"' + name.toString() + '":' + value; + break; + } + if (!end) + val += ',' + return val; +} + +function endLineJson(json) { + if (json.length > 0) { + if (json[json.length - 1] === ",") { + json = json.substr(0, json.length - 1); + } + } + return json; } \ No newline at end of file diff --git a/Code/src/js/level2/Game.js b/Code/src/js/level2/Game.js index fd6be70..1c1f023 100644 --- a/Code/src/js/level2/Game.js +++ b/Code/src/js/level2/Game.js @@ -26,11 +26,6 @@ class Game extends ManageLang { let width = 200; let height = 30; - let c1 = new CategoryBar(this, selectWord("TOKEN : ", "JETON : "), OFFX_MAP + WIDTH_MAP + 5, OFFY_MAP + height * 6, height, 10); - this.damageRobot = new Bar(this, selectWord("DAMAGE", "DEGAT"), width, height, OFFX_MAP + WIDTH_MAP + 5, OFFY_MAP, COLOR_ATTACK, c1, DAMAGE_BEGIN, 5); - this.speedReloadRobot = new Bar(this, selectWord("R.S", "V.R."), width, height, OFFX_MAP + WIDTH_MAP + 5, OFFY_MAP + height * 1.5, COLOR_SPEED_RELOAD, c1, SPEED_RELOAD_BEGIN, 5); - this.speedRobot = new Bar(this, selectWord("SPEED", "VITESSE"), width, height, OFFX_MAP + WIDTH_MAP + 5, OFFY_MAP + height * 3, COLOR_MOVE, c1, SPEED_BEGIN, 5); - this.rangeRobot = new Bar(this, selectWord("RANGE", "PORTEE"), width, height, OFFX_MAP + WIDTH_MAP + 5, OFFY_MAP + height * 4.5, COLOR_RANGE, c1, RANGE_BEGIN, 5); this.createButton(); @@ -38,21 +33,31 @@ class Game extends ManageLang { let diffX = WIDTH_WINDOW / 10; if (this.tree === undefined) { + this.initStat = new InitStat(this, OFFX_MAP + WIDTH_MAP + 5, OFFY_MAP, width, height, 10); + this.initStat.addBar(DAMAGE_BEGIN, 5, COLOR_ATTACK, ["DAMAGE", "DEGATS"]); + this.initStat.addBar(SPEED_RELOAD_BEGIN, 5, COLOR_SPEED_RELOAD, ["R.S", "RECHARGEMENT"]); + this.initStat.addBar(SPEED_BEGIN, 5, COLOR_MOVE, ["SPEED", "VITESSE"]); + this.initStat.addBar(RANGE_BEGIN, 5, COLOR_RANGE, ["RANGE", "PORTEE"]); + this.tree = new RectangleNode(centerX, HEIGHT_WINDOW / 10, this, 'waria'); - this.tree.addRect(new RectangleNode(centerX - 2 * diffX, HEIGHT_WINDOW / 3, this, 'move', true, false)); - this.tree.addRect(new RectangleNode(centerX + diffX, HEIGHT_WINDOW / 3, this, 'move', true)); - this.tree.addRect(new RectangleNode(centerX, HEIGHT_WINDOW / 3, this, 'attack', 1 / 3)); + this.tree.addRect(new RectangleNode(centerX - 2 * diffX, HEIGHT_WINDOW / 3, this, 'move', [true, false])); + this.tree.addRect(new RectangleNode(centerX + diffX, HEIGHT_WINDOW / 3, this, 'move', [true])); + this.tree.addRect(new RectangleNode(centerX, HEIGHT_WINDOW / 3, this, 'attack', [1 / 3])); - let condition = new RectangleNode(centerX - diffX, HEIGHT_WINDOW / 3, this, 'condition', true, true, false, 1 / 3, 0); + let condition = new RectangleNode(centerX - diffX, HEIGHT_WINDOW / 3, this, 'condition', [true, true, false, 1 / 3, 0]); this.tree.addRect(condition); - condition.addRect(new RectangleNode(centerX, HEIGHT_WINDOW / 1.5, this, 'move', false)); - condition.addRect(new RectangleNode(centerX - diffX, HEIGHT_WINDOW / 1.5, this, 'attack')) + condition.addRect(new RectangleNode(centerX, HEIGHT_WINDOW / 1.5, this, 'move', [false])); + condition.addRect(new RectangleNode(centerX - diffX, HEIGHT_WINDOW / 1.5, this, 'attack', [1])) } else { - let save = this.tree.save(); - save = JSON.parse(save); - this.loadSave(save); + let tree = this.tree.getJson(); + tree = JSON.parse(tree); + + let initStat = this.initStat.getJson(); + initStat = JSON.parse(initStat); + + this.loadSave(tree, initStat); } @@ -73,8 +78,9 @@ class Game extends ManageLang { } - loadSave(save) { - this.tree = this.loadTree(save); + loadSave(tree, initStat) { + this.initStat = this.loadInitSave(initStat); + this.tree = this.loadTree(tree); } loadTree(element) { @@ -85,13 +91,24 @@ class Game extends ManageLang { return tree; } + loadInitSave(element) { + let width = 200; + let height = 30; + let initStat = new InitStat(this, OFFX_MAP + WIDTH_MAP + 5, OFFY_MAP, width, height, 10); + + 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]); + } + return initStat; + } + finish() { console.log("FINISH"); let winner; if (this.gm.winner()) { - winner = new Winner(this.father); + winner = new Winner(this.father, this); } else { - winner = new Looser(this.father); + winner = new Looser(this.father, this); } this.father.scene.add('Finish', winner); @@ -150,7 +167,7 @@ class Game extends ManageLang { let sortDesc = (a, b) => a.getX() - b.getX(); this.tree.sort(sortDesc); this.gm.modifyNodes(this.tree.getNode()); - this.gm.modifyValue(this.speedRobot.value, this.rangeRobot.value, this.speedReloadRobot.value, this.damageRobot.value); + 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(); } @@ -253,9 +270,23 @@ class Game extends ManageLang { clickPencil() { console.log("PENCIL"); - - this.changeFrame(this.pencil, 0); + switch (this.selected.type) { + case 'attack': + this.father.scene.add('AddNode', new AddAttack(this.father, this, this.selected, false, 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.father.scene.add('AddNode', new AddCondition(this.father, this, this.selected, this.selected.node.myself, this.selected.node.shield)) + break; + default: + return; + } + this.scene.pause('Game'); + this.scene.launch('AddNode'); + } clickBin() { diff --git a/Code/src/js/level2/GamingBoard.js b/Code/src/js/level2/GamingBoard.js index 30b0dee..b1723e1 100644 --- a/Code/src/js/level2/GamingBoard.js +++ b/Code/src/js/level2/GamingBoard.js @@ -30,7 +30,6 @@ class GamingBoard extends Phaser.Scene { update(time, delta) { super.update(time, delta); - console.log(delta); this.listRobot.forEach(function (robot) { robot.read(); }) @@ -85,7 +84,7 @@ class GamingBoard extends Phaser.Scene { return false; } - modifyValue(speed, range, speedReload, damage) { + modifyValue(damage, speedReload, speed, range) { let myRobot = this.getMyRobot(); if (myRobot !== undefined) { myRobot.setSpeed(speed); diff --git a/Code/src/js/level2/InitStat.js b/Code/src/js/level2/InitStat.js new file mode 100644 index 0000000..1d571ca --- /dev/null +++ b/Code/src/js/level2/InitStat.js @@ -0,0 +1,40 @@ +class InitStat { + constructor(scene, posX, posY, width, height, valueMax) { + this.scene = scene; + this.posX = posX; + this.posY = posY; + this.width = width; + this.height = height; + this.category = new CategoryBar(valueMax); + this.lBar = []; + this.lText = []; + this.category.addText(this.scene, selectWord("TOKENS : ", "JETONS : "), this.posX, this.posY, this.height); + } + + addBar(value, valueMax, color, text) { + this.lText.push(text); + this.lBar.push(new Bar(this.scene, selectWord(text[0], text[1]), this.width, this.height, this.posX, this.posY, color, this.category, value, valueMax)); + this.posY += this.height * 1.5; + this.category.setTextPos(this.posX, this.posY); + } + + getJson() { + let json = '{'; + json += '"lBar":['; + this.lBar.forEach(bar => json += bar.getJson() + ','); + json = endLineJson(json) + '],'; + json += '"lText":['; + this.lText.forEach(text => { + json += '['; + text.forEach(word => { + json += '"' + word + '",'; + }); + json = endLineJson(json); + json += '],'; + }); + json = endLineJson(json); + json += ']'; + json += '}'; + return json; + } +} \ No newline at end of file diff --git a/Code/src/js/level2/LoadFile.js b/Code/src/js/level2/LoadFile.js index c748f87..1933e17 100644 --- a/Code/src/js/level2/LoadFile.js +++ b/Code/src/js/level2/LoadFile.js @@ -50,6 +50,7 @@ class LoadFile extends Phaser.Scene { 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/'); diff --git a/Code/src/js/level2/Looser.js b/Code/src/js/level2/Looser.js index b467af9..474aead 100644 --- a/Code/src/js/level2/Looser.js +++ b/Code/src/js/level2/Looser.js @@ -1,6 +1,6 @@ class Looser extends Finish { - constructor(father) { - super(father); + constructor(father, game) { + super(father, game); } create() { diff --git a/Code/src/js/level2/RectangleNode.js b/Code/src/js/level2/RectangleNode.js index bc825ef..e58b933 100644 --- a/Code/src/js/level2/RectangleNode.js +++ b/Code/src/js/level2/RectangleNode.js @@ -1,5 +1,5 @@ class RectangleNode { - constructor(x, y, scene, type, ...option) { + constructor(x, y, scene, type, option = []) { switch (type.toString().toLowerCase()) { case 'attack': this.rect = new Phaser.GameObjects.Image(scene, x, y, 'attackNode'); @@ -96,43 +96,19 @@ class RectangleNode { } } - toJson(name, value, end = false) { - let val; - if (typeof value === "string") { - val = '"' + name.toString() + '":"' + value + '"'; - } else { - val = '"' + name.toString() + '":' + value; - } - if (!end) - val += ',' - return val; - } - - endLineJson(json) { - if (json.length > 0) { - if (json[json.length - 1] === ",") { - json = json.substr(0, json.length - 1); - } - } - return json; - } - - - save() { + getJson() { let json = '{'; - json += this.toJson("x", this.rect.x) + this.toJson("y", this.rect.y) + this.toJson("type", this.type); + json += toJson("x", this.rect.x) + toJson("y", this.rect.y) + toJson("type", this.type); json += '"option":['; this.option.forEach(option => json += option + ','); - json = this.endLineJson(json) + '],'; + json = endLineJson(json) + '],'; if (this.canAddNode) { json += '"lRect":['; - this.lRect.forEach(rect => json += rect.save() + ','); - json = this.endLineJson(json) + ']'; + this.lRect.forEach(rect => json += rect.getJson() + ','); + json = endLineJson(json) + ']'; } - json = this.endLineJson(json); + json = endLineJson(json); json += '}'; - - console.log(json) return json; } diff --git a/Code/src/js/level2/Robot.js b/Code/src/js/level2/Robot.js index db84d3e..bbd70d2 100644 --- a/Code/src/js/level2/Robot.js +++ b/Code/src/js/level2/Robot.js @@ -10,8 +10,8 @@ class Robot { this.width = width; this.x = posX; this.y = posY; - this.life = new HealthBar(scene, this.width * 2, this.width / 3, this.x, this.y - this.width, LIFE, 0x008000); - this.shield = new HealthBar(scene, this.width * 2, this.width / 3, this.x, this.y - this.width * 1.5, SHIELD, 0x0000FF); + this.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; this.canAttack = true; diff --git a/Code/src/js/level2/Winner.js b/Code/src/js/level2/Winner.js index c7d885c..f22f39d 100644 --- a/Code/src/js/level2/Winner.js +++ b/Code/src/js/level2/Winner.js @@ -1,6 +1,6 @@ class Winner extends Finish { - constructor(father) { - super(father); + constructor(father, game) { + super(father, game); } create() { diff --git a/Code/src/js/level3/AddNode.js b/Code/src/js/level3/AddNode.js index acb14bf..d460a99 100644 --- a/Code/src/js/level3/AddNode.js +++ b/Code/src/js/level3/AddNode.js @@ -1,5 +1,5 @@ class AddNode extends Phaser.Scene { - constructor(father, game, selected) { + constructor(father, game, selected, option = []) { super('AddNode'); this.father = father; this.gameR = game; @@ -8,20 +8,31 @@ class AddNode extends Phaser.Scene { let sizeText = HEIGHT_WINDOW / 14; this.style = {font: sizeText.toString() + 'px stencil', fill: "#e2e2e2"}; this.heightButton = HEIGHT_WINDOW / 8; + this.lastCategory = null; + this.option = option; } - create(son) { + create() { let height = HEIGHT_WINDOW / (4 / 3); this.add.rectangle(0, 0, WIDTH_WINDOW, HEIGHT_WINDOW, 0x000000).setOrigin(0, 0).setAlpha(0.5); this.add.rectangle(0, HEIGHT_WINDOW / 2, WIDTH_WINDOW, height, 0x35363A).setOrigin(0, 0.5); this.createButtonCancel(); - this.createButtonAdd(son); + if (this.option.length > 0) { + this.createButtonModify(); + } else { + this.createButtonAdd(); + } } addButton(x, y, texture, category = new Category(), value) { let btn = this.createButton(x, y, texture); btn.on('pointerdown', () => this.click(btn, category, value)); + if (category !== this.lastCategory && this.option.length > 0 && this.option[0] === value) { + this.option.splice(0, 1); + this.lastCategory = category; + this.click(btn, category, value); + } return btn; } @@ -62,9 +73,14 @@ class AddNode extends Phaser.Scene { .on('pointerdown', () => this.cancel()); } - createButtonAdd(son) { + createButtonAdd() { this.createButton(WIDTH_WINDOW / 1.5, HEIGHT_WINDOW / (16 / 15), 'add', HEIGHT_WINDOW / 9) - .on('pointerdown', () => son.addNode()); + .on('pointerdown', () => this.addNode()); + } + + createButtonModify() { + this.createButton(WIDTH_WINDOW / 1.5, HEIGHT_WINDOW / (16 / 15), 'modify', HEIGHT_WINDOW / 9) + .on('pointerdown', () => this.modifyNode()); } verifyCategory() { diff --git a/Code/src/js/level3/Finish.js b/Code/src/js/level3/Finish.js index 2d3be98..27f6806 100644 --- a/Code/src/js/level3/Finish.js +++ b/Code/src/js/level3/Finish.js @@ -1,7 +1,8 @@ class Finish extends Phaser.Scene { - constructor(father) { + constructor(father, game) { super('Finish'); this.father = father; + this.game = game; } create() { @@ -31,9 +32,11 @@ class Finish extends Phaser.Scene { } retry() { - console.log("RETRY"); this.close(); - newGame(this.father); + console.log("RETRY"); + if (this.father.scene.getIndex('Game') === -1) { + newGame(this.father); + } this.father.scene.start('Game'); } @@ -44,6 +47,7 @@ class Finish extends Phaser.Scene { home() { console.log("HOME"); this.close(); + this.father.scene.remove('Game'); this.father.scene.start('Type'); } @@ -58,7 +62,6 @@ class Finish extends Phaser.Scene { close() { this.sound.stopAll(); this.father.scene.remove('GamingBoard'); - this.father.scene.remove('Game'); this.father.scene.remove('Finish'); } } \ No newline at end of file diff --git a/Code/src/js/level3/HealthBar.js b/Code/src/js/level3/HealthBar.js index a5d1ebb..bef4420 100644 --- a/Code/src/js/level3/HealthBar.js +++ b/Code/src/js/level3/HealthBar.js @@ -1,5 +1,5 @@ class HealthBar { - constructor(scene, width, height, x, y, valueMax, color, colorMin = COLOR_RED, middle = true) { + constructor(scene, name = "", width, height, x, y, valueMax, color, colorMin = COLOR_RED, middle = true) { this.bar = new Phaser.GameObjects.Graphics(scene); this.width = Math.floor(width); @@ -11,9 +11,15 @@ class HealthBar { this.draw(); + scene.add.existing(this.bar); + + height = height - 4; + let style = {font: height.toString() + 'px stencil', fill: "#000000"}; + this.nameText = scene.add.text(x, y, name, style).setOrigin(0, 0); + this.nameText.alpha = 0.5; + this.setX(x, middle); this.setY(y); - scene.add.existing(this.bar); } setValue(value) { @@ -55,15 +61,16 @@ class HealthBar { this.draw(); } - setX(x, middle= true) { - if(middle) - this.bar.setX(x - this.width / 2); - else - this.bar.setX(x); + setX(x, middle = true) { + if (middle) + x = x - this.width / 2; + this.bar.setX(x); + this.nameText.setX(x + 5); } setY(y) { this.bar.setY(y); + this.nameText.setY(y); } draw() { @@ -93,5 +100,14 @@ class HealthBar { destroy() { this.bar.destroy(); + this.nameText.destroy(); + } + + getJson() { + let json = '{'; + json += toJson("value", this.value) + toJson("valueMax", this.valueMax) + toJson("color", this.color) + toJson("colorMin", this.colorMin); + json = endLineJson(json); + json += '}'; + return json; } } \ No newline at end of file