diff --git a/Code/assets/en/buttons/mute.png b/Code/assets/en/buttons/mute.png new file mode 100644 index 0000000..6bc1960 Binary files /dev/null and b/Code/assets/en/buttons/mute.png differ diff --git a/Code/assets/fr/buttons/mute.png b/Code/assets/fr/buttons/mute.png new file mode 100644 index 0000000..6bc1960 Binary files /dev/null and b/Code/assets/fr/buttons/mute.png differ diff --git a/Code/public/js/level1.min.js b/Code/public/js/level1.min.js index 90f50aa..a0dc247 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 n=2*WIDTH_MAP,a=[];return t.forEach(function(t){if(t!==e){let o=Math.hypot(t.x-e.x,t.y-e.y);n>=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(),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 r;switch(h){case 1:r="bonusSpeed0";break;case 2:r="bonusSpeed1";break;case 3:default:r="bonusSpeed2"}super(e,t,s,i,r,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 Phaser.Scene{constructor(e){super("Boot"),this.father=e}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",function(){e.destroy(),t.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.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("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)}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)),this.createFlags()}createFlags(){this.diffXFlag=0,this.createFlag("fr"),this.createFlag("en")}createFlag(e){let t=this.add.image(WIDTH_WINDOW-10-this.diffXFlag,10,e).setOrigin(1,0).setInteractive();t.displayHeight=40,t.scaleX=t.scaleY,this.diffXFlag=this.diffXFlag+t.displayWidth+10,t.on("pointerdown",()=>this.setLang(e))}setLang(e){e!==LANG&&(LANG=e,console.log("Set Lang : "+e),this.scene.restart())}clickPlay(e){e.setFrame(2),console.log("Play"),this.father.scene.add("Type",new Type(this.father)),this.scene.start("Type")}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 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;te.getX()-t.getX();this.tree.lRect.sort(e),this.tree.lRect.forEach(function(t){void 0!==t.lRect&&t.lRect.sort(e)}),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(),r=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),this.linePlay=0,this.lineSpeed=0,h.displayHeight=h.displayWidth=i,a.displayHeight=a.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)),r.on("pointerout",()=>this.changeFrame(r,0,this.lineSpeed)),r.on("pointerover",()=>this.changeFrame(r,1,this.lineSpeed)),this.creatBtnOutAndOver(h),this.creatBtnOutAndOver(this.pencil),this.creatBtnOutAndOver(this.bin),this.creatBtnOutAndOver(this.plus),a.on("pointerdown",()=>this.clickPlay(a)),r.on("pointerdown",()=>this.clickSpeed(r)),h.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(a))}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(){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"),SPEED_GAME=1,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(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.resume()),this.time.addEvent({delay:2e3,callback:this.upShield,callbackScope:this})}update(e,t){super.update(e,t),this.listRobot.forEach(function(e){e.read()});for(let e=0;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,r){this.bar=new Phaser.GameObjects.Graphics(e),this.width=t,this.height=s,this.valueMax=a,this.value=a,this.color=r,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 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.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);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)}getNodes(){if(void 0===this.node){let e=[];return this.lRect.forEach(function(t){void 0!==t.node&&(void 0!==t.lRect&&(t.node.clearNodes(),t.lRect.forEach(e=>t.node.addNode(e.node))),e.push(t.node))}),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(this.target.x!==this.x||this.target.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.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 diff --git a/Code/public/js/level3.min.js b/Code/public/js/level3.min.js index be11d36..43206f8 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,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,i,n,r=new Category,a){let o=this.createButton(e,t,s,i,n);return o.on("pointerdown",()=>this.click(o,r,a)),o}createButton(e,t,s,i,n){let r=this.add.image(e,t,n).setOrigin(.5,.5).setInteractive();return r.on("pointerover",()=>r.setFrame(1)),r.on("pointerout",()=>r.setFrame(0)),r.displayHeight=i,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 i=new Category(e,t,s);return this.lCategory.push(i),i}addTitle(e,t,s){let i={font:(HEIGHT_WINDOW/12).toString()+"px stencil",fill:"#e2e2e2"};this.add.text(e,t,s,i).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 +class AddNode extends Phaser.Scene{constructor(e,t,s){super("AddNode"),this.father=e,this.gameR=t,this.selected=s,this.lCategory=[];let i=HEIGHT_WINDOW/14;this.style={font:i.toString()+"px stencil",fill:"#e2e2e2"},this.heightButton=HEIGHT_WINDOW/8}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,i=new Category,a){let n=this.createButton(e,t,s);return n.on("pointerdown",()=>this.click(n,i,a)),n}createButton(e,t,s,i=this.heightButton,a=null){let n=this.add.image(e,t,s).setOrigin(.5,.5).setInteractive();return n.on("pointerover",()=>n.setFrame(1)),n.on("pointerout",()=>n.setFrame(0)),n.displayHeight=i,null===a?n.scaleX=n.scaleY:n.displayWidth=a,n}click(e,t,s){e.isTinted?t.remove(e):t.add(e,s)}newCategory(e,t,s){let i=new Category(e,t,s);return this.lCategory.push(i),i}addTitle(e,t,s){this.add.text(e,t,s,this.style).setOrigin(.5,.5)}createButtonCancel(){this.createButton(WIDTH_WINDOW/3,HEIGHT_WINDOW/(16/15),"cancel",HEIGHT_WINDOW/9).on("pointerdown",()=>this.cancel())}createButtonAdd(e){this.createButton(WIDTH_WINDOW/1.5,HEIGHT_WINDOW/(16/15),"add",HEIGHT_WINDOW/9).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")}}class ManageLang extends Phaser.Scene{constructor(e,t){super(e),this.name=e,this.father=t,this.otherScenes=[]}addOtherScenes(e){this.otherScenes.push(e)}create(){this.createFlags()}createFlags(){this.diffXFlag=0,this.createFlag("fr"),this.createFlag("en")}createFlag(e){let t=this.add.image(WIDTH_WINDOW-10-this.diffXFlag,10,e).setOrigin(1,0).setInteractive();t.displayHeight=40,t.scaleX=t.scaleY,this.diffXFlag=this.diffXFlag+t.displayWidth+10,t.on("pointerdown",()=>this.setLang(e))}setLang(e){e!==LANG&&(LANG=e,this.father.scene.add("LoadFile",new LoadFile(this.father,this.name)),this.father.scene.start("LoadFile"),this.otherScenes.forEach(e=>this.father.scene.stop(e)))}} \ No newline at end of file diff --git a/Code/src/js/level1/Init.js b/Code/src/js/level1/Init.js index 3572b6f..7c0e40a 100644 --- a/Code/src/js/level1/Init.js +++ b/Code/src/js/level1/Init.js @@ -67,6 +67,5 @@ var config = { }; let father = new Phaser.Game(config); - -father.scene.add('Boot', new Boot(father)); -father.scene.start('Boot'); +father.scene.add('LoadFile', new LoadFile(father, 'Boot', new Boot(father))); +father.scene.start('LoadFile'); diff --git a/Code/src/js/level2/AddAttack.js b/Code/src/js/level2/AddAttack.js index a80fa83..45e960d 100644 --- a/Code/src/js/level2/AddAttack.js +++ b/Code/src/js/level2/AddAttack.js @@ -10,11 +10,11 @@ class AddAttack extends AddNode { 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 / (16 / 5), null, HEIGHT_WINDOW / 8, 'enemyBot', super.newCategory('target', true, true), false); + super.addButton(WIDTH_WINDOW / 2, HEIGHT_WINDOW / (16 / 5), 'enemyBot', super.newCategory('target', true, true), false); let c2 = super.newCategory('range', true, true); - super.addButton(WIDTH_WINDOW / 3, HEIGHT_WINDOW / (16 / 9), null, HEIGHT_WINDOW / 8, 'shortRange', c2, 1 / 3); - super.addButton(WIDTH_WINDOW / 1.5, HEIGHT_WINDOW / (16 / 9), null, HEIGHT_WINDOW / 8, 'mediumRange', c2, 2 / 3); - super.addButton(WIDTH_WINDOW / 2, HEIGHT_WINDOW / (16 / 12), null, HEIGHT_WINDOW / 8, 'longRange', c2, 1); + super.addButton(WIDTH_WINDOW / 3, HEIGHT_WINDOW / (16 / 9), 'shortRange', c2, 1 / 3); + super.addButton(WIDTH_WINDOW / 1.5, HEIGHT_WINDOW / (16 / 9), 'mediumRange', c2, 2 / 3); + super.addButton(WIDTH_WINDOW / 2, HEIGHT_WINDOW / (16 / 12), 'longRange', c2, 1); } addNode() { diff --git a/Code/src/js/level2/AddCondition.js b/Code/src/js/level2/AddCondition.js index ea7a06f..edbea5d 100644 --- a/Code/src/js/level2/AddCondition.js +++ b/Code/src/js/level2/AddCondition.js @@ -10,13 +10,13 @@ class AddCondition extends AddNode { 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 c1 = super.newCategory('target', true, true); - super.addButton(WIDTH_WINDOW / 3, HEIGHT_WINDOW / (16 / 5), null, HEIGHT_WINDOW / 8, 'enemyBot', c1, false); - super.addButton(WIDTH_WINDOW / 1.5, HEIGHT_WINDOW / (16 / 5), null, HEIGHT_WINDOW / 8, 'myself', c1, true); + super.addButton(WIDTH_WINDOW / 3, HEIGHT_WINDOW / (16 / 5), 'enemyBot', c1, false); + super.addButton(WIDTH_WINDOW / 1.5, HEIGHT_WINDOW / (16 / 5), 'myself', c1, true); let c2 = super.newCategory('shield', true, true); - super.addButton(WIDTH_WINDOW / 3, HEIGHT_WINDOW / (16 / 9), null, HEIGHT_WINDOW / 8, 'shield0', c2, 0); - super.addButton(WIDTH_WINDOW / 1.5, HEIGHT_WINDOW / (16 / 9), null, HEIGHT_WINDOW / 8, 'shield33', c2, 1 / 3); - super.addButton(WIDTH_WINDOW / 3, HEIGHT_WINDOW / (16 / 12), null, HEIGHT_WINDOW / 8, 'shield66', c2, 2 / 3); - super.addButton(WIDTH_WINDOW / 1.5, HEIGHT_WINDOW / (16 / 12), null, HEIGHT_WINDOW / 8, 'shield100', c2, 1); + super.addButton(WIDTH_WINDOW / 3, HEIGHT_WINDOW / (16 / 9), 'shield0', c2, 0); + super.addButton(WIDTH_WINDOW / 1.5, HEIGHT_WINDOW / (16 / 9), 'shield33', c2, 1 / 3); + super.addButton(WIDTH_WINDOW / 3, HEIGHT_WINDOW / (16 / 12), 'shield66', c2, 2 / 3); + super.addButton(WIDTH_WINDOW / 1.5, HEIGHT_WINDOW / (16 / 12), 'shield100', c2, 1); } addNode() { diff --git a/Code/src/js/level2/AddMove.js b/Code/src/js/level2/AddMove.js index 73c8a6d..f851471 100644 --- a/Code/src/js/level2/AddMove.js +++ b/Code/src/js/level2/AddMove.js @@ -9,12 +9,12 @@ class AddMove extends AddNode { super.addTitle(WIDTH_WINDOW / 2, HEIGHT_WINDOW / 16, selectWord("ADD NODE : MOVE", "AJOUTER ACTION : DEPLACEMENT")); super.addTitle(WIDTH_WINDOW / 4, HEIGHT_WINDOW / (16 / 3), selectWord("FLEE OR MOVE ?", "RECULER OU AVANCER ?")); let c1 = super.newCategory('direction', true, true); - super.addButton(WIDTH_WINDOW / 6, HEIGHT_WINDOW / (16 / 5), null, HEIGHT_WINDOW / 8, 'fleeFrom', c1, false); - super.addButton(WIDTH_WINDOW / 3, HEIGHT_WINDOW / (16 / 5), null, HEIGHT_WINDOW / 8, 'moveToward', c1, true); + super.addButton(WIDTH_WINDOW / 6, HEIGHT_WINDOW / (16 / 5), 'fleeFrom', c1, false); + super.addButton(WIDTH_WINDOW / 3, HEIGHT_WINDOW / (16 / 5), 'moveToward', c1, true); super.addTitle(WIDTH_WINDOW / 4 * 3, HEIGHT_WINDOW / (16 / 3), selectWord("WHO ?", "QUI ?")); let c2 = super.newCategory('target', true, true); - super.addButton(WIDTH_WINDOW / 6 * 4, HEIGHT_WINDOW / (16 / 5), null, HEIGHT_WINDOW / 8, 'enemyBot', c2, true); - super.addButton(WIDTH_WINDOW / 6 * 5, HEIGHT_WINDOW / (16 / 5), null, HEIGHT_WINDOW / 8, 'bonus', c2, false); + super.addButton(WIDTH_WINDOW / 6 * 4, HEIGHT_WINDOW / (16 / 5), 'enemyBot', c2, true); + super.addButton(WIDTH_WINDOW / 6 * 5, HEIGHT_WINDOW / (16 / 5), 'bonus', c2, false); } addNode() { diff --git a/Code/src/js/level2/Boot.js b/Code/src/js/level2/Boot.js index 29c5834..b786969 100644 --- a/Code/src/js/level2/Boot.js +++ b/Code/src/js/level2/Boot.js @@ -1,157 +1,22 @@ -class Boot extends Phaser.Scene { +class Boot extends ManageLang { constructor(father) { - super('Boot'); - this.father = father; - } - - preload() { - let progressBar = this.add.graphics(); - let progressBox = this.add.graphics(); - let width = 320; - let height = 50; - let x = WIDTH_WINDOW / 2 - width / 2; - let y = HEIGHT_WINDOW / 2 - height / 2; - - progressBox.fillStyle(0x222222, 0.8); - progressBox.fillRect(x, y, 320, height); - this.load.on('progress', function (value) { - progressBar.clear(); - progressBar.fillStyle(0xffffff, 1); - progressBar.fillRect(x + 10, y + 10, (width - 20) * value, height - 20); - }); - this.load.on('complete', function () { - progressBar.destroy(); - progressBox.destroy(); - }); - - this.load.audio('shot', 'assets/sounds/shot.ogg'); - this.load.audio('hit', 'assets/sounds/hit.ogg'); - - this.loadImage('en', 'flags/', true); - this.loadImage('fr', 'flags/', true); - - this.loadImage('bonusSpeed0', 'bonus/', true); - this.loadImage('bonusSpeed1', 'bonus/', true); - this.loadImage('bonusSpeed2', 'bonus/', true); - - 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('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/', true); - this.loadSprite('moveNode', 180, 190, 'nodes/', true); - this.loadSprite('conditionNode', 180, 190, 'nodes/', true); - - - this.loadImage('background'); - this.loadImage('bullet'); - this.loadImage('logoWaria'); - this.loadImage('attack', 'nodes/', true); - this.loadImage('move', 'nodes/', true); - this.loadImage('condition', 'nodes/', true); + super('Boot', father); } create() { + super.create(); let style = {font: '200px stencil', fill: "#e2e2e2"}; this.add.text(WIDTH_WINDOW / 2, HEIGHT_WINDOW / 3, "WARIA", style).setOrigin(0.5, 0.5); let btn = this.add.sprite(WIDTH_WINDOW / 2, (HEIGHT_WINDOW / 3) * 2, 'playLetter').setInteractive(); - //btn.setFrame(0); btn.on('pointerout', () => btn.setFrame(0)); btn.on('pointerover', () => btn.setFrame(1)); btn.on('pointerdown', () => this.clickPlay(btn)); - - this.createFlags(); - } - - createFlags() { - this.diffXFlag = 0; - this.createFlag('fr'); - this.createFlag('en'); } - createFlag(name) { - let flag = this.add.image(WIDTH_WINDOW - 10 - this.diffXFlag, 10, name).setOrigin(1, 0).setInteractive(); - flag.displayHeight = 40; - flag.scaleX = flag.scaleY; - this.diffXFlag = this.diffXFlag + flag.displayWidth + 10; - flag.on('pointerdown', () => this.setLang(name)); - } - - setLang(lang) { - if (lang !== LANG) { - LANG = lang; - console.log('Set Lang : ' + lang); - - this.scene.restart(); - } - } clickPlay(btn) { - btn.setFrame(2); console.log("Play"); this.father.scene.add('Type', new Type(this.father)); this.scene.start('Type'); } - - loadSprite(name, width, height, folder = '', force = false) { - this.deleteLoad(name); - if (force) { - this.load.spritesheet(name, 'assets/' + folder + name + '.png', { - frameWidth: width, - frameHeight: height - }); - } else { - this.load.spritesheet(name, 'assets/' + LANG + '/' + folder + name + '.png', { - frameWidth: width, - frameHeight: height - }); - } - } - - loadImage(name, folder = '', force = false) { - this.deleteLoad(name); - if (force) { - this.load.image(name, 'assets/' + folder + name + '.png'); - } else { - this.load.image(name, 'assets/' + LANG + '/' + folder + name + '.png'); - } - } - - deleteLoad(name) { - if (this.textures.exists(name)) { - this.textures.remove(name); - } - } } \ No newline at end of file diff --git a/Code/src/js/level2/Game.js b/Code/src/js/level2/Game.js index ed85b5d..c0314a7 100644 --- a/Code/src/js/level2/Game.js +++ b/Code/src/js/level2/Game.js @@ -1,22 +1,25 @@ -class Game extends Phaser.Scene { +class Game extends ManageLang { constructor(father) { - super('Game'); - this.father = father; + super('Game', father); + super.addOtherScenes('GamingBoard'); } - preload() { + 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'); + } this.father.scene.add('GamingBoard', this.gm); - } + this.scene.launch('GamingBoard'); + this.scene.pause('GamingBoard'); - create() { this.selected = null; this.createButton(); - this.scene.launch('GamingBoard'); - this.scene.pause('GamingBoard'); - let centerX = WIDTH_WINDOW / 4 * 3; let diffX = WIDTH_WINDOW / 10; this.tree = new RectangleNode(centerX, HEIGHT_WINDOW / 10, this, 'waria'); @@ -33,16 +36,21 @@ class Game extends Phaser.Scene { this.gm.addRobot(new Robot(WIDTH_MAP * 0.1, WIDTH_MAP * 0.1, WIDTH_MAP * 0.9, WIDTH_MAP * 0.9, 0x6666ff, this.gm, MYSELF)); this.gm.addRobot(new Robot(WIDTH_MAP * 0.1, WIDTH_MAP * 0.1, WIDTH_MAP * 0.2, WIDTH_MAP * 0.1, 0xff0000, this.gm)); 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.clickBin(); + }); } update(time, delta) { super.update(time, delta); - this.tree.updateLine(); + if (this.doLine) + this.tree.updateLine(); } finish() { console.log("FINISH"); - SPEED_GAME = 1; let winner; if (this.gm.winner()) { winner = new Winner(this.father); @@ -58,15 +66,10 @@ class Game extends Phaser.Scene { clickNode() { - this.pencil.setVisible(false); - this.bin.setVisible(false); - this.plus.setVisible(false); - if (this.selected != null) { - this.selected.deselect(); - } + this.tryClick(); this.selected = this.tree.getSelected(); - if (this.selected == null) + if (this.selected === null) return; if (this.selected !== this.tree) { @@ -83,6 +86,19 @@ class Game extends Phaser.Scene { target.setY(dragY); } + dragStart(btn) { + console.log("START DRAG"); + + this.doLine = true; + this.pauseScene(btn); + } + + dragEnd() { + console.log("END DRAG"); + + this.doLine = false; + } + pauseScene(btn) { this.linePlay = 0; @@ -94,13 +110,8 @@ class Game extends Phaser.Scene { resume() { this.linePlay = 1; - const sortDesc = (a, b) => a.getX() - b.getX(); - this.tree.lRect.sort(sortDesc); - this.tree.lRect.forEach(function (element) { - if (element.lRect !== undefined) { - element.lRect.sort(sortDesc); - } - }) + let sortDesc = (a, b) => a.getX() - b.getX(); + this.tree.sort(sortDesc); this.gm.modifyNodes(this.tree.getNodes()); this.gm.resume(); @@ -126,13 +137,21 @@ class Game extends Phaser.Scene { this.bin = this.add.sprite(x - diffX * 3, y, 'bin').setOrigin(1, 0).setInteractive().setVisible(false); this.plus = this.add.sprite(x - diffX * 4, y, 'plus').setOrigin(1, 0).setInteractive().setVisible(false); + let mute = this.add.sprite(x - diffX * 5, y, 'mute').setOrigin(1, 0).setInteractive(); + this.linePlay = 0; this.lineSpeed = 0; + if (this.father.sound.mute) { + this.lineMute = 1; + } else { + this.lineMute = 0; + } back.displayHeight = back.displayWidth = width; play.displayHeight = play.displayWidth = width; speed.displayHeight = speed.displayWidth = width; + mute.displayHeight = mute.displayWidth = width; this.pencil.displayHeight = this.pencil.displayWidth = width; this.bin.displayHeight = this.bin.displayWidth = width; this.plus.displayHeight = this.plus.displayWidth = width; @@ -141,6 +160,8 @@ class Game extends Phaser.Scene { play.on('pointerover', () => this.changeFrame(play, 1, this.linePlay)); speed.on('pointerout', () => this.changeFrame(speed, 0, this.lineSpeed)); speed.on('pointerover', () => this.changeFrame(speed, 1, this.lineSpeed)); + mute.on('pointerout', () => this.changeFrame(mute, 0, this.lineMute)); + mute.on('pointerover', () => this.changeFrame(mute, 1, this.lineMute)); this.creatBtnOutAndOver(back); this.creatBtnOutAndOver(this.pencil); this.creatBtnOutAndOver(this.bin); @@ -149,13 +170,15 @@ class Game extends Phaser.Scene { play.on('pointerdown', () => this.clickPlay(play)); speed.on('pointerdown', () => this.clickSpeed(speed)); back.on('pointerdown', () => this.clickBack()); + mute.on('pointerdown', () => this.clickMute(mute)); 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(play)); + this.input.on('dragstart', () => this.dragStart(play)); + this.input.on('dragend', () => this.dragEnd()); } creatBtnOutAndOver(btn) { @@ -192,10 +215,13 @@ class Game extends Phaser.Scene { } clickBin() { - console.log("BIN"); - this.tree.delete(this.selected); + if (this.selected !== null) { + console.log("BIN"); + this.tree.delete(this.selected); - this.changeFrame(this.bin, 0); + this.changeFrame(this.bin, 0); + this.tryClick(); + } } clickPlus() { @@ -212,11 +238,33 @@ class Game extends Phaser.Scene { clickBack() { console.log("BACK"); - SPEED_GAME = 1; this.father.scene.stop('GamingBoard'); this.father.scene.remove('GamingBoard'); this.father.scene.stop('Game'); this.father.scene.start('Type'); } + + clickMute(btn) { + console.log("MUTE"); + + if (this.father.sound.mute) { + this.father.sound.mute = false; + this.lineMute = 0; + } else { + this.father.sound.mute = true; + this.lineMute = 1; + } + this.changeFrame(btn, 1, this.lineMute); + } + + tryClick() { + this.pencil.setVisible(false); + this.bin.setVisible(false); + this.plus.setVisible(false); + if (this.selected != null) { + this.selected.deselect(); + this.selected = null; + } + } } \ No newline at end of file diff --git a/Code/src/js/level2/GamingBoard.js b/Code/src/js/level2/GamingBoard.js index 4a2360f..900abb6 100644 --- a/Code/src/js/level2/GamingBoard.js +++ b/Code/src/js/level2/GamingBoard.js @@ -14,6 +14,7 @@ class GamingBoard extends Phaser.Scene { } create() { + listBonus.push(new BonusSpeed('Balle Argent', this, WIDTH_MAP / 2, WIDTH_MAP / 2, 3, 2000)); this.add.image(0, 0, 'background').alpha = 0.1; @@ -24,9 +25,8 @@ class GamingBoard extends Phaser.Scene { this.listRobot[0].drawRange(); - this.events.on('resume', () => this.resume()); - this.time.addEvent({delay: 2000, callback: this.upShield, callbackScope: this}); + } update(time, delta) { diff --git a/Code/src/js/level2/LoadFile.js b/Code/src/js/level2/LoadFile.js new file mode 100644 index 0000000..c6df436 --- /dev/null +++ b/Code/src/js/level2/LoadFile.js @@ -0,0 +1,127 @@ +class LoadFile extends Phaser.Scene { + constructor(father, nameSon, son) { + super('LoadFile'); + this.father = father; + this.son = son; + this.nameSon = nameSon; + + this.father.scene.pause(this.nameSon); + this.father.scene.stop(this.nameSon); + this.father.scene.remove('LoadFile'); + } + + preload() { + let progressBar = this.add.graphics(); + let progressBox = this.add.graphics(); + let width = 320; + let height = 50; + let x = WIDTH_WINDOW / 2 - width / 2; + let y = HEIGHT_WINDOW / 2 - height / 2; + + progressBox.fillStyle(0x222222, 0.8); + progressBox.fillRect(x, y, 320, height); + this.load.on('progress', function (value) { + progressBar.clear(); + progressBar.fillStyle(0xffffff, 1); + progressBar.fillRect(x + 10, y + 10, (width - 20) * value, height - 20); + }); + this.load.on('complete', () => { + + progressBar.destroy(); + progressBox.destroy(); + if (this.father.scene.getIndex(this.nameSon) === -1) { + 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/', true); + this.loadImage('fr', 'flags/', true); + + this.loadImage('bonusSpeed0', 'bonus/', true); + this.loadImage('bonusSpeed1', 'bonus/', true); + this.loadImage('bonusSpeed2', 'bonus/', true); + + 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/', true); + this.loadSprite('moveNode', 180, 190, 'nodes/', true); + this.loadSprite('conditionNode', 180, 190, 'nodes/', true); + + + this.loadImage('background'); + this.loadImage('bullet'); + this.loadImage('logoWaria'); + this.loadImage('attack', 'nodes/', true); + this.loadImage('move', 'nodes/', true); + this.loadImage('condition', 'nodes/', true); + } + + loadSprite(name, width, height, folder = '', force = false) { + this.deleteLoad(name); + if (force) { + this.load.spritesheet(name, 'assets/' + folder + name + '.png', { + frameWidth: width, + frameHeight: height + }); + } else { + this.load.spritesheet(name, 'assets/' + LANG + '/' + folder + name + '.png', { + frameWidth: width, + frameHeight: height + }); + } + } + + loadImage(name, folder = '', force = false) { + this.deleteLoad(name); + if (force) { + this.load.image(name, 'assets/' + folder + name + '.png'); + } else { + this.load.image(name, 'assets/' + LANG + '/' + folder + name + '.png'); + } + } + + deleteLoad(name) { + if (this.textures.exists(name)) { + this.textures.remove(name); + } + } +} \ No newline at end of file diff --git a/Code/src/js/level2/PlusNode.js b/Code/src/js/level2/PlusNode.js index 380cd22..2469db4 100644 --- a/Code/src/js/level2/PlusNode.js +++ b/Code/src/js/level2/PlusNode.js @@ -18,7 +18,7 @@ class PlusNode extends Phaser.Scene { let y = HEIGHT_WINDOW / 2; let diffX = WIDTH_WINDOW / 3; let diffY = HEIGHT_WINDOW / 10; - let sizeText = diffY; + let sizeText = diffY / 1.5; let style = {font: sizeText.toString() + 'px stencil', fill: "#e2e2e2"}; diff --git a/Code/src/js/level2/RectangleNode.js b/Code/src/js/level2/RectangleNode.js index 3d3b593..12c4b61 100644 --- a/Code/src/js/level2/RectangleNode.js +++ b/Code/src/js/level2/RectangleNode.js @@ -28,6 +28,7 @@ class RectangleNode { this.lRect = []; this.scene = scene; this.scene.add.existing(this.rect); + this.scene.input.setDraggable(this.rect); break; default: console.log("Création d'un node echoué"); @@ -99,7 +100,7 @@ class RectangleNode { this.updateLine(true); } - updateLine(force) { + updateLine(force = false) { if ((force === true || this.xLine !== this.rect.x || this.yLine !== this.rect.y) && this.line !== undefined) { this.xLine = this.rect.x; this.yLine = this.rect.y; @@ -116,14 +117,23 @@ class RectangleNode { node.setLine(this.rect.x, this.rect.y + this.rect.displayHeight * 0.9); } + 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.lRect !== undefined) { + if (element.canAddNode) { element.node.clearNodes(); - element.lRect.forEach(rect => element.node.addNode(rect.node)); + element.lRect.forEach(rect => element.node.addNode(rect.getNode())); } lNodes.push(element.node); } @@ -133,6 +143,17 @@ class RectangleNode { } + sort(sortDesc) { + if (this.canAddNode) { + this.lRect.sort(sortDesc); + this.lRect.forEach(function (element) { + if (element.canAddNode) { + element.sort(sortDesc); + } + }) + } + } + destroy() { this.line.destroy(); this.rect.destroy(); diff --git a/Code/src/js/level2/Robot.js b/Code/src/js/level2/Robot.js index 45cdf27..26dd715 100644 --- a/Code/src/js/level2/Robot.js +++ b/Code/src/js/level2/Robot.js @@ -94,7 +94,7 @@ class Robot { } advanceTo(target) { - if (this.target.x !== this.x || this.target.y !== this.y) { + if (target.x !== this.x || target.y !== this.y) { let x = false; let y = false; let velocity = this.getVelocity(target); diff --git a/Code/src/js/level2/Type.js b/Code/src/js/level2/Type.js index a06d3f3..1f65780 100644 --- a/Code/src/js/level2/Type.js +++ b/Code/src/js/level2/Type.js @@ -1,13 +1,13 @@ -class Type extends Phaser.Scene { +class Type extends ManageLang { constructor(father) { - super('Type'); - this.father = father; + super('Type', father); } preload() { } create() { + super.create(); let style = {font: '200px stencil', fill: "#e2e2e2"}; this.add.text(WIDTH_WINDOW / 2, HEIGHT_WINDOW / 4, "WARIA", style).setOrigin(0.5, 1); diff --git a/Code/src/js/level3/AddNode.js b/Code/src/js/level3/AddNode.js index 5ea8ccc..acb14bf 100644 --- a/Code/src/js/level3/AddNode.js +++ b/Code/src/js/level3/AddNode.js @@ -5,6 +5,9 @@ class AddNode extends Phaser.Scene { this.gameR = game; this.selected = selected; this.lCategory = []; + let sizeText = HEIGHT_WINDOW / 14; + this.style = {font: sizeText.toString() + 'px stencil', fill: "#e2e2e2"}; + this.heightButton = HEIGHT_WINDOW / 8; } create(son) { @@ -16,13 +19,13 @@ class AddNode extends Phaser.Scene { } - addButton(x, y, width, height, texture, category = new Category(), value) { - let btn = this.createButton(x, y, width, height, texture); + addButton(x, y, texture, category = new Category(), value) { + let btn = this.createButton(x, y, texture); btn.on('pointerdown', () => this.click(btn, category, value)); return btn; } - createButton(x, y, width, height, texture) { + createButton(x, y, texture, height = this.heightButton, width = null) { let btn = this.add.image(x, y, texture).setOrigin(0.5, 0.5).setInteractive(); btn.on('pointerover', () => btn.setFrame(1)); btn.on('pointerout', () => btn.setFrame(0)); @@ -51,18 +54,16 @@ class AddNode extends Phaser.Scene { } addTitle(x, y, title) { - let sizeText = HEIGHT_WINDOW / 12; - let style = {font: sizeText.toString() + 'px stencil', fill: "#e2e2e2"}; - this.add.text(x, y, title, style).setOrigin(0.5, 0.5); + this.add.text(x, y, title, this.style).setOrigin(0.5, 0.5); } createButtonCancel() { - this.createButton(WIDTH_WINDOW / 3, HEIGHT_WINDOW / (16 / 15), null, HEIGHT_WINDOW / 9, 'cancel') + this.createButton(WIDTH_WINDOW / 3, HEIGHT_WINDOW / (16 / 15), 'cancel', HEIGHT_WINDOW / 9) .on('pointerdown', () => this.cancel()); } createButtonAdd(son) { - this.createButton(WIDTH_WINDOW / 1.5, HEIGHT_WINDOW / (16 / 15), null, HEIGHT_WINDOW / 9, 'add') + this.createButton(WIDTH_WINDOW / 1.5, HEIGHT_WINDOW / (16 / 15), 'add', HEIGHT_WINDOW / 9) .on('pointerdown', () => son.addNode()); } diff --git a/Code/src/js/level3/ManageLang.js b/Code/src/js/level3/ManageLang.js new file mode 100644 index 0000000..556276d --- /dev/null +++ b/Code/src/js/level3/ManageLang.js @@ -0,0 +1,39 @@ +class ManageLang extends Phaser.Scene { + constructor(name, father) { + super(name); + this.name = name; + this.father = father; + this.otherScenes = []; + } + + addOtherScenes(name) { + this.otherScenes.push(name); + } + + create() { + this.createFlags(); + } + + createFlags() { + this.diffXFlag = 0; + this.createFlag('fr'); + this.createFlag('en'); + } + + createFlag(name) { + let flag = this.add.image(WIDTH_WINDOW - 10 - this.diffXFlag, 10, name).setOrigin(1, 0).setInteractive(); + flag.displayHeight = 40; + flag.scaleX = flag.scaleY; + this.diffXFlag = this.diffXFlag + flag.displayWidth + 10; + flag.on('pointerdown', () => this.setLang(name)); + } + + setLang(lang) { + if (lang !== LANG) { + LANG = lang; + this.father.scene.add('LoadFile', new LoadFile(this.father, this.name)); + this.father.scene.start('LoadFile'); + this.otherScenes.forEach(scene => this.father.scene.stop(scene)); + } + } +} \ No newline at end of file