diff --git a/Code/assets/en/robots/enemy.png b/Code/assets/en/robots/enemy.png new file mode 100644 index 0000000..46b5b00 Binary files /dev/null and b/Code/assets/en/robots/enemy.png differ diff --git a/Code/assets/fr/robots/enemy.png b/Code/assets/fr/robots/enemy.png new file mode 100644 index 0000000..46b5b00 Binary files /dev/null and b/Code/assets/fr/robots/enemy.png differ diff --git a/Code/public/js/level1.min.js b/Code/public/js/level1.min.js index a0dc247..4174dee 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))}function chooseTarget(e,t){let a=2*WIDTH_MAP,n=[];return t.forEach(function(t){if(t!==e){let o=Math.hypot(t.x-e.x,t.y-e.y);a>=o&&(a>o&&(a=o,n=[]),n.push(t))}}),n.length>1?n[Math.floor(Math.random()*(n.length+1))]:n[0]}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,WIDTH_WINDOW=$(document).width()-20,HEIGHT_WINDOW=$(document).height()-20,WIDTH_MAP=WIDTH_WINDOW=o&&(a>o&&(a=o,n=[]),n.push(t))}}),n.length>1?n[Math.floor(Math.random()*(n.length+1))]:n[0]}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,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 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.increaseSpeed(this.value),this.scene.time.addEvent({delay:this.time,callback:()=>e.decreaseSpeed(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 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{this.clickBin()})}update(e,t){super.update(e,t),this.doLine&&this.tree.updateLine()}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(){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(e){console.log("START DRAG"),this.doLine=!0,this.pauseScene(e)}dragEnd(){console.log("END DRAG"),this.doLine=!1}pauseScene(e){this.linePlay=0,this.changeFrame(e,0),this.gm.pause()}resume(){this.linePlay=1;this.tree.sort((e,t)=>e.getX()-t.getX()),this.gm.modifyNodes(this.tree.getNodes()),this.gm.resume()}changeFrame(e,t=0,s=0){e.setFrame(t+2*s)}createButton(){let e=WIDTH_MAP+WIDTH_WINDOW/10,t=WIDTH_MAP+HEIGHT_WINDOW/10+5,s=HEIGHT_WINDOW/10,i=HEIGHT_WINDOW/15,h=this.add.sprite(10,10,"back").setOrigin(0,0).setInteractive(),a=this.add.sprite(e,t,"play").setOrigin(1,0).setInteractive(),n=this.add.sprite(e-s,t,"speed").setOrigin(1,0).setInteractive();this.pencil=this.add.sprite(e-2*s,t,"pencil").setOrigin(1,0).setInteractive().setVisible(!1),this.bin=this.add.sprite(e-3*s,t,"bin").setOrigin(1,0).setInteractive().setVisible(!1),this.plus=this.add.sprite(e-4*s,t,"plus").setOrigin(1,0).setInteractive().setVisible(!1);let r=this.add.sprite(e-5*s,t,"mute").setOrigin(1,0).setInteractive();this.linePlay=0,this.lineSpeed=0,this.father.sound.mute?this.lineMute=1:this.lineMute=0,h.displayHeight=h.displayWidth=i,a.displayHeight=a.displayWidth=i,n.displayHeight=n.displayWidth=i,r.displayHeight=r.displayWidth=i,this.pencil.displayHeight=this.pencil.displayWidth=i,this.bin.displayHeight=this.bin.displayWidth=i,this.plus.displayHeight=this.plus.displayWidth=i,a.on("pointerout",()=>this.changeFrame(a,0,this.linePlay)),a.on("pointerover",()=>this.changeFrame(a,1,this.linePlay)),n.on("pointerout",()=>this.changeFrame(n,0,this.lineSpeed)),n.on("pointerover",()=>this.changeFrame(n,1,this.lineSpeed)),r.on("pointerout",()=>this.changeFrame(r,0,this.lineMute)),r.on("pointerover",()=>this.changeFrame(r,1,this.lineMute)),this.creatBtnOutAndOver(h),this.creatBtnOutAndOver(this.pencil),this.creatBtnOutAndOver(this.bin),this.creatBtnOutAndOver(this.plus),a.on("pointerdown",()=>this.clickPlay(a)),n.on("pointerdown",()=>this.clickSpeed(n)),h.on("pointerdown",()=>this.clickBack()),r.on("pointerdown",()=>this.clickMute(r)),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(a)),this.input.on("dragend",()=>this.dragEnd())}creatBtnOutAndOver(e){e.on("pointerout",()=>this.changeFrame(e,0)),e.on("pointerover",()=>this.changeFrame(e,1))}clickPlay(e){this.scene.isPaused("GamingBoard")?this.resume():this.pauseScene(e),this.changeFrame(e,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(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 e=0;ethis.listRobot[0].addNode(e)),!0;return!1}upShield(){this.listRobot.forEach(e=>e.addShield(SHIELD_PER_SECOND)),this.time.addEvent({delay:1e3/SPEED_GAME,callback:this.upShield,callbackScope:this})}}class HealthBar{constructor(e,t,s,i,h,a,n){this.bar=new Phaser.GameObjects.Graphics(e),this.width=t,this.height=s,this.valueMax=a,this.value=a,this.color=n,this.draw(),this.setX(i),this.setY(h),e.add.existing(this.bar)}decrease(e){this.value-=e;let t=0;return this.value<0&&(t=-this.value,this.value=0),this.draw(),t}increase(e){this.value+=e,this.value>this.valueMax&&(this.value=this.valueMax),this.draw()}setX(e){this.bar.setX(e-this.width/2)}setY(e){this.bar.setY(e)}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 e=this.value/this.valueMax;e<1/3?this.bar.fillStyle(16711680):this.bar.fillStyle(this.color);let t=Math.floor(e*(this.width-4));this.bar.fillRect(2,2,t,this.height-4)}destroy(){this.bar.destroy()}}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.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.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;ethis.addLine(e))}addLine(e){e.setLine(this.rect.x,this.rect.y+.9*this.rect.displayHeight)}getNode(){return this.canAddNode&&(this.node.clearNodes(),this.lRect.forEach(e=>this.node.addNode(e.node)),console.log(this)),this.node}getNodes(){if(void 0===this.node){let e=[];return this.lRect.forEach(function(t){void 0!==t.node&&(t.canAddNode&&(t.node.clearNodes(),t.lRect.forEach(e=>t.node.addNode(e.getNode()))),e.push(t.node))}),e}}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){}setSpeed(e){this.speed=e}increaseSpeed(e){this.speed+=e}decreaseSpeed(e){this.speed-=e}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);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){let t=[],s=e.x-this.x,i=e.y-this.y,h=Math.hypot(s,i);return t[0]=s/h*WIDTH_MAP/1e3*SPEED*this.speed*SPEED_GAME,t[1]=i/h*WIDTH_MAP/1e3*SPEED*this.speed*SPEED_GAME,t}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:Phaser.Math.Between(1e3/SPEED_GAME,3e3/SPEED_GAME),callback:this.reload,callbackScope:this})}finishAttack(e,t){e.beAttack(this.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)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")}}class Winner extends Finish{constructor(e){super(e)}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 +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 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.increaseSpeed(this.value),this.scene.time.addEvent({delay:this.time,callback:()=>e.decreaseSpeed(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 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{this.clickBin()})}update(e,t){super.update(e,t),this.doLine&&this.tree.updateLine()}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(){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(e){console.log("START DRAG"),this.doLine=!0,this.pauseScene(e)}dragEnd(){console.log("END DRAG"),this.doLine=!1}pauseScene(e){this.linePlay=0,this.changeFrame(e,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.resume()}changeFrame(e,t=0,s=0){e.setFrame(t+2*s)}createButton(){let e=WIDTH_MAP+WIDTH_WINDOW/10,t=WIDTH_MAP+HEIGHT_WINDOW/10+5,s=HEIGHT_WINDOW/10,i=HEIGHT_WINDOW/15,h=this.add.sprite(10,10,"back").setOrigin(0,0).setInteractive(),a=this.add.sprite(e,t,"play").setOrigin(1,0).setInteractive(),n=this.add.sprite(e-s,t,"speed").setOrigin(1,0).setInteractive();this.pencil=this.add.sprite(e-2*s,t,"pencil").setOrigin(1,0).setInteractive().setVisible(!1),this.bin=this.add.sprite(e-3*s,t,"bin").setOrigin(1,0).setInteractive().setVisible(!1),this.plus=this.add.sprite(e-4*s,t,"plus").setOrigin(1,0).setInteractive().setVisible(!1);let r=this.add.sprite(e-5*s,t,"mute").setOrigin(1,0).setInteractive();this.linePlay=0,1===SPEED_GAME?this.lineSpeed=0:this.lineSpeed=1,this.changeFrame(n,0,this.lineSpeed),this.father.sound.mute?this.lineMute=1:this.lineMute=0,this.changeFrame(r,0,this.lineMute),h.displayHeight=h.displayWidth=i,a.displayHeight=a.displayWidth=i,n.displayHeight=n.displayWidth=i,r.displayHeight=r.displayWidth=i,this.pencil.displayHeight=this.pencil.displayWidth=i,this.bin.displayHeight=this.bin.displayWidth=i,this.plus.displayHeight=this.plus.displayWidth=i,a.on("pointerout",()=>this.changeFrame(a,0,this.linePlay)),a.on("pointerover",()=>this.changeFrame(a,1,this.linePlay)),n.on("pointerout",()=>this.changeFrame(n,0,this.lineSpeed)),n.on("pointerover",()=>this.changeFrame(n,1,this.lineSpeed)),r.on("pointerout",()=>this.changeFrame(r,0,this.lineMute)),r.on("pointerover",()=>this.changeFrame(r,1,this.lineMute)),this.creatBtnOutAndOver(h),this.creatBtnOutAndOver(this.pencil),this.creatBtnOutAndOver(this.bin),this.creatBtnOutAndOver(this.plus),a.on("pointerdown",()=>this.clickPlay(a)),n.on("pointerdown",()=>this.clickSpeed(n)),h.on("pointerdown",()=>this.clickBack()),r.on("pointerdown",()=>this.clickMute(r)),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(a)),this.input.on("dragend",()=>this.dragEnd())}creatBtnOutAndOver(e){e.on("pointerout",()=>this.changeFrame(e,0)),e.on("pointerover",()=>this.changeFrame(e,1))}clickPlay(e){this.scene.isPaused("GamingBoard")?this.resume():this.pauseScene(e),this.changeFrame(e,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(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 e=0;ethis.listRobot[0].addNode(e)),!0;return!1}upShield(){this.listRobot.forEach(e=>e.addShield(SHIELD_PER_SECOND)),this.time.addEvent({delay:1e3/SPEED_GAME,callback:this.upShield,callbackScope:this})}}class HealthBar{constructor(e,t,s,i,h,a,n){this.bar=new Phaser.GameObjects.Graphics(e),this.width=Math.floor(t),this.height=Math.floor(s),this.valueMax=a,this.value=a,this.color=n,this.draw(),this.setX(i),this.setY(h),e.add.existing(this.bar)}decrease(e){this.value-=e;let t=0;return this.value<0&&(t=-this.value,this.value=0),this.draw(),t}increase(e){this.value+=e,this.value>this.valueMax&&(this.value=this.valueMax),this.draw()}setX(e){this.bar.setX(e-this.width/2)}setY(e){this.bar.setY(e)}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 e=this.value/this.valueMax;e<1/3?this.bar.fillStyle(16711680):this.bar.fillStyle(this.color);let t=Math.floor(e*(this.width-4));this.bar.fillRect(2,2,t,this.height-4)}destroy(){this.bar.destroy()}}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.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;ethis.addLine(e))}addLine(e){e.setLine(this.rect.x,this.rect.y+.9*this.rect.displayHeight)}getNode(){if(void 0===this.node){let e=[];return this.lRect.forEach(function(t){e.push(t.getNode())}),e}return this.canAddNode&&(this.node.clearNodes(),this.lRect.forEach(e=>this.node.addNode(e.getNode()))),this.node}sort(e){this.canAddNode&&(this.lRect.sort(e),this.lRect.forEach(function(t){t.canAddNode&&t.sort(e)}))}destroy(){this.line.destroy(),this.rect.destroy(),void 0!==this.lRect&&this.lRect.forEach(e=>e.destroy())}delete(e){let t=this.lRect.indexOf(e);if(-1!==t)return this.lRect.splice(t,1),e.destroy(),!0;for(let t=0;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){}setSpeed(e){this.speed=e}increaseSpeed(e){this.speed+=e}decreaseSpeed(e){this.speed-=e}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*WIDTH_MAP/1e3*SPEED*this.speed*SPEED_GAME,s[1]=h/a*WIDTH_MAP/1e3*SPEED*this.speed*SPEED_GAME,t&&(this.x+this.width/2+s[0]>WIDTH_MAP||this.x-this.width/2+s[0]<0?(console.log(s),s[1]+=s[0]*Math.sign(s[1]),s[0]=0,console.log(s)):(this.y+this.width/2+s[1]>WIDTH_MAP||this.y-this.width/2+s[1]<0)&&(console.log(s),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:this.timeReload/SPEED_GAME,callback:this.reload,callbackScope:this})}finishAttack(e,t){e.beAttack(this.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)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")}}class Winner extends Finish{constructor(e){super(e)}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/src/js/level1/Init.js b/Code/src/js/level1/Init.js index 7c0e40a..dae8f49 100644 --- a/Code/src/js/level1/Init.js +++ b/Code/src/js/level1/Init.js @@ -56,6 +56,7 @@ const RANGE = WIDTH_MAP / 2; const HEIGHT_BONUS = WIDTH_MAP / 10; const HEIGHT_DAMAGE = WIDTH_MAP / 20; const DURATION_DAMAGE = 700; +const TIME_RELOAD = 1000; var config = { diff --git a/Code/src/js/level2/Game.js b/Code/src/js/level2/Game.js index c0314a7..f4159b7 100644 --- a/Code/src/js/level2/Game.js +++ b/Code/src/js/level2/Game.js @@ -2,12 +2,12 @@ class Game extends ManageLang { constructor(father) { super('Game', father); super.addOtherScenes('GamingBoard'); + SPEED_GAME = 1; } create() { super.create(); this.doLine = false; - SPEED_GAME = 1; this.gm = new GamingBoard(this); if (this.father.scene.getIndex('GamingBoard') !== -1) { this.father.scene.remove('GamingBoard'); @@ -38,7 +38,7 @@ class Game extends ManageLang { this.gm.addRobot(new Robot(WIDTH_MAP * 0.1, WIDTH_MAP * 0.1, WIDTH_MAP * 0.1, WIDTH_MAP * 0.9, 0xff0000, this.gm)); - this.input.keyboard.on('keydown-ESC', () => { + this.input.keyboard.on('keydown-DELETE', () => { this.clickBin(); }); } @@ -112,7 +112,7 @@ class Game extends ManageLang { let sortDesc = (a, b) => a.getX() - b.getX(); this.tree.sort(sortDesc); - this.gm.modifyNodes(this.tree.getNodes()); + this.gm.modifyNodes(this.tree.getNode()); this.gm.resume(); } @@ -140,12 +140,18 @@ class Game extends ManageLang { let mute = this.add.sprite(x - diffX * 5, y, 'mute').setOrigin(1, 0).setInteractive(); this.linePlay = 0; - this.lineSpeed = 0; + if (SPEED_GAME === 1) { + this.lineSpeed = 0; + } else { + this.lineSpeed = 1; + } + this.changeFrame(speed, 0, this.lineSpeed); if (this.father.sound.mute) { this.lineMute = 1; } else { this.lineMute = 0; } + this.changeFrame(mute, 0, this.lineMute); back.displayHeight = back.displayWidth = width; diff --git a/Code/src/js/level2/HealthBar.js b/Code/src/js/level2/HealthBar.js index 7fda8ce..266274f 100644 --- a/Code/src/js/level2/HealthBar.js +++ b/Code/src/js/level2/HealthBar.js @@ -2,8 +2,8 @@ class HealthBar { constructor(scene, width, height, x, y, valueMax, color) { this.bar = new Phaser.GameObjects.Graphics(scene); - this.width = width; - this.height = height; + this.width = Math.floor(width); + this.height = Math.floor(height); this.valueMax = valueMax; this.value = valueMax; this.color = color; diff --git a/Code/src/js/level2/LoadFile.js b/Code/src/js/level2/LoadFile.js index c6df436..c748f87 100644 --- a/Code/src/js/level2/LoadFile.js +++ b/Code/src/js/level2/LoadFile.js @@ -45,6 +45,8 @@ class LoadFile extends Phaser.Scene { this.loadImage('bonusSpeed1', 'bonus/', true); this.loadImage('bonusSpeed2', 'bonus/', true); + this.loadImage('enemy', 'robots/'); + this.loadSprite('playLetter', 550, 150, 'buttons/'); this.loadSprite('cancel', 550, 150, 'buttons/'); this.loadSprite('add', 550, 150, 'buttons/'); diff --git a/Code/src/js/level2/RectangleNode.js b/Code/src/js/level2/RectangleNode.js index 12c4b61..fd99bde 100644 --- a/Code/src/js/level2/RectangleNode.js +++ b/Code/src/js/level2/RectangleNode.js @@ -118,29 +118,17 @@ class RectangleNode { } getNode() { - if (this.canAddNode) { - this.node.clearNodes(); - this.lRect.forEach(rect => this.node.addNode(rect.node)); - console.log(this); - } - return this.node; - } - - getNodes() { if (this.node === undefined) { let lNodes = []; this.lRect.forEach(function (element) { - if (element.node !== undefined) { - if (element.canAddNode) { - element.node.clearNodes(); - element.lRect.forEach(rect => element.node.addNode(rect.getNode())); - } - lNodes.push(element.node); - } + lNodes.push(element.getNode()); }); return lNodes; + } else if (this.canAddNode) { + this.node.clearNodes(); + this.lRect.forEach(rect => this.node.addNode(rect.getNode())); } - + return this.node; } sort(sortDesc) { diff --git a/Code/src/js/level2/Robot.js b/Code/src/js/level2/Robot.js index 26dd715..de3b941 100644 --- a/Code/src/js/level2/Robot.js +++ b/Code/src/js/level2/Robot.js @@ -1,6 +1,7 @@ class Robot { constructor(height, width, posX, posY, color, scene, name = 'enemy', speed = 1) { this.speed = speed; + this.timeReload = TIME_RELOAD; this.name = name; this.height = height; this.width = width; @@ -30,7 +31,12 @@ class Robot { addScene(scene) { this.scene = scene; - this.circle = this.scene.add.circle(this.x, this.y, this.width / 2, this.color).setInteractive(); + if (this.name === 'enemy') { + this.circle = this.scene.add.image(this.x, this.y, 'enemy').setOrigin(0.5, 0.5).setInteractive(); + this.circle.displayWidth = this.circle.displayHeight = this.width; + } else { + this.circle = this.scene.add.circle(this.x, this.y, this.width / 2, this.color).setInteractive(); + } this.circle.on('pointerdown', () => this.click()); } @@ -125,10 +131,10 @@ class Robot { 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) + let velocity = this.getVelocity(target, true); + if (velocity[0] >= 0 && this.x - this.width / 2 <= 0) { this.setX(this.width / 2); - else if (velocity[0] <= 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 - velocity[0]); @@ -144,13 +150,28 @@ class Robot { return false; } - getVelocity(target) { + getVelocity(target, calcul = false) { 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 * SPEED_GAME; velocity[1] = diffY / hypot * WIDTH_MAP / 1000 * SPEED * this.speed * SPEED_GAME; + if (calcul) { + if (this.x + this.width / 2 + velocity[0] > WIDTH_MAP || this.x - this.width / 2 + velocity[0] < 0) { + console.log(velocity); + velocity[1] += velocity[0] * Math.sign(velocity[1]); + velocity[0] = 0; + console.log(velocity); + } else { + if (this.y + this.width / 2 + velocity[1] > WIDTH_MAP || this.y - this.width / 2 + velocity[1] < 0) { + console.log(velocity); + velocity[0] += velocity[1] * Math.sign(velocity[0]); + velocity[1] = 0; + } + } + } + return velocity; } @@ -196,7 +217,7 @@ class Robot { }); this.scene.time.addEvent({ - delay: Phaser.Math.Between(1000 / SPEED_GAME, 3000 / SPEED_GAME), + delay: this.timeReload / SPEED_GAME, callback: this.reload, callbackScope: this });