diff --git a/Code/public/js/level1.min.js b/Code/public/js/level1.min.js index 4174dee..afe7a85 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_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.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 +class AddAttack extends AddNode{constructor(e,t,s){super(e,t,s)}create(){console.log("ATTACK"),super.create(this),super.addTitle(WIDTH_WINDOW/2,HEIGHT_WINDOW/16,selectWord("ADD NODE : ATTACK","AJOUTER ACTION : ATTAQUE")),super.addTitle(WIDTH_WINDOW/2,HEIGHT_WINDOW/(16/3),selectWord("WHO ?","QUI ?")),super.addTitle(WIDTH_WINDOW/2,HEIGHT_WINDOW/(16/7),selectWord("TARGET FILTERS (OPTIONAL)","FILTRES CIBLES (FACULTATIF)")),super.addButton(WIDTH_WINDOW/2,HEIGHT_WINDOW/3.2,"enemyBot",super.newCategory("target",!0,!0),!1);let e=super.newCategory("range",!0,!0);super.addButton(WIDTH_WINDOW/3,HEIGHT_WINDOW/(16/9),"shortRange",e,1/3),super.addButton(WIDTH_WINDOW/1.5,HEIGHT_WINDOW/(16/9),"mediumRange",e,2/3),super.addButton(WIDTH_WINDOW/2,HEIGHT_WINDOW/(16/12),"longRange",e,1)}addNode(){super.verifyCategory()&&(this.selected.addRect(new RectangleNode(this.selected.getX(),this.selected.getY()+200,this.gameR,"attack",this.lCategory[1].getValue())),super.cancel())}}class AddCondition extends AddNode{constructor(e,t,s){super(e,t,s)}create(){super.create(this),console.log("CONDITION"),super.addTitle(WIDTH_WINDOW/2,HEIGHT_WINDOW/16,selectWord("ADD NODE : CONDITION","AJOUTER ACTION : CONDITION")),super.addTitle(WIDTH_WINDOW/2,HEIGHT_WINDOW/(16/3),selectWord("WHO ?","QUI ?")),super.addTitle(WIDTH_WINDOW/2,HEIGHT_WINDOW/(16/7),selectWord("TARGET FILTERS (OPTIONAL)","FILTRES CIBLES (FACULTATIF)"));let e=super.newCategory("target",!0,!0);super.addButton(WIDTH_WINDOW/3,HEIGHT_WINDOW/3.2,"enemyBot",e,!1),super.addButton(WIDTH_WINDOW/1.5,HEIGHT_WINDOW/3.2,"myself",e,!0);let t=super.newCategory("shield",!0,!0);super.addButton(WIDTH_WINDOW/3,HEIGHT_WINDOW/(16/9),"shield0",t,0),super.addButton(WIDTH_WINDOW/1.5,HEIGHT_WINDOW/(16/9),"shield33",t,1/3),super.addButton(WIDTH_WINDOW/3,HEIGHT_WINDOW/(16/12),"shield66",t,2/3),super.addButton(WIDTH_WINDOW/1.5,HEIGHT_WINDOW/(16/12),"shield100",t,1)}addNode(){super.verifyCategory()&&(this.selected.addRect(new RectangleNode(this.selected.getX(),this.selected.getY()+200,this.gameR,"condition",this.lCategory[0].getValue(),!0,!1,this.lCategory[1].getValue(),0)),super.cancel())}}class AddMove extends AddNode{constructor(e,t,s){super(e,t,s)}create(){console.log("MOVE"),super.create(this),super.addTitle(WIDTH_WINDOW/2,HEIGHT_WINDOW/16,selectWord("ADD NODE : MOVE","AJOUTER ACTION : DEPLACEMENT")),super.addTitle(WIDTH_WINDOW/4,HEIGHT_WINDOW/(16/3),selectWord("FLEE OR MOVE ?","RECULER OU AVANCER ?"));let e=super.newCategory("direction",!0,!0);super.addButton(WIDTH_WINDOW/6,HEIGHT_WINDOW/3.2,"fleeFrom",e,!1),super.addButton(WIDTH_WINDOW/3,HEIGHT_WINDOW/3.2,"moveToward",e,!0),super.addTitle(WIDTH_WINDOW/4*3,HEIGHT_WINDOW/(16/3),selectWord("WHO ?","QUI ?"));let t=super.newCategory("target",!0,!0);super.addButton(WIDTH_WINDOW/6*4,HEIGHT_WINDOW/3.2,"enemyBot",t,!0),super.addButton(WIDTH_WINDOW/6*5,HEIGHT_WINDOW/3.2,"bonus",t,!1)}addNode(){super.verifyCategory()&&(this.selected.addRect(new RectangleNode(this.selected.getX(),this.selected.getY()+200,this.gameR,"move",this.lCategory[0].getValue(),this.lCategory[1].getValue())),super.cancel())}}class Attack{constructor(e=1){e>1/3?e>2/3?(e=1,this.percentBonus=1):(e=2/3,this.percentBonus=1.5):(e=1/3,this.percentBonus=2),this.percentRange=e}do(e){return!(!e.haveTarget()||!e.isTargetInRange(this.percentRange))&&e.attackTarget(this.percentBonus)}getFrame(){return 3*this.percentRange-1}}class Bar extends HealthBar{constructor(e,t,s,i,h,a,n,r){super(e,t,s,i,h,n,r,r),this.scene=e,this.scene.input.on("pointerdown",this.doDrag,this);let o={font:s.toString()+"px stencil",fill:"#e2e2e2"};this.text=this.scene.add.text(this.bar.x+this.width+10,this.bar.y,this.value.toString(),o).setOrigin(0,0),this.setValue(a)}doDrag(){let e=this.scene.input;e.x>=this.bar.x&&e.x<=this.bar.x+this.width&&e.y>=this.bar.y&&e.y<=this.bar.y+this.height&&(this.scene.pauseScene(),this.clickOn())}clickOn(){this.onMove(),this.scene.input.on("pointermove",()=>this.onMove()),this.scene.input.on("pointerup",()=>this.stopClick())}stopClick(){this.scene.input.off("pointermove"),this.scene.input.off("pointerup")}onMove(){this.setValWithX(this.scene.input.x)}setValWithX(e){this.setValue(Math.round((e-this.bar.x)/this.width*this.valueMax))}draw(){super.draw();let e=this.value/this.valueMax*this.width-5;this.bar.fillStyle(9868950),this.bar.fillRect(e,0,10,this.height),void 0!==this.text&&this.text.setText(this.value.toString())}}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=h&&(s>h&&(s=h,i=[]),i.push(t))}}),i.length>1?i[Math.floor(Math.random()*(i.length+1))]:i[0]}class Game extends ManageLang{constructor(e){super("Game",e),super.addOtherScenes("GamingBoard"),SPEED_GAME=1}create(){super.create(),this.doLine=!1,this.gm=new GamingBoard(this),-1!==this.father.scene.getIndex("GamingBoard")&&this.father.scene.remove("GamingBoard"),this.father.scene.add("GamingBoard",this.gm),this.scene.launch("GamingBoard"),this.scene.pause("GamingBoard"),this.selected=null,this.damageRobot=new Bar(this,200,30,OFFX_MAP+WIDTH_MAP/4,OFFY_MAP/2,DAMAGE_BEGIN,5,COLOR_ATTACK),this.speedReloadRobot=new Bar(this,200,30,OFFX_MAP+WIDTH_MAP/4,0,SPEED_RELOAD_BEGIN,5,COLOR_SPEED_RELOAD),this.speedRobot=new Bar(this,200,30,OFFX_MAP+WIDTH_MAP/4*3,0,SPEED,5,COLOR_MOVE),this.rangeRobot=new Bar(this,200,30,OFFX_MAP+WIDTH_MAP/4*3,OFFY_MAP/2,RANGE_BEGIN,5,COLOR_RANGE),this.createButton();let e=WIDTH_WINDOW/4*3,t=WIDTH_WINDOW/10;this.tree=new RectangleNode(e,HEIGHT_WINDOW/10,this,"waria"),this.tree.addRect(new RectangleNode(e-2*t,HEIGHT_WINDOW/3,this,"move",!0,!1)),this.tree.addRect(new RectangleNode(e+t,HEIGHT_WINDOW/3,this,"move",!0)),this.tree.addRect(new RectangleNode(e,HEIGHT_WINDOW/3,this,"attack",1/3));let s=new RectangleNode(e-t,HEIGHT_WINDOW/3,this,"condition",!0,!0,!1,1/3,0);s.addRect(new RectangleNode(e,HEIGHT_WINDOW/1.5,this,"move",!1)),s.addRect(new RectangleNode(e-t,HEIGHT_WINDOW/1.5,this,"attack")),this.tree.addRect(s),this.gm.addRobot(new Robot(.1*WIDTH_MAP,.1*WIDTH_MAP,.9*WIDTH_MAP,.9*WIDTH_MAP,6711039,this.gm,MYSELF)),this.gm.addRobot(new Robot(.1*WIDTH_MAP,.1*WIDTH_MAP,.2*WIDTH_MAP,.1*WIDTH_MAP,16711680,this.gm)),this.gm.addRobot(new Robot(.1*WIDTH_MAP,.1*WIDTH_MAP,.1*WIDTH_MAP,.9*WIDTH_MAP,16711680,this.gm)),this.input.keyboard.on("keydown-DELETE",()=>{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(){console.log("NODE"),this.tryClick(),this.selected=this.tree.getSelected(),null!==this.selected&&(this.selected!==this.tree&&(this.pencil.setVisible(!0),this.bin.setVisible(!0)),this.selected.canAddNode&&this.plus.setVisible(!0))}doDrag(e,t,s,i){t.setX(s),t.setY(i)}dragStart(){console.log("START DRAG"),this.doLine=!0,this.pauseScene()}dragEnd(){console.log("END DRAG"),this.doLine=!1}pauseScene(){this.linePlay=0,this.changeFrame(this.play,0),this.gm.pause()}resume(){this.linePlay=1;this.tree.sort((e,t)=>e.getX()-t.getX()),this.gm.modifyNodes(this.tree.getNode()),this.gm.modifyValue(this.speedRobot.value,this.rangeRobot.value,this.speedReloadRobot.value,this.damageRobot.value),this.gm.resume()}changeFrame(e,t=0,s=0){e.setFrame(t+2*s)}createButton(){let e=WIDTH_MAP+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();this.play=this.add.sprite(e,t,"play").setOrigin(1,0).setInteractive();let a=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 n=this.add.sprite(e-5*s,t,"mute").setOrigin(1,0).setInteractive();this.linePlay=0,this.lineSpeed=1===SPEED_GAME?0:1,this.changeFrame(a,0,this.lineSpeed),this.father.sound.mute?this.lineMute=1:this.lineMute=0,this.changeFrame(n,0,this.lineMute),h.displayHeight=h.displayWidth=i,this.play.displayHeight=this.play.displayWidth=i,a.displayHeight=a.displayWidth=i,n.displayHeight=n.displayWidth=i,this.pencil.displayHeight=this.pencil.displayWidth=i,this.bin.displayHeight=this.bin.displayWidth=i,this.plus.displayHeight=this.plus.displayWidth=i,this.play.on("pointerout",()=>this.changeFrame(this.play,0,this.linePlay)),this.play.on("pointerover",()=>this.changeFrame(this.play,1,this.linePlay)),a.on("pointerout",()=>this.changeFrame(a,0,this.lineSpeed)),a.on("pointerover",()=>this.changeFrame(a,1,this.lineSpeed)),n.on("pointerout",()=>this.changeFrame(n,0,this.lineMute)),n.on("pointerover",()=>this.changeFrame(n,1,this.lineMute)),this.creatBtnOutAndOver(h),this.creatBtnOutAndOver(this.pencil),this.creatBtnOutAndOver(this.bin),this.creatBtnOutAndOver(this.plus),this.play.on("pointerdown",()=>this.clickPlay()),a.on("pointerdown",()=>this.clickSpeed(a)),h.on("pointerdown",()=>this.clickBack()),n.on("pointerdown",()=>this.clickMute(n)),this.pencil.on("pointerdown",()=>this.clickPencil()),this.bin.on("pointerdown",()=>this.clickBin()),this.plus.on("pointerdown",()=>this.clickPlus()),this.input.on("pointerdown",()=>this.clickNode()),this.input.on("drag",this.doDrag),this.input.on("dragstart",()=>this.dragStart()),this.input.on("dragend",()=>this.dragEnd())}creatBtnOutAndOver(e){e.on("pointerout",()=>this.changeFrame(e,0)),e.on("pointerover",()=>this.changeFrame(e,1))}clickPlay(){this.scene.isPaused("GamingBoard")?this.resume():this.pauseScene(),this.changeFrame(this.play,1,this.linePlay)}clickSpeed(e){1===SPEED_GAME?(SPEED_GAME=2,this.lineSpeed=1):(SPEED_GAME=1,this.lineSpeed=0),this.changeFrame(e,1,this.lineSpeed)}clickPencil(){console.log("PENCIL"),this.changeFrame(this.pencil,0)}clickBin(){null!==this.selected&&(console.log("BIN"),this.tree.delete(this.selected),this.changeFrame(this.bin,0),this.tryClick())}clickPlus(){console.log("PLUS"),this.father.scene.add("PlusNode",new PlusNode(this.father,this,this.selected)),this.scene.launch("PlusNode"),this.changeFrame(this.plus,0),this.scene.pause("Game")}clickBack(){console.log("BACK"),this.father.scene.stop("GamingBoard"),this.father.scene.remove("GamingBoard"),this.father.scene.stop("Game"),this.father.scene.start("Type")}clickMute(e){console.log("MUTE"),this.father.sound.mute?(this.father.sound.mute=!1,this.lineMute=0):(this.father.sound.mute=!0,this.lineMute=1),this.changeFrame(e,1,this.lineMute)}tryClick(){this.pencil.setVisible(!1),this.bin.setVisible(!1),this.plus.setVisible(!1),null!=this.selected&&(this.selected.deselect(),this.selected=null)}}class GamingBoard extends Phaser.Scene{constructor(e){super("GamingBoard"),this.listRobot=[],listBonus=[],this.father=e,this.end=!1}preload(){this.cameras.main.setViewport(OFFX_MAP,OFFY_MAP,WIDTH_MAP,WIDTH_MAP),this.sound.add("shot"),this.sound.add("hit")}create(){listBonus.push(new BonusSpeed("Balle Argent",this,WIDTH_MAP/2,WIDTH_MAP/2,3,2e3)),this.add.image(0,0,"background").alpha=.1;for(let e=0;et.addNode(e)),!0)}modifyValue(e,t,s,i){let h=this.getMyRobot();return void 0!==h&&(h.setSpeed(e),h.setRange(t),h.setSpeedReload(s),h.setDamage(i),!0)}getMyRobot(){for(let e=0;ee.addShield(SHIELD_PER_SECOND)),this.time.addEvent({delay:1e3/SPEED_GAME,callback:this.upShield,callbackScope:this})}}class LoadFile extends Phaser.Scene{constructor(e,t,s){super("LoadFile"),this.father=e,this.son=s,this.nameSon=t,this.father.scene.pause(this.nameSon),this.father.scene.stop(this.nameSon),this.father.scene.remove("LoadFile")}preload(){let e=this.add.graphics(),t=this.add.graphics(),s=WIDTH_WINDOW/2-160,i=HEIGHT_WINDOW/2-25;t.fillStyle(2236962,.8),t.fillRect(s,i,320,50),this.load.on("progress",function(t){e.clear(),e.fillStyle(16777215,1),e.fillRect(s+10,i+10,300*t,30)}),this.load.on("complete",()=>{e.destroy(),t.destroy(),-1===this.father.scene.getIndex(this.nameSon)&&this.father.scene.add(this.nameSon,this.son),this.father.scene.start(this.nameSon)}),this.load.audio("shot","assets/sounds/shot.ogg"),this.load.audio("hit","assets/sounds/hit.ogg"),this.loadImage("en","flags/",!0),this.loadImage("fr","flags/",!0),this.loadImage("bonusSpeed0","bonus/",!0),this.loadImage("bonusSpeed1","bonus/",!0),this.loadImage("bonusSpeed2","bonus/",!0),this.loadImage("enemy","robots/"),this.loadSprite("playLetter",550,150,"buttons/"),this.loadSprite("cancel",550,150,"buttons/"),this.loadSprite("add",550,150,"buttons/"),this.loadSprite("home",550,150,"buttons/"),this.loadSprite("next",550,150,"buttons/"),this.loadSprite("retry",550,150,"buttons/"),this.loadSprite("duel",269,262,"buttons/"),this.loadSprite("last",269,262,"buttons/"),this.loadSprite("team",269,262,"buttons/"),this.loadSprite("flag",269,262,"buttons/"),this.loadSprite("map",269,262,"buttons/"),this.loadSprite("play",100,100,"buttons/"),this.loadSprite("bin",100,100,"buttons/"),this.loadSprite("plus",100,100,"buttons/"),this.loadSprite("pencil",100,100,"buttons/"),this.loadSprite("speed",100,100,"buttons/"),this.loadSprite("mute",100,100,"buttons/"),this.loadSprite("back",200,200,"buttons/"),this.loadSprite("shortRange",300,150,"buttons/"),this.loadSprite("mediumRange",300,150,"buttons/"),this.loadSprite("longRange",300,150,"buttons/"),this.loadSprite("shield0",300,150,"buttons/"),this.loadSprite("shield33",300,150,"buttons/"),this.loadSprite("shield66",300,150,"buttons/"),this.loadSprite("shield100",300,150,"buttons/"),this.loadSprite("myself",300,150,"buttons/"),this.loadSprite("enemyBot",300,150,"buttons/"),this.loadSprite("bonus",300,150,"buttons/"),this.loadSprite("moveToward",300,150,"buttons/"),this.loadSprite("fleeFrom",300,150,"buttons/"),this.loadSprite("attackNode",180,190,"nodes/",!0),this.loadSprite("moveNode",180,190,"nodes/",!0),this.loadSprite("conditionNode",180,190,"nodes/",!0),this.loadImage("background"),this.loadImage("bullet"),this.loadImage("logoWaria"),this.loadImage("attack","nodes/",!0),this.loadImage("move","nodes/",!0),this.loadImage("condition","nodes/",!0)}loadSprite(e,t,s,i="",h=!1){this.deleteLoad(e),h?this.load.spritesheet(e,"assets/"+i+e+".png",{frameWidth:t,frameHeight:s}):this.load.spritesheet(e,"assets/"+LANG+"/"+i+e+".png",{frameWidth:t,frameHeight:s})}loadImage(e,t="",s=!1){this.deleteLoad(e),s?this.load.image(e,"assets/"+t+e+".png"):this.load.image(e,"assets/"+LANG+"/"+t+e+".png")}deleteLoad(e){this.textures.exists(e)&&this.textures.remove(e)}}class Looser extends Finish{constructor(e){super(e)}create(){super.create(),super.addTitle(selectWord("GAME OVER","PARTIE PERDUE")),super.btnRetry(super.createButton(WIDTH_WINDOW/3,"retry")),super.btnHome(super.createButton(WIDTH_WINDOW/1.5,"home"))}}class Missile extends Phaser.GameObjects.Image{constructor(e,t,s,i){super(e,0,0,t),this.visible=!1,this.setOrigin(.5,.5),this.setScale(.02)}}class Move{constructor(e,t=!0){this.toward=e,this.enemyBot=t}do(e){if(this.enemyBot){if(e.verifyTarget())return!0===this.toward?this.moveToward(e):this.fleeFrom(e)}else{let t=chooseTarget(e,listBonus);if(void 0!==t){let s;return(s=!0===this.toward?this.moveToward(e,t):this.fleeFrom(e,t))||(t.useOn(e),listBonus.splice(listBonus.indexOf(t),1)),!0}}return!1}moveToward(e,t=e.target){return e.advanceTo(t)}fleeFrom(e,t=e.target){return e.fleeFrom(t)}getFrame(){let e;return e=this.toward?0:2,this.enemyBot||(e+=1),e}}class PlusNode extends Phaser.Scene{constructor(e,t,s){super("PlusNode"),this.father=e,this.gameR=t,this.selected=s}create(){this.add.rectangle(0,0,WIDTH_WINDOW,HEIGHT_WINDOW,0).setOrigin(0,0).setAlpha(.5),this.add.rectangle(0,HEIGHT_WINDOW/2,WIDTH_WINDOW,HEIGHT_WINDOW/2,3487290).setOrigin(0,.5),this.createNode(),this.createButton()}createNode(){let e=WIDTH_WINDOW/2,t=HEIGHT_WINDOW/2,s=WIDTH_WINDOW/3,i=HEIGHT_WINDOW/10,h={font:(i/1.5).toString()+"px stencil",fill:"#e2e2e2"};this.add.text(e-s,t-i,selectWord("ATTACK","ATTAQUE"),h).setOrigin(.5,.5),this.add.text(e,t-i,selectWord("MOVE","DEPLACEMENT"),h).setOrigin(.5,.5),this.add.text(e+s,t-i,selectWord("CONDITION","CONDITION"),h).setOrigin(.5,.5);let a=this.add.sprite(e-s,t+i,"attack").setOrigin(.5,.5).setInteractive().on("pointerdown",()=>this.click("attack"));a.displayHeight=2*i,a.scaleX=a.scaleY,(a=this.add.sprite(e,t+i,"move").setOrigin(.5,.5).setInteractive().on("pointerdown",()=>this.click("move"))).displayHeight=2*i,a.scaleX=a.scaleY,(a=this.add.sprite(e+s,t+i,"condition").setOrigin(.5,.5).setInteractive().on("pointerdown",()=>this.click("condition"))).displayHeight=2*i,a.scaleX=a.scaleY}click(e){switch(e.toString()){case"attack":this.father.scene.add("AddNode",new AddAttack(this.father,this.gameR,this.selected));break;case"move":this.father.scene.add("AddNode",new AddMove(this.father,this.gameR,this.selected));break;case"condition":this.father.scene.add("AddNode",new AddCondition(this.father,this.gameR,this.selected))}this.scene.launch("AddNode"),this.scene.stop("PlusNode"),this.father.scene.remove("PlusNode")}createButton(){let e=WIDTH_WINDOW/2,t=HEIGHT_WINDOW-100,s=this.add.image(e,t,"cancel").setOrigin(.5,.5).setInteractive();s.on("pointerover",()=>s.setFrame(1)),s.on("pointerout",()=>s.setFrame(0)),s.on("pointerdown",()=>this.cancel()),s.displayHeight=HEIGHT_WINDOW/10,s.scaleX=s.scaleY}cancel(){this.scene.resume("Game"),this.scene.stop("PlusNode"),this.father.scene.remove("PlusNode")}}class RectangleNode{constructor(e,t,s,i,...h){switch(i.toString().toLowerCase()){case"attack":this.rect=new Phaser.GameObjects.Image(s,e,t,"attackNode"),this.node=new Attack(h[0]),this.canAddNode=!1,this.line=s.add.graphics();break;case"move":this.rect=new Phaser.GameObjects.Image(s,e,t,"moveNode"),this.node=new Move(h[0],h[1]),this.canAddNode=!1,this.line=s.add.graphics();break;case"condition":this.rect=new Phaser.GameObjects.Image(s,e,t,"conditionNode"),this.node=new Condition(h[0],h[1],h[2],h[3],h[4]),this.canAddNode=!0,this.lRect=[],this.scene=s,this.line=s.add.graphics();break;case"waria":this.rect=new Phaser.GameObjects.Image(s,e,t,"logoWaria").setInteractive(),this.canAddNode=!0,this.lRect=[],this.scene=s,this.scene.add.existing(this.rect),this.scene.input.setDraggable(this.rect);break;default:return void console.log("Création d'un node echoué")}"waria"!==i.toString().toLowerCase()&&this.rect.setFrame(this.node.getFrame()),this.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){}setDamage(e=this.damage){this.damage=e}setRange(e=this.range){this.range=e,this.drawCircleRange()}setSpeed(e=this.speed){this.speed=e}setSpeedReload(e=this.speedReload){this.speedReload=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:TIME_RELOAD/this.speedReload/SPEED_GAME,callback:this.reload,callbackScope:this})}finishAttack(e,t){e.beAttack(this.damage*DAMAGE*t)&&this.setTarget(null),this.missile.setVisible(!1)}reload(){this.canAttack=!0}beAttack(e){let t=this.shield.decrease(e),s={font:HEIGHT_DAMAGE.toString()+"px stencil",fill:"#ffff00"},i=this.scene.add.text(this.x,this.y,e.toString(),s).setOrigin(0,1);return this.scene.tweens.add({targets:i,x:this.x+30,y:this.y-50,alpha:0,duration:DURATION_DAMAGE,ease:"Sine.easeOut",onComplete:()=>i.destroy()}),this.scene.sound.play("hit"),console.log("HIT"),t>0&&(console.log("Shield Broken"),this.life.decrease(t)),this.die()}isTargetInRange(e=1){return!!this.haveTarget()&&this.calcDistance(this.target)<=this.range*RANGE*e}calcDistance(e){return Math.hypot(e.x-this.x,e.y-this.y)}isAlive(){return this.life.value>0}die(){return 0===this.life.value&&(null!==this.circleRange&&this.circleRange.destroy(),this.circle.destroy(),this.shield.destroy(),this.life.destroy(),!0)}haveTarget(){return null!=this.target}read(){for(let e=0;ee.setFrame(0)),e.on("pointerover",()=>e.setFrame(1)),e.on("pointerdown",()=>this.clickPlay(e))}clickPlay(e){newGame(this.father),this.scene.start("Game")}}var listBonus=[],LANG=navigator.language.substr(0,2).toLowerCase(),SPEED_GAME=1;const MYSELF="myself",SHIELD_PER_SECOND=5,COLOR_ATTACK=16711680,COLOR_MOVE=255,COLOR_CONDITION=921102,COLOR_RED=16711680,COLOR_ORANGE=16744192,COLOR_GREEN=32768,COLOR_RANGE=32768,COLOR_SPEED_RELOAD=8323327,WIDTH_WINDOW=$(document).width()-20,HEIGHT_WINDOW=$(document).height()-20,WIDTH_MAP=WIDTH_WINDOWthis.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 +class AddNode extends Phaser.Scene{constructor(t,e,s){super("AddNode"),this.father=t,this.gameR=e,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(t){let e=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,e,3487290).setOrigin(0,.5),this.createButtonCancel(),this.createButtonAdd(t)}addButton(t,e,s,i=new Category,a){let h=this.createButton(t,e,s);return h.on("pointerdown",()=>this.click(h,i,a)),h}createButton(t,e,s,i=this.heightButton,a=null){let h=this.add.image(t,e,s).setOrigin(.5,.5).setInteractive();return h.on("pointerover",()=>h.setFrame(1)),h.on("pointerout",()=>h.setFrame(0)),h.displayHeight=i,null===a?h.scaleX=h.scaleY:h.displayWidth=a,h}click(t,e,s){t.isTinted?e.remove(t):e.add(t,s)}newCategory(t,e,s){let i=new Category(t,e,s);return this.lCategory.push(i),i}addTitle(t,e,s){this.add.text(t,e,s,this.style).setOrigin(.5,.5)}createButtonCancel(){this.createButton(WIDTH_WINDOW/3,HEIGHT_WINDOW/(16/15),"cancel",HEIGHT_WINDOW/9).on("pointerdown",()=>this.cancel())}createButtonAdd(t){this.createButton(WIDTH_WINDOW/1.5,HEIGHT_WINDOW/(16/15),"add",HEIGHT_WINDOW/9).on("pointerdown",()=>t.addNode())}verifyCategory(){for(let t=0;ts.setFrame(1)),s.on("pointerout",()=>s.setFrame(0)),s.displayHeight=HEIGHT_WINDOW/9,s.scaleX=s.scaleY,s}btnRetry(t){t.on("pointerdown",()=>this.retry())}retry(){console.log("RETRY"),this.close(),newGame(this.father),this.father.scene.start("Game")}btnHome(t){t.on("pointerdown",()=>this.home())}home(){console.log("HOME"),this.close(),this.father.scene.start("Type")}btnNext(t){t.on("pointerdown",()=>this.next())}next(){console.log("NEXT")}close(){this.sound.stopAll(),this.father.scene.remove("GamingBoard"),this.father.scene.remove("Game"),this.father.scene.remove("Finish")}}class HealthBar{constructor(t,e,s,i,a,h,r,n=COLOR_RED){this.bar=new Phaser.GameObjects.Graphics(t),this.width=Math.floor(e),this.height=Math.floor(s),this.valueMax=h,this.value=h,this.color=r,this.colorMin=n,this.draw(),this.setX(i),this.setY(a),t.add.existing(this.bar)}setValue(t){t<0&&(t=0),t>this.valueMax&&(t=this.valueMax),t!==this.value&&(this.value=t,this.draw())}decrease(t){this.value-=t;let e=0;return this.value<0&&(e=-this.value,this.value=0),this.draw(),e}getBar(){return this.bar}increase(t){this.value+=t,this.value>this.valueMax&&(this.value=this.valueMax),this.draw()}setX(t){this.bar.setX(t-this.width/2)}setY(t){this.bar.setY(t)}draw(){this.bar.clear(),this.bar.fillStyle(0),this.bar.fillRect(0,0,this.width,this.height),this.bar.fillStyle(16777215),this.bar.fillRect(2,2,this.width-4,this.height-4);let t=this.value/this.valueMax;t<1/3?this.bar.fillStyle(this.colorMin):this.bar.fillStyle(this.color);let e=Math.floor(t*(this.width-4));this.bar.fillRect(2,2,e,this.height-4)}destroy(){this.bar.destroy()}}class ManageLang extends Phaser.Scene{constructor(t,e){super(t),this.name=t,this.father=e,this.otherScenes=[]}addOtherScenes(t){this.otherScenes.push(t)}create(){this.createFlags()}createFlags(){this.diffXFlag=0,this.createFlag("fr"),this.createFlag("en")}createFlag(t){let e=this.add.image(WIDTH_WINDOW-10-this.diffXFlag,10,t).setOrigin(1,0).setInteractive();e.displayHeight=40,e.scaleX=e.scaleY,this.diffXFlag=this.diffXFlag+e.displayWidth+10,e.on("pointerdown",()=>this.setLang(t))}setLang(t){t!==LANG&&(LANG=t,this.father.scene.add("LoadFile",new LoadFile(this.father,this.name)),this.father.scene.start("LoadFile"),this.otherScenes.forEach(t=>this.father.scene.stop(t)))}} \ No newline at end of file diff --git a/Code/src/js/level1/Init.js b/Code/src/js/level1/Init.js index dae8f49..2417afc 100644 --- a/Code/src/js/level1/Init.js +++ b/Code/src/js/level1/Init.js @@ -1,65 +1,4 @@ -function selectWord(en, fr) { - switch (LANG) { - case 'fr': - return fr; - default: - return en; - } -} - -function newGame(father) { - if (father.scene.getIndex('Game') !== -1) { - father.scene.remove('Game'); - } - father.scene.add('Game', new Game(father)); -} - -function chooseTarget(robot, list) { - let minDist = WIDTH_MAP * 2; - let l = []; - list.forEach(function (item) { - if (item !== robot) { - let hypot = Math.hypot(item.x - robot.x, item.y - robot.y); - if (minDist >= hypot) { - if (minDist > hypot) { - minDist = hypot; - l = []; - } - l.push(item); - } - } - }); - if (l.length > 1) { - return l[Math.floor(Math.random() * (l.length + 1))]; - } else { - return l[0]; - } -} - - -var listBonus = []; -var LANG = navigator.language.substr(0, 2).toLowerCase(); -var SPEED_GAME = 1; -const MYSELF = 'myself'; -const SHIELD_PER_SECOND = 5; -const COLOR_ATTACK = 0xff0000; -const COLOR_MOVE = 0x0000ff; -const COLOR_CONDITION = 0x0e0e0e; -const WIDTH_WINDOW = $(document).width() - 20; -const HEIGHT_WINDOW = $(document).height() - 20; -const WIDTH_MAP = WIDTH_WINDOW < HEIGHT_WINDOW ? WIDTH_WINDOW * 0.8 : HEIGHT_WINDOW * 0.8; -const SPEED = 2; -const LIFE = 100; -const DAMAGE = 40; -const SHIELD = 100; -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 = { +let config = { type: Phaser.AUTO, width: WIDTH_WINDOW, height: HEIGHT_WINDOW, diff --git a/Code/src/js/level2/Bar.js b/Code/src/js/level2/Bar.js new file mode 100644 index 0000000..40db811 --- /dev/null +++ b/Code/src/js/level2/Bar.js @@ -0,0 +1,47 @@ +class Bar extends HealthBar { + constructor(scene, width, height, x, y, startValue, valueMax, color) { + super(scene, width, height, x, y, valueMax, color, color); + this.scene = scene; + this.scene.input.on('pointerdown', this.doDrag, this); + let style = {font: height.toString() + 'px stencil', fill: "#e2e2e2"}; + this.text = this.scene.add.text(this.bar.x + this.width + 10, this.bar.y, this.value.toString(), style).setOrigin(0, 0); + this.setValue(startValue); + } + + doDrag() { + let pointer = this.scene.input; + if (pointer.x >= this.bar.x && pointer.x <= this.bar.x + this.width && pointer.y >= this.bar.y && pointer.y <= this.bar.y + this.height) { + this.scene.pauseScene(); + this.clickOn(); + } + } + + clickOn() { + this.onMove(); + this.scene.input.on('pointermove', () => this.onMove()); + this.scene.input.on('pointerup', () => this.stopClick()); + } + + stopClick() { + this.scene.input.off('pointermove'); + this.scene.input.off('pointerup'); + } + + onMove() { + this.setValWithX(this.scene.input.x); + } + + setValWithX(posX) { + this.setValue(Math.round((posX - this.bar.x) / this.width * this.valueMax)); + } + + draw() { + super.draw(); + let posX = this.value / this.valueMax * this.width - 5; + this.bar.fillStyle(0x969696); + this.bar.fillRect(posX, 0, 10, this.height); + if (this.text !== undefined) { + this.text.setText(this.value.toString()); + } + } +} \ No newline at end of file diff --git a/Code/src/js/level2/Function.js b/Code/src/js/level2/Function.js new file mode 100644 index 0000000..71e59b7 --- /dev/null +++ b/Code/src/js/level2/Function.js @@ -0,0 +1,37 @@ +function selectWord(en, fr) { + switch (LANG) { + case 'fr': + return fr; + default: + return en; + } +} + +function newGame(father) { + if (father.scene.getIndex('Game') !== -1) { + father.scene.remove('Game'); + } + father.scene.add('Game', new Game(father)); +} + +function chooseTarget(robot, list) { + let minDist = WIDTH_MAP * 2; + let l = []; + list.forEach(function (item) { + if (item !== robot) { + let hypot = Math.hypot(item.x - robot.x, item.y - robot.y); + if (minDist >= hypot) { + if (minDist > hypot) { + minDist = hypot; + l = []; + } + l.push(item); + } + } + }); + if (l.length > 1) { + return l[Math.floor(Math.random() * (l.length + 1))]; + } else { + return l[0]; + } +} \ No newline at end of file diff --git a/Code/src/js/level2/Game.js b/Code/src/js/level2/Game.js index f4159b7..b40bc3c 100644 --- a/Code/src/js/level2/Game.js +++ b/Code/src/js/level2/Game.js @@ -18,6 +18,12 @@ class Game extends ManageLang { this.selected = null; + + this.damageRobot = new Bar(this, 200, 30, OFFX_MAP + WIDTH_MAP / 4, OFFY_MAP / 2, DAMAGE_BEGIN, 5, COLOR_ATTACK); + this.speedReloadRobot = new Bar(this, 200, 30, OFFX_MAP + WIDTH_MAP / 4, 0, SPEED_RELOAD_BEGIN, 5, COLOR_SPEED_RELOAD); + this.speedRobot = new Bar(this, 200, 30, OFFX_MAP + WIDTH_MAP / 4 * 3, 0, SPEED, 5, COLOR_MOVE); + this.rangeRobot = new Bar(this, 200, 30, OFFX_MAP + WIDTH_MAP / 4 * 3, OFFY_MAP / 2, RANGE_BEGIN, 5, COLOR_RANGE); + this.createButton(); let centerX = WIDTH_WINDOW / 4 * 3; @@ -66,6 +72,7 @@ class Game extends ManageLang { clickNode() { + console.log("NODE"); this.tryClick(); this.selected = this.tree.getSelected(); @@ -86,11 +93,11 @@ class Game extends ManageLang { target.setY(dragY); } - dragStart(btn) { + dragStart() { console.log("START DRAG"); this.doLine = true; - this.pauseScene(btn); + this.pauseScene(); } dragEnd() { @@ -100,9 +107,9 @@ class Game extends ManageLang { } - pauseScene(btn) { + pauseScene() { this.linePlay = 0; - this.changeFrame(btn, 0); + this.changeFrame(this.play, 0); this.gm.pause(); } @@ -113,6 +120,7 @@ class Game extends ManageLang { let sortDesc = (a, b) => a.getX() - b.getX(); this.tree.sort(sortDesc); this.gm.modifyNodes(this.tree.getNode()); + this.gm.modifyValue(this.speedRobot.value, this.rangeRobot.value, this.speedReloadRobot.value, this.damageRobot.value); this.gm.resume(); } @@ -130,7 +138,7 @@ class Game extends ManageLang { let back = this.add.sprite(10, 10, 'back').setOrigin(0, 0).setInteractive(); - let play = this.add.sprite(x, y, 'play').setOrigin(1, 0).setInteractive(); + this.play = this.add.sprite(x, y, 'play').setOrigin(1, 0).setInteractive(); let speed = this.add.sprite(x - diffX, y, 'speed').setOrigin(1, 0).setInteractive(); this.pencil = this.add.sprite(x - diffX * 2, y, 'pencil').setOrigin(1, 0).setInteractive().setVisible(false); @@ -155,15 +163,15 @@ class Game extends ManageLang { back.displayHeight = back.displayWidth = width; - play.displayHeight = play.displayWidth = width; + this.play.displayHeight = this.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; - play.on('pointerout', () => this.changeFrame(play, 0, this.linePlay)); - play.on('pointerover', () => this.changeFrame(play, 1, this.linePlay)); + this.play.on('pointerout', () => this.changeFrame(this.play, 0, this.linePlay)); + this.play.on('pointerover', () => this.changeFrame(this.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)); @@ -173,7 +181,7 @@ class Game extends ManageLang { this.creatBtnOutAndOver(this.bin); this.creatBtnOutAndOver(this.plus); - play.on('pointerdown', () => this.clickPlay(play)); + this.play.on('pointerdown', () => this.clickPlay()); speed.on('pointerdown', () => this.clickSpeed(speed)); back.on('pointerdown', () => this.clickBack()); mute.on('pointerdown', () => this.clickMute(mute)); @@ -183,7 +191,7 @@ class Game extends ManageLang { this.input.on('pointerdown', () => this.clickNode()); this.input.on('drag', this.doDrag); - this.input.on('dragstart', () => this.dragStart(play)); + this.input.on('dragstart', () => this.dragStart()); this.input.on('dragend', () => this.dragEnd()); } @@ -192,13 +200,13 @@ class Game extends ManageLang { btn.on('pointerover', () => this.changeFrame(btn, 1)); } - clickPlay(btn) { + clickPlay() { if (this.scene.isPaused('GamingBoard')) this.resume(); else - this.pauseScene(btn); + this.pauseScene(); - this.changeFrame(btn, 1, this.linePlay); + this.changeFrame(this.play, 1, this.linePlay); } clickSpeed(btn) { diff --git a/Code/src/js/level2/GamingBoard.js b/Code/src/js/level2/GamingBoard.js index 900abb6..d43f1c3 100644 --- a/Code/src/js/level2/GamingBoard.js +++ b/Code/src/js/level2/GamingBoard.js @@ -8,7 +8,7 @@ class GamingBoard extends Phaser.Scene { } preload() { - this.cameras.main.setViewport(WIDTH_WINDOW / 10, HEIGHT_WINDOW / 10, WIDTH_MAP, WIDTH_MAP); + this.cameras.main.setViewport(OFFX_MAP, OFFY_MAP, WIDTH_MAP, WIDTH_MAP); this.sound.add('shot'); this.sound.add('hit'); } @@ -58,7 +58,7 @@ class GamingBoard extends Phaser.Scene { } winner() { - return this.listRobot.length !== 0 && this.listRobot[0].name === 'myself'; + return this.getMyRobot() !== undefined; } pause() { @@ -76,14 +76,34 @@ class GamingBoard extends Phaser.Scene { } modifyNodes(lNodes) { + let myRobot = this.getMyRobot(); + if (myRobot !== undefined) { + myRobot.cleanNodes(); + lNodes.forEach(element => myRobot.addNode(element)); + return true; + } + return false; + } + + modifyValue(speed, range, speedReload, damage) { + let myRobot = this.getMyRobot(); + if (myRobot !== undefined) { + myRobot.setSpeed(speed); + myRobot.setRange(range); + myRobot.setSpeedReload(speedReload); + myRobot.setDamage(damage); + return true; + } + return false; + } + + getMyRobot() { for (let i = 0; i < this.listRobot.length; i++) { if (this.listRobot[i].name === MYSELF) { - this.listRobot[i].cleanNodes(); - lNodes.forEach(element => this.listRobot[0].addNode(element)); - return true; + return this.listRobot[i]; } } - return false; + return undefined; } diff --git a/Code/src/js/level2/Robot.js b/Code/src/js/level2/Robot.js index de3b941..08530f6 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.speedReload = SPEED_RELOAD_BEGIN; this.timeReload = TIME_RELOAD; this.name = name; this.height = height; @@ -8,8 +9,8 @@ class Robot { this.x = posX; this.y = posY; this.color = color; - this.range = WIDTH_MAP / 2; - this.damage = DAMAGE; + this.range = RANGE_BEGIN; + this.damage = DAMAGE_BEGIN; this.life = new HealthBar(scene, this.width * 2, this.width / 3, this.x, this.y - this.width, LIFE, 0x008000); this.shield = new HealthBar(scene, this.width * 2, this.width / 3, this.x, this.y - this.width * 1.5, SHIELD, 0x0000FF); this.circleRange = null; @@ -80,10 +81,23 @@ class Robot { setTargetPos(x, y) { } - setSpeed(speed) { + setDamage(damage = this.damage) { + this.damage = damage; + } + + setRange(range = this.range) { + this.range = range; + this.drawCircleRange(); + } + + setSpeed(speed = this.speed) { this.speed = speed; } + setSpeedReload(speedReload = this.speedReload) { + this.speedReload = speedReload; + } + increaseSpeed(amount) { this.speed += amount; } @@ -217,14 +231,14 @@ class Robot { }); this.scene.time.addEvent({ - delay: this.timeReload / SPEED_GAME, + delay: TIME_RELOAD / this.speedReload / SPEED_GAME, callback: this.reload, callbackScope: this }); } finishAttack(target, percentBonus) { - if (target.beAttack(this.damage * percentBonus)) { + if (target.beAttack(this.damage * DAMAGE * percentBonus)) { this.setTarget(null); } this.missile.setVisible(false); @@ -262,7 +276,7 @@ class Robot { isTargetInRange(percentRange = 1) { if (this.haveTarget()) { - return this.calcDistance(this.target) < this.range * percentRange; + return this.calcDistance(this.target) <= this.range * RANGE * percentRange; } return false; } @@ -319,23 +333,23 @@ class Robot { this.circleRange.clear(); - let color = 0x008000; + let color = COLOR_GREEN; let thickness = 4; let alpha = 1 / 3; this.circleRange.lineStyle(thickness, color, alpha); - let radius = this.range; + let radius = this.range * RANGE; this.circleRange.strokeCircle(this.x, this.y, radius); - color = 0xff7f00; + color = COLOR_ORANGE; alpha = 2 / 3; this.circleRange.lineStyle(thickness, color, alpha); - radius = this.range * 2 / 3; + radius = this.range * RANGE * 2 / 3; this.circleRange.strokeCircle(this.x, this.y, radius); - color = 0xff0000; + color = COLOR_RED; alpha = 1; this.circleRange.lineStyle(thickness, color, alpha); - radius = this.range / 3; + radius = this.range * RANGE / 3; this.circleRange.strokeCircle(this.x, this.y, radius); } } diff --git a/Code/src/js/level2/Variable.js b/Code/src/js/level2/Variable.js new file mode 100644 index 0000000..0b8d6e1 --- /dev/null +++ b/Code/src/js/level2/Variable.js @@ -0,0 +1,30 @@ +var listBonus = []; +var LANG = navigator.language.substr(0, 2).toLowerCase(); +var SPEED_GAME = 1; +const MYSELF = 'myself'; +const SHIELD_PER_SECOND = 5; +const COLOR_ATTACK = 0xff0000; +const COLOR_MOVE = 0x0000ff; +const COLOR_CONDITION = 0x0e0e0e; +const COLOR_RED = 0xff0000; +const COLOR_ORANGE = 0xff7f00; +const COLOR_GREEN = 0x008000; +const COLOR_RANGE = 0x008000; +const COLOR_SPEED_RELOAD = 0x7f00ff; +const WIDTH_WINDOW = $(document).width() - 20; +const HEIGHT_WINDOW = $(document).height() - 20; +const WIDTH_MAP = WIDTH_WINDOW < HEIGHT_WINDOW ? WIDTH_WINDOW * 0.8 : HEIGHT_WINDOW * 0.8; +const OFFX_MAP = WIDTH_WINDOW / 20; +const OFFY_MAP = WIDTH_WINDOW / 20; +const SPEED = 2; +const LIFE = 100; +const DAMAGE = 10; +const DAMAGE_BEGIN = 3; +const SHIELD = 100; +const RANGE_BEGIN = 2; +const RANGE = WIDTH_MAP / 4; +const HEIGHT_BONUS = WIDTH_MAP / 10; +const HEIGHT_DAMAGE = WIDTH_MAP / 20; +const DURATION_DAMAGE = 700; +const TIME_RELOAD = 4000; +const SPEED_RELOAD_BEGIN = 2; \ No newline at end of file diff --git a/Code/src/js/level2/HealthBar.js b/Code/src/js/level3/HealthBar.js similarity index 75% rename from Code/src/js/level2/HealthBar.js rename to Code/src/js/level3/HealthBar.js index 266274f..01b8c48 100644 --- a/Code/src/js/level2/HealthBar.js +++ b/Code/src/js/level3/HealthBar.js @@ -1,5 +1,5 @@ class HealthBar { - constructor(scene, width, height, x, y, valueMax, color) { + constructor(scene, width, height, x, y, valueMax, color, colorMin = COLOR_RED) { this.bar = new Phaser.GameObjects.Graphics(scene); this.width = Math.floor(width); @@ -7,6 +7,7 @@ class HealthBar { this.valueMax = valueMax; this.value = valueMax; this.color = color; + this.colorMin = colorMin; this.draw(); @@ -15,6 +16,19 @@ class HealthBar { scene.add.existing(this.bar); } + setValue(value) { + if (value < 0) { + value = 0; + } + if (value > this.valueMax) { + value = this.valueMax; + } + if (value !== this.value) { + this.value = value; + this.draw(); + } + } + decrease(amount) { this.value -= amount; @@ -29,6 +43,10 @@ class HealthBar { return diff; } + getBar() { + return this.bar; + } + increase(amount) { this.value += amount; if (this.value > this.valueMax) { @@ -60,7 +78,7 @@ class HealthBar { let percent = this.value / this.valueMax; if (percent < 1 / 3) { - this.bar.fillStyle(0xff0000); + this.bar.fillStyle(this.colorMin); } else { this.bar.fillStyle(this.color); }