diff --git a/Code/public/js/level1.min.js b/Code/public/js/level1.min.js index fcdbfdf..685ec5d 100644 --- a/Code/public/js/level1.min.js +++ b/Code/public/js/level1.min.js @@ -1 +1 @@ -function selectWord(e,t){switch(LANG){case"fr":return t;default:return e}}function newGame(e){-1!==e.scene.getIndex("Game")&&e.scene.remove("Game"),e.scene.add("Game",new Game(e))}var LANG=navigator.language.substr(0,2).toLowerCase();const MYSELF="myself",SHIELD_PER_SECOND=5,COLOR_ATTACK=16711680,COLOR_MOVE=255,COLOR_CONDITION=921102,DURATION_DAMAGE=700,WIDTH_WINDOW=$(document).width()-20,HEIGHT_WINDOW=$(document).height()-20,WIDTH_MAP=WIDTH_WINDOW=o&&(n>o&&(n=o,a=[]),a.push(t))}}),a.length>1?a[Math.floor(Math.random()*(a.length+1))]:a[0]}var listBonus=[],LANG=navigator.language.substr(0,2).toLowerCase();const MYSELF="myself",SHIELD_PER_SECOND=5,COLOR_ATTACK=16711680,COLOR_MOVE=255,COLOR_CONDITION=921102,DURATION_DAMAGE=700,WIDTH_WINDOW=$(document).width()-20,HEIGHT_WINDOW=$(document).height()-20,WIDTH_MAP=WIDTH_WINDOW1/3?t>2/3?(t=1,this.percentBonus=1):(t=2/3,this.percentBonus=1.5):(t=1/3,this.percentBonus=2),this.percentRange=t}do(t){return!(!t.haveTarget()||!t.isTargetInRange(this.percentRange))&&t.attackTarget(this.percentBonus)}}class Boot extends Phaser.Scene{constructor(t){super("Boot"),this.father=t}preload(){let t=this.add.graphics(),e=this.add.graphics(),s=WIDTH_WINDOW/2-160,i=HEIGHT_WINDOW/2-25;e.fillStyle(2236962,.8),e.fillRect(s,i,320,50),this.load.on("progress",function(e){t.clear(),t.fillStyle(16777215,1),t.fillRect(s+10,i+10,300*e,30)}),this.load.on("complete",function(){t.destroy(),e.destroy()}),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.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("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("moveToward",300,150,"buttons/"),this.loadSprite("fleeFrom",300,150,"buttons/"),this.loadSprite("attackNode",180,190,"nodes/"),this.loadSprite("moveNode",180,190,"nodes/"),this.loadSprite("conditionNode",180,190,"nodes/"),this.loadImage("background"),this.loadImage("bullet"),this.loadImage("logoWaria"),this.loadImage("attack","nodes/"),this.loadImage("move","nodes/"),this.loadImage("condition","nodes/")}create(){this.add.text(WIDTH_WINDOW/2,HEIGHT_WINDOW/3,"WARIA",{font:"200px stencil",fill:"#e2e2e2"}).setOrigin(.5,.5);let t=this.add.sprite(WIDTH_WINDOW/2,HEIGHT_WINDOW/3*2,"playLetter").setInteractive();t.on("pointerout",()=>t.setFrame(0)),t.on("pointerover",()=>t.setFrame(1)),t.on("pointerdown",()=>this.clickPlay(t)),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,console.log("Set Lang : "+t),this.scene.restart())}clickPlay(t){t.setFrame(2),console.log("Play"),this.father.scene.add("Type",new Type(this.father)),this.scene.start("Type")}loadSprite(t,e,s,i="",h=!1){this.deleteLoad(t),h?this.load.spritesheet(t,"assets/"+i+t+".png",{frameWidth:e,frameHeight:s}):this.load.spritesheet(t,"assets/"+LANG+"/"+i+t+".png",{frameWidth:e,frameHeight:s})}loadImage(t,e="",s=!1){this.deleteLoad(t),s?this.load.image(t,"assets/"+e+t+".png"):this.load.image(t,"assets/"+LANG+"/"+e+t+".png")}deleteLoad(t){this.textures.exists(t)&&this.textures.remove(t)}}class Category{constructor(t="undefined",e=!0,s=!0){this.name=t,this.single=e,this.lBtn=[],this.lValue=[],this.obligatory=s}add(t,e){0!==this.lBtn.length&&this.single&&(this.lBtn[0].clearTint(),this.lValue=[],this.lBtn=[]),this.lValue.push(e),this.lBtn.push(t),t.tint=15718407}getValue(){return this.single?this.lValue[0]:this.lValue}validate(){return!(0===this.lBtn.length&&this.obligatory)}remove(t){let e=this.lBtn.indexOf(t);-1!==e&&(this.lBtn.splice(e,1),this.lValue.splice(e,1)),t.clearTint()}}class Condition{constructor(t,e=!1,s=!1,i,h){this.shieldFilter=e,this.rangeFilter=s,this.shield=i,this.range=h,this.myself=t,this.lNode=[]}addNode(t){this.lNode.push(t)}do(t){if(this.doCondition(t))for(let e=0;et.getX()-e.getX();this.tree.lRect.sort(t),this.tree.lRect.forEach(function(e){void 0!==e.lRect&&e.lRect.sort(t)}),this.gm.modifyNodes(this.tree.getNodes()),this.gm.resume()}changeFrame(t,e){t.setFrame(2*this.line+e)}createButton(){let t=WIDTH_MAP+WIDTH_WINDOW/10,e=WIDTH_MAP+HEIGHT_WINDOW/10+5,s=HEIGHT_WINDOW/10,i=HEIGHT_WINDOW/15,h=this.add.sprite(t,e,"play").setOrigin(1,0).setInteractive(),a=this.add.sprite(10,10,"back").setOrigin(0,0).setInteractive();this.pencil=this.add.sprite(t-s,e,"pencil").setOrigin(1,0).setInteractive().setVisible(!1),this.bin=this.add.sprite(t-2*s,e,"bin").setOrigin(1,0).setInteractive().setVisible(!1),this.plus=this.add.sprite(t-3*s,e,"plus").setOrigin(1,0).setInteractive().setVisible(!1),this.line=0,h.displayHeight=h.displayWidth=i,a.displayHeight=a.displayWidth=i,this.pencil.displayHeight=this.pencil.displayWidth=i,this.bin.displayHeight=this.bin.displayWidth=i,this.plus.displayHeight=this.plus.displayWidth=i,this.creatBtnOutAndOver(h),this.creatBtnOutAndOver(a),this.creatBtnOutAndOver(this.pencil),this.creatBtnOutAndOver(this.bin),this.creatBtnOutAndOver(this.plus),h.on("pointerdown",()=>this.clickPlay(h)),a.on("pointerdown",()=>this.clickBack()),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.pauseScene(h))}creatBtnOutAndOver(t){t.on("pointerout",()=>this.changeFrame(t,0)),t.on("pointerover",()=>this.changeFrame(t,1))}clickPlay(t){this.scene.isPaused("GamingBoard")?this.resume():this.pauseScene(t),this.changeFrame(t,1)}clickPencil(){console.log("PENCIL"),this.changeFrame(this.pencil,0)}clickBin(){console.log("BIN"),this.tree.delete(this.selected),this.changeFrame(this.bin,0)}clickPlus(){console.log("PLUS"),this.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")}}class GamingBoard extends Phaser.Scene{constructor(t){super("GamingBoard"),this.listRobot=[],this.father=t}preload(){this.cameras.main.setViewport(WIDTH_WINDOW/10,HEIGHT_WINDOW/10,WIDTH_MAP,WIDTH_MAP)}create(){this.end=!1,this.sound.add("shot"),this.sound.add("hit"),this.add.image(0,0,"background").alpha=.1;for(let t=0;tthis.resume()),this.time.addEvent({delay:2e3,callback:this.upShield,callbackScope:this})}update(t,e){super.update(t,e),this.listRobot.forEach(function(t){t.read()});for(let t=0;tthis.listRobot[0].addNode(t)),!0;return!1}chooseTarget(t){let e=2*WIDTH_MAP,s=[];this.listRobot.forEach(function(i){if(i!==t&&i.isAlive()){let h=Math.hypot(i.x-t.x,i.y-t.y);e>=h&&(e>h&&(e=h,s=[]),s.push(i))}}),this.listRobot.length>1?t.setTarget(s[Math.floor(Math.random()*(s.length+1))]):t.setTarget(s[0])}upShield(){this.listRobot.forEach(t=>t.addShield(SHIELD_PER_SECOND)),this.time.addEvent({delay:1e3,callback:this.upShield,callbackScope:this})}}class HealthBar{constructor(t,e,s,i,h,a,r){this.bar=new Phaser.GameObjects.Graphics(t),this.width=e,this.height=s,this.valueMax=a,this.value=a,this.color=r,this.draw(),this.setX(i),this.setY(h),t.add.existing(this.bar)}decrease(t){this.value-=t;let e=0;return this.value<0&&(e=-this.value,this.value=0),this.draw(),e}increase(t){this.value+=t,this.value>this.valueMax&&(this.value=this.valueMax),this.draw()}setX(t){this.bar.setX(t-this.width/2)}setY(t){this.bar.setY(t)}draw(){this.bar.clear(),this.bar.fillStyle(0),this.bar.fillRect(0,0,this.width,this.height),this.bar.fillStyle(16777215),this.bar.fillRect(2,2,this.width-4,this.height-4);let t=this.value/this.valueMax;t<1/3?this.bar.fillStyle(16711680):this.bar.fillStyle(this.color);let e=Math.floor(t*(this.width-4));this.bar.fillRect(2,2,e,this.height-4)}destroy(){this.bar.destroy()}}class Looser extends Finish{constructor(t){super(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(t,e,s,i){super(t,0,0,e),this.visible=!1,this.setOrigin(.5,.5),this.setScale(.02)}}class Move{constructor(t){this.toward=t}do(t){return!!t.haveTarget()&&(!0===this.toward?this.moveToward(t):this.fleeFrom(t))}moveToward(t){return t.advanceToTarget()}fleeFrom(t){return t.fleeFromTarget()}}class PlusNode extends Phaser.Scene{constructor(t,e,s){super("PlusNode"),this.father=t,this.gameR=e,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 t=WIDTH_WINDOW/2,e=HEIGHT_WINDOW/2,s=WIDTH_WINDOW/3,i=HEIGHT_WINDOW/10,h={font:i.toString()+"px stencil",fill:"#e2e2e2"};this.add.text(t-s,e-i,selectWord("ATTACK","ATTAQUE"),h).setOrigin(.5,.5),this.add.text(t,e-i,selectWord("MOVE","DEPLACEMENT"),h).setOrigin(.5,.5),this.add.text(t+s,e-i,selectWord("CONDITION","CONDITION"),h).setOrigin(.5,.5);let a=this.add.sprite(t-s,e+i,"attack").setOrigin(.5,.5).setInteractive().on("pointerdown",()=>this.click("attack"));a.displayHeight=2*i,a.scaleX=a.scaleY,(a=this.add.sprite(t,e+i,"move").setOrigin(.5,.5).setInteractive().on("pointerdown",()=>this.click("move"))).displayHeight=2*i,a.scaleX=a.scaleY,(a=this.add.sprite(t+s,e+i,"condition").setOrigin(.5,.5).setInteractive().on("pointerdown",()=>this.click("condition"))).displayHeight=2*i,a.scaleX=a.scaleY}click(t){switch(t.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 t=WIDTH_WINDOW/2,e=HEIGHT_WINDOW-100,s=this.add.image(t,e,"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(t,e,s,i,...h){switch(i.toString().toLowerCase()){case"attack":this.rect=new Phaser.GameObjects.Image(s,t,e,"attackNode"),this.node=new Attack(h[0]),this.canAddNode=!1,this.line=s.add.graphics(),console.log(3*this.node.percentRange),this.rect.setFrame(3*this.node.percentRange-1);break;case"move":this.rect=new Phaser.GameObjects.Image(s,t,e,"moveNode"),this.node=new Move(h[0]),this.canAddNode=!1,this.line=s.add.graphics(),!0===h[0]?this.rect.setFrame(0):this.rect.setFrame(2);break;case"condition":let a;this.rect=new Phaser.GameObjects.Image(s,t,e,"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(),a=h[0]?0:1;let r=0;!0===h[1]&&(r=Math.floor(3*h[3])),h[2],this.rect.setFrame(4*a+r);break;case"waria":this.rect=new Phaser.GameObjects.Image(s,t,e,"logoWaria").setInteractive(),this.canAddNode=!0,this.lRect=[],this.scene=s,this.scene.add.existing(this.rect);break;default:return void console.log("Création d'un node echoué")}i.toString().toLowerCase(),this.rect.on("pointerdown",()=>this.click()),this.rect.setOrigin(.5,0),this.rect.displayHeight=HEIGHT_WINDOW/6,this.rect.scaleX=this.rect.scaleY}getSelected(){if(this.rect.isTinted)return this;if(this.canAddNode)for(let t=0;tthis.addLine(t))}addLine(t){t.setLine(this.rect.x,this.rect.y+.9*this.rect.displayHeight)}getNodes(){if(void 0===this.node){let t=[];return this.lRect.forEach(function(e){void 0!==e.node&&(void 0!==e.lRect&&(e.node.clearNodes(),e.lRect.forEach(t=>e.node.addNode(t.node))),t.push(e.node))}),t}}destroy(){this.line.destroy(),this.rect.destroy(),void 0!==this.lRect&&this.lRect.forEach(t=>t.destroy())}delete(t){let e=this.lRect.indexOf(t);if(-1!==e)return this.lRect.splice(e,1),t.destroy(),!0;for(let e=0;ethis.click())}click(){null===this.circleRange?this.drawRange():this.eraseRange()}addShield(t){this.shield.increase(t)}setX(t){this.x=t,this.circle.setX(this.x),this.life.setX(this.x),this.shield.setX(this.x),this.drawCircleRange()}setY(t){this.y=t,this.life.setY(this.y-this.width),this.shield.setY(this.y-1.5*this.width),this.circle.setY(this.y),this.drawCircleRange()}setTarget(t){this.target=t,this.updateTarget()}updateTarget(){this.verifyTarget()&&this.setTargetPos(this.target.x,this.target.y)}setTargetPos(t,e){let s=this.target.x-this.x,i=this.target.y-this.y,h=Math.hypot(s,i);this.velocityX=s/h*WIDTH_MAP/1e3*SPEED*this.speed,this.velocityY=i/h*WIDTH_MAP/1e3*SPEED*this.speed}setSpeed(t){this.speed=t,this.updateTarget()}advanceToTarget(){return!!this.verifyTarget()&&(this.velocityX>=0&&this.x>=this.target.x||this.velocityX<=0&&this.x<=this.target.x?this.setX(this.target.x):this.setX(this.x+this.velocityX),this.velocityY>=0&&this.y>=this.target.y||this.velocityY<=0&&this.y<=this.target.y?this.setY(this.target.y):this.setY(this.y+this.velocityY),!0)}fleeFromTarget(){return!!this.verifyTarget()&&(this.velocityX>=0&&this.x-this.width/2<=0?this.setX(this.width/2):this.velocityX<=0&&this.x+this.width/2>=WIDTH_MAP?this.setX(WIDTH_MAP-this.width/2):this.setX(this.x-this.velocityX),this.velocityY>=0&&this.y-this.width/2<=0?this.setY(this.height/2):this.velocityY<=0&&this.y+this.width/2>=WIDTH_MAP?this.setY(WIDTH_MAP-this.height/2):this.setY(this.y-this.velocityY),!0)}attackTarget(t=0){return!!(this.verifyTarget()&&this.target.isAlive()&&this.isTargetInRange())&&(this.canAttack&&this.attack(this.target,t),!0)}verifyTarget(){return!!this.haveTarget()&&(!!this.target.isAlive()||(this.setTarget(null),!1))}attack(t,e){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;this.scene.tweens.add({targets:this.missile,x:t.x,y:t.y,ease:"Linear",duration:s,onComplete:()=>this.finishAttack(t,e)}),this.scene.time.addEvent({delay:Phaser.Math.Between(1e3,3e3),callback:this.reload,callbackScope:this})}finishAttack(t,e){t.beAttack(this.damage*e)&&this.setTarget(null),this.missile.setVisible(!1)}reload(){this.canAttack=!0}beAttack(t){let e=this.shield.decrease(t),s=this.scene.add.text(this.x,this.y,t.toString(),{font:"40px stencil",fill:"#ffff00"}).setOrigin(0,1);return this.scene.tweens.add({targets:s,x:this.x+30,y:this.y-50,alpha:0,duration:DURATION_DAMAGE,ease:"Sine.easeOut",onComplete:()=>s.destroy()}),this.scene.sound.play("hit"),console.log("HIT"),e>0&&(console.log("Shield Broken"),this.life.decrease(e)),this.die()}isTargetInRange(t=1){return!!this.verifyTarget()&&this.calcDistance(this.target)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 t=0;tt.setFrame(0)),t.on("pointerover",()=>t.setFrame(1)),t.on("pointerdown",()=>this.clickPlay(t))}clickPlay(t){newGame(this.father),this.scene.start("Game")}}class Winner extends Finish{constructor(t){super(t)}create(){super.create(),super.addTitle(selectWord("WINNER","PARTIE GAGNÉE")),super.btnRetry(super.createButton(WIDTH_WINDOW/4,"retry")),super.btnHome(super.createButton(WIDTH_WINDOW/2,"home")),super.btnNext(super.createButton(WIDTH_WINDOW/4*3,"next"))}} \ No newline at end of file +class AddAttack extends AddNode{constructor(t,e,s){super(t,e,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,null,HEIGHT_WINDOW/8,"enemyBot",super.newCategory("target",!0,!0),!1);let t=super.newCategory("range",!0,!0);super.addButton(WIDTH_WINDOW/3,HEIGHT_WINDOW/(16/9),null,HEIGHT_WINDOW/8,"shortRange",t,1/3),super.addButton(WIDTH_WINDOW/1.5,HEIGHT_WINDOW/(16/9),null,HEIGHT_WINDOW/8,"mediumRange",t,2/3),super.addButton(WIDTH_WINDOW/2,HEIGHT_WINDOW/(16/12),null,HEIGHT_WINDOW/8,"longRange",t,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(t,e,s){super(t,e,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 t=super.newCategory("target",!0,!0);super.addButton(WIDTH_WINDOW/3,HEIGHT_WINDOW/3.2,null,HEIGHT_WINDOW/8,"enemyBot",t,!1),super.addButton(WIDTH_WINDOW/1.5,HEIGHT_WINDOW/3.2,null,HEIGHT_WINDOW/8,"myself",t,!0);let e=super.newCategory("shield",!0,!0);super.addButton(WIDTH_WINDOW/3,HEIGHT_WINDOW/(16/9),null,HEIGHT_WINDOW/8,"shield0",e,0),super.addButton(WIDTH_WINDOW/1.5,HEIGHT_WINDOW/(16/9),null,HEIGHT_WINDOW/8,"shield33",e,1/3),super.addButton(WIDTH_WINDOW/3,HEIGHT_WINDOW/(16/12),null,HEIGHT_WINDOW/8,"shield66",e,2/3),super.addButton(WIDTH_WINDOW/1.5,HEIGHT_WINDOW/(16/12),null,HEIGHT_WINDOW/8,"shield100",e,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(t,e,s){super(t,e,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 t=super.newCategory("direction",!0,!0);super.addButton(WIDTH_WINDOW/6,HEIGHT_WINDOW/3.2,null,HEIGHT_WINDOW/8,"fleeFrom",t,!1),super.addButton(WIDTH_WINDOW/3,HEIGHT_WINDOW/3.2,null,HEIGHT_WINDOW/8,"moveToward",t,!0),super.addTitle(WIDTH_WINDOW/4*3,HEIGHT_WINDOW/(16/3),selectWord("WHO ?","QUI ?")),super.addButton(WIDTH_WINDOW/4*3,HEIGHT_WINDOW/3.2,null,HEIGHT_WINDOW/8,"enemyBot",super.newCategory("target",!0,!0),!1)}addNode(){super.verifyCategory()&&(this.selected.addRect(new RectangleNode(this.selected.getX(),this.selected.getY()+200,this.gameR,"move",this.lCategory[0].getValue())),super.cancel())}}class Attack{constructor(t=1){t>1/3?t>2/3?(t=1,this.percentBonus=1):(t=2/3,this.percentBonus=1.5):(t=1/3,this.percentBonus=2),this.percentRange=t}do(t){return!(!t.haveTarget()||!t.isTargetInRange(this.percentRange))&&t.attackTarget(this.percentBonus)}}class BonusAttack extends Bonus{constructor(t,e,s,i,h){super(t,e,s,i,"bonusAttack",h)}useOn(t){let e=t.speed;t.setSpeed(e+this.value),this.scene.time.addEvent({delay:this.time,callback:t.setSpeed(e)}),this.destroy()}}class BonusShield extends Bonus{constructor(t,e,s,i,h){super(t,e,s,i,"bonusShield",h)}useOn(t){t.shield.valueMax=t.shield.valueMax+this.value,t.shield.value=t.shield.value+this.val,this.destroy()}}class BonusSpeed extends Bonus{constructor(t,e,s,i,h,a){super(t,e,s,i,"play",h),this.time=a}useOn(t){t.increaseSpeed(this.value),this.scene.time.addEvent({delay:this.time,callback:()=>t.decreaseSpeed(this.value)}),this.destroy()}}class Boot extends Phaser.Scene{constructor(t){super("Boot"),this.father=t}preload(){let t=this.add.graphics(),e=this.add.graphics(),s=WIDTH_WINDOW/2-160,i=HEIGHT_WINDOW/2-25;e.fillStyle(2236962,.8),e.fillRect(s,i,320,50),this.load.on("progress",function(e){t.clear(),t.fillStyle(16777215,1),t.fillRect(s+10,i+10,300*e,30)}),this.load.on("complete",function(){t.destroy(),e.destroy()}),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.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("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("moveToward",300,150,"buttons/"),this.loadSprite("fleeFrom",300,150,"buttons/"),this.loadSprite("attackNode",180,190,"nodes/"),this.loadSprite("moveNode",180,190,"nodes/"),this.loadSprite("conditionNode",180,190,"nodes/"),this.loadImage("background"),this.loadImage("bullet"),this.loadImage("logoWaria"),this.loadImage("attack","nodes/"),this.loadImage("move","nodes/"),this.loadImage("condition","nodes/")}create(){this.add.text(WIDTH_WINDOW/2,HEIGHT_WINDOW/3,"WARIA",{font:"200px stencil",fill:"#e2e2e2"}).setOrigin(.5,.5);let t=this.add.sprite(WIDTH_WINDOW/2,HEIGHT_WINDOW/3*2,"playLetter").setInteractive();t.on("pointerout",()=>t.setFrame(0)),t.on("pointerover",()=>t.setFrame(1)),t.on("pointerdown",()=>this.clickPlay(t)),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,console.log("Set Lang : "+t),this.scene.restart())}clickPlay(t){t.setFrame(2),console.log("Play"),this.father.scene.add("Type",new Type(this.father)),this.scene.start("Type")}loadSprite(t,e,s,i="",h=!1){this.deleteLoad(t),h?this.load.spritesheet(t,"assets/"+i+t+".png",{frameWidth:e,frameHeight:s}):this.load.spritesheet(t,"assets/"+LANG+"/"+i+t+".png",{frameWidth:e,frameHeight:s})}loadImage(t,e="",s=!1){this.deleteLoad(t),s?this.load.image(t,"assets/"+e+t+".png"):this.load.image(t,"assets/"+LANG+"/"+e+t+".png")}deleteLoad(t){this.textures.exists(t)&&this.textures.remove(t)}}class Category{constructor(t="undefined",e=!0,s=!0){this.name=t,this.single=e,this.lBtn=[],this.lValue=[],this.obligatory=s}add(t,e){0!==this.lBtn.length&&this.single&&(this.lBtn[0].clearTint(),this.lValue=[],this.lBtn=[]),this.lValue.push(e),this.lBtn.push(t),t.tint=15718407}getValue(){return this.single?this.lValue[0]:this.lValue}validate(){return!(0===this.lBtn.length&&this.obligatory)}remove(t){let e=this.lBtn.indexOf(t);-1!==e&&(this.lBtn.splice(e,1),this.lValue.splice(e,1)),t.clearTint()}}class Condition{constructor(t,e=!1,s=!1,i,h){this.shieldFilter=e,this.rangeFilter=s,this.shield=i,this.range=h,this.myself=t,this.lNode=[]}addNode(t){this.lNode.push(t)}do(t){if(this.doCondition(t))for(let e=0;et.getX()-e.getX();this.tree.lRect.sort(t),this.tree.lRect.forEach(function(e){void 0!==e.lRect&&e.lRect.sort(t)}),this.gm.modifyNodes(this.tree.getNodes()),this.gm.resume()}changeFrame(t,e){t.setFrame(2*this.line+e)}createButton(){let t=WIDTH_MAP+WIDTH_WINDOW/10,e=WIDTH_MAP+HEIGHT_WINDOW/10+5,s=HEIGHT_WINDOW/10,i=HEIGHT_WINDOW/15,h=this.add.sprite(t,e,"play").setOrigin(1,0).setInteractive(),a=this.add.sprite(10,10,"back").setOrigin(0,0).setInteractive();this.pencil=this.add.sprite(t-s,e,"pencil").setOrigin(1,0).setInteractive().setVisible(!1),this.bin=this.add.sprite(t-2*s,e,"bin").setOrigin(1,0).setInteractive().setVisible(!1),this.plus=this.add.sprite(t-3*s,e,"plus").setOrigin(1,0).setInteractive().setVisible(!1),this.line=0,h.displayHeight=h.displayWidth=i,a.displayHeight=a.displayWidth=i,this.pencil.displayHeight=this.pencil.displayWidth=i,this.bin.displayHeight=this.bin.displayWidth=i,this.plus.displayHeight=this.plus.displayWidth=i,this.creatBtnOutAndOver(h),this.creatBtnOutAndOver(a),this.creatBtnOutAndOver(this.pencil),this.creatBtnOutAndOver(this.bin),this.creatBtnOutAndOver(this.plus),h.on("pointerdown",()=>this.clickPlay(h)),a.on("pointerdown",()=>this.clickBack()),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.pauseScene(h))}creatBtnOutAndOver(t){t.on("pointerout",()=>this.changeFrame(t,0)),t.on("pointerover",()=>this.changeFrame(t,1))}clickPlay(t){this.scene.isPaused("GamingBoard")?this.resume():this.pauseScene(t),this.changeFrame(t,1)}clickPencil(){console.log("PENCIL"),this.changeFrame(this.pencil,0)}clickBin(){console.log("BIN"),this.tree.delete(this.selected),this.changeFrame(this.bin,0)}clickPlus(){console.log("PLUS"),this.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")}}class GamingBoard extends Phaser.Scene{constructor(t){super("GamingBoard"),this.listRobot=[],listBonus=[],this.father=t,this.end=!1}preload(){this.cameras.main.setViewport(WIDTH_WINDOW/10,HEIGHT_WINDOW/10,WIDTH_MAP,WIDTH_MAP),this.sound.add("shot"),this.sound.add("hit")}create(){listBonus.push(new BonusSpeed("Balle Argent",this,WIDTH_MAP/2,WIDTH_MAP/2,3,2e3)),this.add.image(0,0,"background").alpha=.1;for(let t=0;tthis.resume()),this.time.addEvent({delay:2e3,callback:this.upShield,callbackScope:this})}update(t,e){super.update(t,e),this.listRobot.forEach(function(t){t.read()});for(let t=0;tthis.listRobot[0].addNode(t)),!0;return!1}upShield(){this.listRobot.forEach(t=>t.addShield(SHIELD_PER_SECOND)),this.time.addEvent({delay:1e3,callback:this.upShield,callbackScope:this})}}class HealthBar{constructor(t,e,s,i,h,a,r){this.bar=new Phaser.GameObjects.Graphics(t),this.width=e,this.height=s,this.valueMax=a,this.value=a,this.color=r,this.draw(),this.setX(i),this.setY(h),t.add.existing(this.bar)}decrease(t){this.value-=t;let e=0;return this.value<0&&(e=-this.value,this.value=0),this.draw(),e}increase(t){this.value+=t,this.value>this.valueMax&&(this.value=this.valueMax),this.draw()}setX(t){this.bar.setX(t-this.width/2)}setY(t){this.bar.setY(t)}draw(){this.bar.clear(),this.bar.fillStyle(0),this.bar.fillRect(0,0,this.width,this.height),this.bar.fillStyle(16777215),this.bar.fillRect(2,2,this.width-4,this.height-4);let t=this.value/this.valueMax;t<1/3?this.bar.fillStyle(16711680):this.bar.fillStyle(this.color);let e=Math.floor(t*(this.width-4));this.bar.fillRect(2,2,e,this.height-4)}destroy(){this.bar.destroy()}}class Looser extends Finish{constructor(t){super(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(t,e,s,i){super(t,0,0,e),this.visible=!1,this.setOrigin(.5,.5),this.setScale(.02)}}class Move{constructor(t,e=!0){this.toward=t,this.enemyBot=e}do(t){if(this.enemyBot){if(t.verifyTarget())return!0===this.toward?this.moveToward(t):this.fleeFrom(t)}else{let e=chooseTarget(t,listBonus);if(void 0!==e){let s;return(s=!0===this.toward?this.moveToward(t,e):this.fleeFrom(t,e))||(e.useOn(t),listBonus.splice(listBonus.indexOf(e),1)),!0}}return!1}moveToward(t,e=t.target){return t.advanceTo(e)}fleeFrom(t,e=t.target){return t.fleeFrom(e)}}class PlusNode extends Phaser.Scene{constructor(t,e,s){super("PlusNode"),this.father=t,this.gameR=e,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 t=WIDTH_WINDOW/2,e=HEIGHT_WINDOW/2,s=WIDTH_WINDOW/3,i=HEIGHT_WINDOW/10,h={font:i.toString()+"px stencil",fill:"#e2e2e2"};this.add.text(t-s,e-i,selectWord("ATTACK","ATTAQUE"),h).setOrigin(.5,.5),this.add.text(t,e-i,selectWord("MOVE","DEPLACEMENT"),h).setOrigin(.5,.5),this.add.text(t+s,e-i,selectWord("CONDITION","CONDITION"),h).setOrigin(.5,.5);let a=this.add.sprite(t-s,e+i,"attack").setOrigin(.5,.5).setInteractive().on("pointerdown",()=>this.click("attack"));a.displayHeight=2*i,a.scaleX=a.scaleY,(a=this.add.sprite(t,e+i,"move").setOrigin(.5,.5).setInteractive().on("pointerdown",()=>this.click("move"))).displayHeight=2*i,a.scaleX=a.scaleY,(a=this.add.sprite(t+s,e+i,"condition").setOrigin(.5,.5).setInteractive().on("pointerdown",()=>this.click("condition"))).displayHeight=2*i,a.scaleX=a.scaleY}click(t){switch(t.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 t=WIDTH_WINDOW/2,e=HEIGHT_WINDOW-100,s=this.add.image(t,e,"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(t,e,s,i,...h){switch(i.toString().toLowerCase()){case"attack":this.rect=new Phaser.GameObjects.Image(s,t,e,"attackNode"),this.node=new Attack(h[0]),this.canAddNode=!1,this.line=s.add.graphics(),console.log(3*this.node.percentRange),this.rect.setFrame(3*this.node.percentRange-1);break;case"move":this.rect=new Phaser.GameObjects.Image(s,t,e,"moveNode"),this.node=new Move(h[0],h[1]),this.canAddNode=!1,this.line=s.add.graphics(),!0===h[0]?this.rect.setFrame(0):this.rect.setFrame(2);break;case"condition":let a;this.rect=new Phaser.GameObjects.Image(s,t,e,"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(),a=h[0]?0:1;let r=0;!0===h[1]&&(r=Math.floor(3*h[3])),h[2],this.rect.setFrame(4*a+r);break;case"waria":this.rect=new Phaser.GameObjects.Image(s,t,e,"logoWaria").setInteractive(),this.canAddNode=!0,this.lRect=[],this.scene=s,this.scene.add.existing(this.rect);break;default:return void console.log("Création d'un node echoué")}i.toString().toLowerCase(),this.rect.on("pointerdown",()=>this.click()),this.rect.setOrigin(.5,0),this.rect.displayHeight=HEIGHT_WINDOW/6,this.rect.scaleX=this.rect.scaleY}getSelected(){if(this.rect.isTinted)return this;if(this.canAddNode)for(let t=0;tthis.addLine(t))}addLine(t){t.setLine(this.rect.x,this.rect.y+.9*this.rect.displayHeight)}getNodes(){if(void 0===this.node){let t=[];return this.lRect.forEach(function(e){void 0!==e.node&&(void 0!==e.lRect&&(e.node.clearNodes(),e.lRect.forEach(t=>e.node.addNode(t.node))),t.push(e.node))}),t}}destroy(){this.line.destroy(),this.rect.destroy(),void 0!==this.lRect&&this.lRect.forEach(t=>t.destroy())}delete(t){let e=this.lRect.indexOf(t);if(-1!==e)return this.lRect.splice(e,1),t.destroy(),!0;for(let e=0;ethis.click())}click(){null===this.circleRange?this.drawRange():this.eraseRange()}addShield(t){this.shield.increase(t)}setX(t){this.x=t,this.circle.setX(this.x),this.life.setX(this.x),this.shield.setX(this.x),this.drawCircleRange()}setY(t){this.y=t,this.life.setY(this.y-this.width),this.shield.setY(this.y-1.5*this.width),this.circle.setY(this.y),this.drawCircleRange()}setTarget(t){this.target=t}updateTarget(){this.verifyTarget()&&this.setTargetPos(this.target.x,this.target.y)}setTargetPos(t,e){}setSpeed(t){this.speed=t}increaseSpeed(t){this.speed+=t}decreaseSpeed(t){this.speed-=t}advanceToTarget(){return this.verifyTarget()&&this.advanceTo(this.target),!1}advanceTo(t){if(this.target.x!==this.x||this.target.y!==this.y){let e=!1,s=!1,i=this.getVelocity(t),h=i[0]+this.x,a=i[1]+this.y;return i[0]>=0&&h>=t.x||i[0]<=0&&h<=t.x?(this.setX(t.x),e=!0):this.setX(this.x+i[0]),i[1]>=0&&a>=t.y||i[1]<=0&&a<=t.y?(this.setY(t.y),s=!0):this.setY(this.y+i[1]),!(e&&s)}return!1}fleeFromTarget(){return!!this.verifyTarget()&&this.fleeFrom(this.target)}fleeFrom(t){if(this.target.x!==this.x||this.target.y!==this.y){let e=this.getVelocity(t);return e[0]>=0&&this.x-this.width/2<=0?this.setX(this.width/2):e[0]<=0&&this.x+this.width/2>=WIDTH_MAP?this.setX(WIDTH_MAP-this.width/2):this.setX(this.x-e[0]),e[1]>=0&&this.y-this.width/2<=0?this.setY(this.height/2):e[1]<=0&&this.y+this.width/2>=WIDTH_MAP?this.setY(WIDTH_MAP-this.height/2):this.setY(this.y-e[1]),!0}return!1}getVelocity(t){let e=[],s=t.x-this.x,i=t.y-this.y,h=Math.hypot(s,i);return e[0]=s/h*WIDTH_MAP/1e3*SPEED*this.speed,e[1]=i/h*WIDTH_MAP/1e3*SPEED*this.speed,e}attackTarget(t=0){return!!this.verifyTarget()&&(this.canAttack&&this.attack(this.target,t),!0)}verifyTarget(){return!!this.haveTarget()&&(!!this.target.isAlive()||(this.setTarget(null),!1))}attack(t,e){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;this.scene.tweens.add({targets:this.missile,x:t.x,y:t.y,ease:"Linear",duration:s,onComplete:()=>this.finishAttack(t,e)}),this.scene.time.addEvent({delay:Phaser.Math.Between(1e3,3e3),callback:this.reload,callbackScope:this})}finishAttack(t,e){t.beAttack(this.damage*e)&&this.setTarget(null),this.missile.setVisible(!1)}reload(){this.canAttack=!0}beAttack(t){let e=this.shield.decrease(t),s=this.scene.add.text(this.x,this.y,t.toString(),{font:"40px stencil",fill:"#ffff00"}).setOrigin(0,1);return this.scene.tweens.add({targets:s,x:this.x+30,y:this.y-50,alpha:0,duration:DURATION_DAMAGE,ease:"Sine.easeOut",onComplete:()=>s.destroy()}),this.scene.sound.play("hit"),console.log("HIT"),e>0&&(console.log("Shield Broken"),this.life.decrease(e)),this.die()}isTargetInRange(t=1){return!!this.haveTarget()&&this.calcDistance(this.target)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 t=0;tt.setFrame(0)),t.on("pointerover",()=>t.setFrame(1)),t.on("pointerdown",()=>this.clickPlay(t))}clickPlay(t){newGame(this.father),this.scene.start("Game")}}class Winner extends Finish{constructor(t){super(t)}create(){super.create(),super.addTitle(selectWord("YOU WIN","PARTIE GAGNÉE")),super.btnRetry(super.createButton(WIDTH_WINDOW/4,"retry")),super.btnHome(super.createButton(WIDTH_WINDOW/2,"home")),super.btnNext(super.createButton(WIDTH_WINDOW/4*3,"next"))}} \ No newline at end of file diff --git a/Code/public/js/level3.min.js b/Code/public/js/level3.min.js index 5acbbac..bca2c30 100644 --- a/Code/public/js/level3.min.js +++ b/Code/public/js/level3.min.js @@ -1 +1 @@ -class AddNode extends Phaser.Scene{constructor(e,t,n){super("AddNode"),this.father=e,this.gameR=t,this.selected=n,this.lCategory=[]}create(e){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.createButtonAdd(e)}addButton(e,t,n,s,i,r=new Category,o){let a=this.createButton(e,t,n,s,i);return a.on("pointerdown",()=>this.click(a,r,o)),a}createButton(e,t,n,s,i){let r=this.add.image(e,t,i).setOrigin(.5,.5).setInteractive();return r.on("pointerover",()=>r.setFrame(1)),r.on("pointerout",()=>r.setFrame(0)),r.displayHeight=s,null===n?r.scaleX=r.scaleY:r.displayWidth=n,r}click(e,t,n){e.isTinted?t.remove(e):t.add(e,n)}newCategory(e,t,n){let s=new Category(e,t,n);return this.lCategory.push(s),s}addTitle(e,t,n){let s={font:(HEIGHT_WINDOW/12).toString()+"px stencil",fill:"#e2e2e2"};this.add.text(e,t,n,s).setOrigin(.5,.5)}createButtonCancel(){this.createButton(WIDTH_WINDOW/3,HEIGHT_WINDOW/(16/15),null,HEIGHT_WINDOW/9,"cancel").on("pointerdown",()=>this.cancel())}createButtonAdd(e){this.createButton(WIDTH_WINDOW/1.5,HEIGHT_WINDOW/(16/15),null,HEIGHT_WINDOW/9,"add").on("pointerdown",()=>e.addNode())}verifyCategory(){for(let e=0;en.setFrame(1)),n.on("pointerout",()=>n.setFrame(0)),n.displayHeight=HEIGHT_WINDOW/9,n.scaleX=n.scaleY,n}btnRetry(e){e.on("pointerdown",()=>this.retry())}retry(){console.log("RETRY"),this.close(),newGame(this.father),this.father.scene.start("Game")}btnHome(e){e.on("pointerdown",()=>this.home())}home(){console.log("HOME"),this.close(),this.father.scene.start("Type")}btnNext(e){e.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")}} \ No newline at end of file +class AddNode extends Phaser.Scene{constructor(e,t,s){super("AddNode"),this.father=e,this.gameR=t,this.selected=s,this.lCategory=[]}create(e){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.createButtonAdd(e)}addButton(e,t,s,n,i,r=new Category,a){let o=this.createButton(e,t,s,n,i);return o.on("pointerdown",()=>this.click(o,r,a)),o}createButton(e,t,s,n,i){let r=this.add.image(e,t,i).setOrigin(.5,.5).setInteractive();return r.on("pointerover",()=>r.setFrame(1)),r.on("pointerout",()=>r.setFrame(0)),r.displayHeight=n,null===s?r.scaleX=r.scaleY:r.displayWidth=s,r}click(e,t,s){e.isTinted?t.remove(e):t.add(e,s)}newCategory(e,t,s){let n=new Category(e,t,s);return this.lCategory.push(n),n}addTitle(e,t,s){let n={font:(HEIGHT_WINDOW/12).toString()+"px stencil",fill:"#e2e2e2"};this.add.text(e,t,s,n).setOrigin(.5,.5)}createButtonCancel(){this.createButton(WIDTH_WINDOW/3,HEIGHT_WINDOW/(16/15),null,HEIGHT_WINDOW/9,"cancel").on("pointerdown",()=>this.cancel())}createButtonAdd(e){this.createButton(WIDTH_WINDOW/1.5,HEIGHT_WINDOW/(16/15),null,HEIGHT_WINDOW/9,"add").on("pointerdown",()=>e.addNode())}verifyCategory(){for(let e=0;es.setFrame(1)),s.on("pointerout",()=>s.setFrame(0)),s.displayHeight=HEIGHT_WINDOW/9,s.scaleX=s.scaleY,s}btnRetry(e){e.on("pointerdown",()=>this.retry())}retry(){console.log("RETRY"),this.close(),newGame(this.father),this.father.scene.start("Game")}btnHome(e){e.on("pointerdown",()=>this.home())}home(){console.log("HOME"),this.close(),this.father.scene.start("Type")}btnNext(e){e.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")}} \ No newline at end of file diff --git a/Code/src/js/level1/Init.js b/Code/src/js/level1/Init.js index 71986c1..060793e 100644 --- a/Code/src/js/level1/Init.js +++ b/Code/src/js/level1/Init.js @@ -14,6 +14,30 @@ function newGame(father) { father.scene.add('Game', new Game(father)); } +function chooseTarget(robot, list) { + let minDist = WIDTH_MAP * 2; + let l = []; + list.forEach(function (item) { + if (item !== robot) { + let hypot = Math.hypot(item.x - robot.x, item.y - robot.y); + if (minDist >= hypot) { + if (minDist > hypot) { + minDist = hypot; + l = []; + } + l.push(item); + } + } + }); + if (l.length > 1) { + return l[Math.floor(Math.random() * (l.length + 1))]; + } else { + return l[0]; + } +} + + +var listBonus = []; var LANG = navigator.language.substr(0, 2).toLowerCase(); const MYSELF = 'myself'; const SHIELD_PER_SECOND = 5; diff --git a/Code/src/js/level2/BonusShield.js b/Code/src/js/level2/BonusShield.js index 9899a48..edf1e36 100644 --- a/Code/src/js/level2/BonusShield.js +++ b/Code/src/js/level2/BonusShield.js @@ -5,7 +5,7 @@ class BonusShield extends Bonus { useOn(robot) { robot.shield.valueMax = robot.shield.valueMax + this.value; - robot.shield.value = robot.shield.value + this.value; + robot.shield.value = robot.shield.value + this.val this.destroy(); } } \ No newline at end of file diff --git a/Code/src/js/level2/BonusSpeed.js b/Code/src/js/level2/BonusSpeed.js index 0192a96..7a4c34d 100644 --- a/Code/src/js/level2/BonusSpeed.js +++ b/Code/src/js/level2/BonusSpeed.js @@ -1,13 +1,12 @@ class BonusSpeed extends Bonus { constructor(name, scene, x, y, value, time) { - super(name, scene, x, y, 'bonusSpeed', value); + super(name, scene, x, y, 'play', value); this.time = time; } useOn(robot) { - let oldSpeed = robot.speed; - robot.setSpeed(oldSpeed + this.value); - this.scene.time.addEvent({delay: this.time, callback: robot.setSpeed(oldSpeed)}); + robot.increaseSpeed(this.value); + this.scene.time.addEvent({delay: this.time, callback: () => robot.decreaseSpeed(this.value)}); this.destroy(); } } \ No newline at end of file diff --git a/Code/src/js/level2/Game.js b/Code/src/js/level2/Game.js index 848c6b7..43ca9dc 100644 --- a/Code/src/js/level2/Game.js +++ b/Code/src/js/level2/Game.js @@ -20,7 +20,8 @@ class Game extends Phaser.Scene { let centerX = WIDTH_WINDOW / 4 * 3; let diffX = WIDTH_WINDOW / 10; this.tree = new RectangleNode(centerX, HEIGHT_WINDOW / 10, this, 'waria'); - this.tree.addRect(new RectangleNode(centerX + diffX, HEIGHT_WINDOW / 3, this, 'move', true)) + 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)); diff --git a/Code/src/js/level2/GamingBoard.js b/Code/src/js/level2/GamingBoard.js index 104eb89..34c05bd 100644 --- a/Code/src/js/level2/GamingBoard.js +++ b/Code/src/js/level2/GamingBoard.js @@ -2,22 +2,24 @@ class GamingBoard extends Phaser.Scene { constructor(father) { super('GamingBoard'); this.listRobot = []; + listBonus = []; this.father = father; + this.end = false; } preload() { this.cameras.main.setViewport(WIDTH_WINDOW / 10, HEIGHT_WINDOW / 10, WIDTH_MAP, WIDTH_MAP); + this.sound.add('shot'); + this.sound.add('hit'); } create() { - this.end = false; - this.sound.add('shot'); - this.sound.add('hit'); + listBonus.push(new BonusSpeed('Balle Argent', this, WIDTH_MAP / 2, WIDTH_MAP / 2, 3, 2000)); this.add.image(0, 0, 'background').alpha = 0.1; for (let i = 0; i < this.listRobot.length; i++) { - this.chooseTarget(this.listRobot[i]); + this.listRobot[i].setTarget(chooseTarget(this.listRobot[i], this.listRobot)); } this.listRobot[0].drawRange(); @@ -29,7 +31,6 @@ class GamingBoard extends Phaser.Scene { update(time, delta) { super.update(time, delta); - this.listRobot.forEach(function (robot) { robot.read(); }) @@ -40,9 +41,7 @@ class GamingBoard extends Phaser.Scene { i -= 1; } else { if (!this.listRobot[i].haveTarget()) { - this.chooseTarget(this.listRobot[i]); - } else { - this.listRobot[i].updateTarget(); + this.listRobot[i].setTarget(chooseTarget(this.listRobot[i], this.listRobot)); } } } @@ -54,7 +53,6 @@ class GamingBoard extends Phaser.Scene { } finish() { - console.log("QUOI ?"); this.pause(); this.father.finish(); } @@ -88,28 +86,6 @@ class GamingBoard extends Phaser.Scene { return false; } - chooseTarget(robot) { - let minDist = WIDTH_MAP * 2; - let l = []; - this.listRobot.forEach(function (item) { - if (item !== robot && item.isAlive()) { - let hypot = Math.hypot(item.x - robot.x, item.y - robot.y); - if (minDist >= hypot) { - if (minDist > hypot) { - minDist = hypot; - l = []; - } - l.push(item); - } - } - }); - if (this.listRobot.length > 1) { - robot.setTarget(l[Math.floor(Math.random() * (l.length + 1))]); - } else { - robot.setTarget(l[0]); - } - } - upShield() { this.listRobot.forEach(robot => robot.addShield(SHIELD_PER_SECOND)); diff --git a/Code/src/js/level2/Move.js b/Code/src/js/level2/Move.js index b2886fe..434f91d 100644 --- a/Code/src/js/level2/Move.js +++ b/Code/src/js/level2/Move.js @@ -1,24 +1,43 @@ class Move { - constructor(toward) { //true = move toward / false = flee from + constructor(toward, enemyBot = true) { //true = move toward / false = flee from this.toward = toward; + this.enemyBot = enemyBot; } do(robot) { - if (robot.haveTarget()) { - if (this.toward === true) { - return this.moveToward(robot); - } else { - return this.fleeFrom(robot); + if (this.enemyBot) { + if (robot.verifyTarget()) { + if (this.toward === true) { + return this.moveToward(robot); + } else { + return this.fleeFrom(robot); + } + } + } else { + let bonusTarget = chooseTarget(robot, listBonus); + if (bonusTarget !== undefined) { + let ret; + if (this.toward === true) { + ret = this.moveToward(robot, bonusTarget); + } else { + ret = this.fleeFrom(robot, bonusTarget); + } + if (!ret) { + bonusTarget.useOn(robot); + listBonus.splice(listBonus.indexOf(bonusTarget), 1); + } + return true; } } return false; } - moveToward(robot) { - return robot.advanceToTarget(); + moveToward(robot, target = robot.target) { + return robot.advanceTo(target); + } - fleeFrom(robot) { - return robot.fleeFromTarget(); + fleeFrom(robot, target = robot.target) { + return robot.fleeFrom(target); } } \ No newline at end of file diff --git a/Code/src/js/level2/RectangleNode.js b/Code/src/js/level2/RectangleNode.js index b4eb533..8f87184 100644 --- a/Code/src/js/level2/RectangleNode.js +++ b/Code/src/js/level2/RectangleNode.js @@ -11,7 +11,7 @@ class RectangleNode { break; case 'move' : this.rect = new Phaser.GameObjects.Image(scene, x, y, 'moveNode'); - this.node = new Move(option[0]); + this.node = new Move(option[0], option[1]); this.canAddNode = false; this.line = scene.add.graphics(); if (option[0] === true) { diff --git a/Code/src/js/level2/Robot.js b/Code/src/js/level2/Robot.js index 9a1b2f3..b9a6f2b 100644 --- a/Code/src/js/level2/Robot.js +++ b/Code/src/js/level2/Robot.js @@ -64,7 +64,6 @@ class Robot { setTarget(target) { this.target = target; - this.updateTarget(); } updateTarget() { @@ -73,57 +72,91 @@ class Robot { } setTargetPos(x, y) { - let diffX = this.target.x - this.x; - let diffY = this.target.y - this.y; - let hypot = Math.hypot(diffX, diffY); - this.velocityX = diffX / hypot * WIDTH_MAP / 1000 * SPEED * this.speed; - this.velocityY = diffY / hypot * WIDTH_MAP / 1000 * SPEED * this.speed; } setSpeed(speed) { this.speed = speed; - this.updateTarget(); + } + + increaseSpeed(amount) { + this.speed += amount; + } + + decreaseSpeed(amount) { + this.speed -= amount; } advanceToTarget() { if (this.verifyTarget()) { - if ((this.velocityX >= 0 && this.x >= this.target.x) || (this.velocityX <= 0 && this.x <= this.target.x)) - this.setX(this.target.x); - else - this.setX(this.x + this.velocityX); + this.advanceTo(this.target); + } + return false; + } - if ((this.velocityY >= 0 && this.y >= this.target.y) || (this.velocityY <= 0 && this.y <= this.target.y)) - this.setY(this.target.y); - else - this.setY(this.y + this.velocityY); - return true; + advanceTo(target) { + if (this.target.x !== this.x || this.target.y !== this.y) { + let x = false; + let y = false; + let velocity = this.getVelocity(target); + let newX = velocity[0] + this.x; + let newY = velocity[1] + this.y; + if ((velocity[0] >= 0 && newX >= target.x) || (velocity[0] <= 0 && newX <= target.x)) { + this.setX(target.x); + x = true; + } else + this.setX(this.x + velocity[0]); + + if ((velocity[1] >= 0 && newY >= target.y) || (velocity[1] <= 0 && newY <= target.y)) { + this.setY(target.y); + y = true; + } else + this.setY(this.y + velocity[1]); + return !(x && y); } return false; } fleeFromTarget() { if (this.verifyTarget()) { - if (this.velocityX >= 0 && this.x - this.width / 2 <= 0) + return this.fleeFrom(this.target) + } + return false; + } + + fleeFrom(target) { + if (this.target.x !== this.x || this.target.y !== this.y) { + let velocity = this.getVelocity(target); + if (velocity[0] >= 0 && this.x - this.width / 2 <= 0) this.setX(this.width / 2); - else if (this.velocityX <= 0 && this.x + this.width / 2 >= WIDTH_MAP) + else if (velocity[0] <= 0 && this.x + this.width / 2 >= WIDTH_MAP) this.setX(WIDTH_MAP - this.width / 2); else - this.setX(this.x - this.velocityX); + this.setX(this.x - velocity[0]); - if (this.velocityY >= 0 && this.y - this.width / 2 <= 0) + if (velocity[1] >= 0 && this.y - this.width / 2 <= 0) this.setY(this.height / 2); - else if (this.velocityY <= 0 && this.y + this.width / 2 >= WIDTH_MAP) + else if (velocity[1] <= 0 && this.y + this.width / 2 >= WIDTH_MAP) this.setY(WIDTH_MAP - this.height / 2); else - this.setY(this.y - this.velocityY); + this.setY(this.y - velocity[1]); return true; } return false; } + getVelocity(target) { + let velocity = []; + let diffX = target.x - this.x; + let diffY = target.y - this.y; + let hypot = Math.hypot(diffX, diffY); + velocity[0] = diffX / hypot * WIDTH_MAP / 1000 * SPEED * this.speed; + velocity[1] = diffY / hypot * WIDTH_MAP / 1000 * SPEED * this.speed; + return velocity; + } + attackTarget(percentBonus = 0) { - if (this.verifyTarget() && this.target.isAlive() && this.isTargetInRange()) { + if (this.verifyTarget()) { if (this.canAttack) this.attack(this.target, percentBonus); return true; @@ -203,7 +236,7 @@ class Robot { } isTargetInRange(percentRange = 1) { - if (this.verifyTarget()) { + if (this.haveTarget()) { return this.calcDistance(this.target) < this.range * percentRange; } return false; diff --git a/Code/src/js/level3/Bonus.js b/Code/src/js/level3/Bonus.js index d8b3453..38c909c 100644 --- a/Code/src/js/level3/Bonus.js +++ b/Code/src/js/level3/Bonus.js @@ -1,7 +1,10 @@ class Bonus extends Phaser.GameObjects.Image { constructor(name, scene, x, y, texture, value) { super(scene, x, y, texture); + this.setOrigin(0.5, 0.5); + scene.add.existing(this); this.name = name; this.value = value; + this.scene = scene; } } \ No newline at end of file