You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
1 line
26 KiB
1 line
26 KiB
class AddAttack extends AddNode{constructor(t,e,s){super(t,e,s)}create(){console.log("ATTACK"),super.create(this),super.addTitle(WIDTH_WINDOW/2,HEIGHT_WINDOW/16,selectWord("ADD NODE : ATTACK","AJOUTER ACTION : ATTAQUE")),super.addTitle(WIDTH_WINDOW/2,HEIGHT_WINDOW/(16/3),selectWord("WHO ?","QUI ?")),super.addTitle(WIDTH_WINDOW/2,HEIGHT_WINDOW/(16/7),selectWord("TARGET FILTERS (OPTIONAL)","FILTRES CIBLES (FACULTATIF)")),super.addButton(WIDTH_WINDOW/2,HEIGHT_WINDOW/3.2,null,HEIGHT_WINDOW/8,"enemyBot",super.newCategory("target",!0,!0),!1);let t=super.newCategory("range",!0,!0);super.addButton(WIDTH_WINDOW/3,HEIGHT_WINDOW/(16/9),null,HEIGHT_WINDOW/8,"shortRange",t,1/3),super.addButton(WIDTH_WINDOW/1.5,HEIGHT_WINDOW/(16/9),null,HEIGHT_WINDOW/8,"mediumRange",t,2/3),super.addButton(WIDTH_WINDOW/2,HEIGHT_WINDOW/(16/12),null,HEIGHT_WINDOW/8,"longRange",t,1)}addNode(){super.verifyCategory()&&(this.selected.addRect(new RectangleNode(this.selected.getX(),this.selected.getY()+200,this.gameR,"attack",this.lCategory[1].getValue())),super.cancel())}}class AddCondition extends AddNode{constructor(t,e,s){super(t,e,s)}create(){super.create(this),console.log("CONDITION"),super.addTitle(WIDTH_WINDOW/2,HEIGHT_WINDOW/16,selectWord("ADD NODE : CONDITION","AJOUTER ACTION : CONDITION")),super.addTitle(WIDTH_WINDOW/2,HEIGHT_WINDOW/(16/3),selectWord("WHO ?","QUI ?")),super.addTitle(WIDTH_WINDOW/2,HEIGHT_WINDOW/(16/7),selectWord("TARGET FILTERS (OPTIONAL)","FILTRES CIBLES (FACULTATIF)"));let t=super.newCategory("target",!0,!0);super.addButton(WIDTH_WINDOW/3,HEIGHT_WINDOW/3.2,null,HEIGHT_WINDOW/8,"enemyBot",t,!1),super.addButton(WIDTH_WINDOW/1.5,HEIGHT_WINDOW/3.2,null,HEIGHT_WINDOW/8,"myself",t,!0);let e=super.newCategory("shield",!0,!0);super.addButton(WIDTH_WINDOW/3,HEIGHT_WINDOW/(16/9),null,HEIGHT_WINDOW/8,"shield0",e,0),super.addButton(WIDTH_WINDOW/1.5,HEIGHT_WINDOW/(16/9),null,HEIGHT_WINDOW/8,"shield33",e,1/3),super.addButton(WIDTH_WINDOW/3,HEIGHT_WINDOW/(16/12),null,HEIGHT_WINDOW/8,"shield66",e,2/3),super.addButton(WIDTH_WINDOW/1.5,HEIGHT_WINDOW/(16/12),null,HEIGHT_WINDOW/8,"shield100",e,1)}addNode(){super.verifyCategory()&&(this.selected.addRect(new RectangleNode(this.selected.getX(),this.selected.getY()+200,this.gameR,"condition",this.lCategory[0].getValue(),!0,!1,this.lCategory[1].getValue(),0)),super.cancel())}}class AddMove extends AddNode{constructor(t,e,s){super(t,e,s)}create(){console.log("MOVE"),super.create(this),super.addTitle(WIDTH_WINDOW/2,HEIGHT_WINDOW/16,selectWord("ADD NODE : MOVE","AJOUTER ACTION : DEPLACEMENT")),super.addTitle(WIDTH_WINDOW/4,HEIGHT_WINDOW/(16/3),selectWord("FLEE OR MOVE ?","RECULER OU AVANCER ?"));let t=super.newCategory("direction",!0,!0);super.addButton(WIDTH_WINDOW/6,HEIGHT_WINDOW/3.2,null,HEIGHT_WINDOW/8,"fleeFrom",t,!1),super.addButton(WIDTH_WINDOW/3,HEIGHT_WINDOW/3.2,null,HEIGHT_WINDOW/8,"moveToward",t,!0),super.addTitle(WIDTH_WINDOW/4*3,HEIGHT_WINDOW/(16/3),selectWord("WHO ?","QUI ?")),super.addButton(WIDTH_WINDOW/4*3,HEIGHT_WINDOW/3.2,null,HEIGHT_WINDOW/8,"enemyBot",super.newCategory("target",!0,!0),!1)}addNode(){super.verifyCategory()&&(this.selected.addRect(new RectangleNode(this.selected.getX(),this.selected.getY()+200,this.gameR,"move",this.lCategory[0].getValue())),super.cancel())}}class Attack{constructor(t=1){t>1/3?t>2/3?(t=1,this.percentBonus=1):(t=2/3,this.percentBonus=1.5):(t=1/3,this.percentBonus=2),this.percentRange=t}do(t){return!(!t.haveTarget()||!t.isTargetInRange(this.percentRange))&&t.attackTarget(this.percentBonus)}}class Boot extends Phaser.Scene{constructor(t){super("Boot"),this.father=t}preload(){let t=this.add.graphics(),e=this.add.graphics(),s=WIDTH_WINDOW/2-160,i=HEIGHT_WINDOW/2-25;e.fillStyle(2236962,.8),e.fillRect(s,i,320,50),this.load.on("progress",function(e){t.clear(),t.fillStyle(16777215,1),t.fillRect(s+10,i+10,300*e,30)}),this.load.on("complete",function(){t.destroy(),e.destroy()}),this.load.audio("shot","assets/sounds/shot.ogg"),this.load.audio("hit","assets/sounds/hit.ogg"),this.loadImage("en","flags/",!0),this.loadImage("fr","flags/",!0),this.loadSprite("playLetter",550,150,"buttons/"),this.loadSprite("cancel",550,150,"buttons/"),this.loadSprite("add",550,150,"buttons/"),this.loadSprite("home",550,150,"buttons/"),this.loadSprite("next",550,150,"buttons/"),this.loadSprite("retry",550,150,"buttons/"),this.loadSprite("duel",269,262,"buttons/"),this.loadSprite("last",269,262,"buttons/"),this.loadSprite("team",269,262,"buttons/"),this.loadSprite("flag",269,262,"buttons/"),this.loadSprite("map",269,262,"buttons/"),this.loadSprite("play",100,100,"buttons/"),this.loadSprite("bin",100,100,"buttons/"),this.loadSprite("plus",100,100,"buttons/"),this.loadSprite("pencil",100,100,"buttons/"),this.loadSprite("back",200,200,"buttons/"),this.loadSprite("shortRange",300,150,"buttons/"),this.loadSprite("mediumRange",300,150,"buttons/"),this.loadSprite("longRange",300,150,"buttons/"),this.loadSprite("shield0",300,150,"buttons/"),this.loadSprite("shield33",300,150,"buttons/"),this.loadSprite("shield66",300,150,"buttons/"),this.loadSprite("shield100",300,150,"buttons/"),this.loadSprite("myself",300,150,"buttons/"),this.loadSprite("enemyBot",300,150,"buttons/"),this.loadSprite("moveToward",300,150,"buttons/"),this.loadSprite("fleeFrom",300,150,"buttons/"),this.loadSprite("attackNode",180,190,"nodes/"),this.loadSprite("moveNode",180,190,"nodes/"),this.loadSprite("conditionNode",180,190,"nodes/"),this.loadImage("background"),this.loadImage("bullet"),this.loadImage("logoWaria"),this.loadImage("attack","nodes/"),this.loadImage("move","nodes/"),this.loadImage("condition","nodes/")}create(){this.add.text(WIDTH_WINDOW/2,HEIGHT_WINDOW/3,"WARIA",{font:"200px stencil",fill:"#e2e2e2"}).setOrigin(.5,.5);let t=this.add.sprite(WIDTH_WINDOW/2,HEIGHT_WINDOW/3*2,"playLetter").setInteractive();t.on("pointerout",()=>t.setFrame(0)),t.on("pointerover",()=>t.setFrame(1)),t.on("pointerdown",()=>this.clickPlay(t)),this.createFlags()}createFlags(){this.diffXFlag=0,this.createFlag("fr"),this.createFlag("en")}createFlag(t){let e=this.add.image(WIDTH_WINDOW-10-this.diffXFlag,10,t).setOrigin(1,0).setInteractive();e.displayHeight=40,e.scaleX=e.scaleY,this.diffXFlag=this.diffXFlag+e.displayWidth+10,e.on("pointerdown",()=>this.setLang(t))}setLang(t){t!==LANG&&(LANG=t,console.log("Set Lang : "+t),this.scene.restart())}clickPlay(t){t.setFrame(2),console.log("Play"),this.father.scene.add("Type",new Type(this.father)),this.scene.start("Type")}loadSprite(t,e,s,i="",h=!1){this.deleteLoad(t),h?this.load.spritesheet(t,"assets/"+i+t+".png",{frameWidth:e,frameHeight:s}):this.load.spritesheet(t,"assets/"+LANG+"/"+i+t+".png",{frameWidth:e,frameHeight:s})}loadImage(t,e="",s=!1){this.deleteLoad(t),s?this.load.image(t,"assets/"+e+t+".png"):this.load.image(t,"assets/"+LANG+"/"+e+t+".png")}deleteLoad(t){this.textures.exists(t)&&this.textures.remove(t)}}class Category{constructor(t="undefined",e=!0,s=!0){this.name=t,this.single=e,this.lBtn=[],this.lValue=[],this.obligatory=s}add(t,e){0!==this.lBtn.length&&this.single&&(this.lBtn[0].clearTint(),this.lValue=[],this.lBtn=[]),this.lValue.push(e),this.lBtn.push(t),t.tint=15718407}getValue(){return this.single?this.lValue[0]:this.lValue}validate(){return!(0===this.lBtn.length&&this.obligatory)}remove(t){let e=this.lBtn.indexOf(t);-1!==e&&(this.lBtn.splice(e,1),this.lValue.splice(e,1)),t.clearTint()}}class Condition{constructor(t,e=!1,s=!1,i,h){this.shieldFilter=e,this.rangeFilter=s,this.shield=i,this.range=h,this.myself=t,this.lNode=[]}addNode(t){this.lNode.push(t)}do(t){if(this.doCondition(t))for(let e=0;e<this.lNode.length;e++)if(this.lNode[e].do(t))return!0;return!1}doCondition(t){if(this.shieldFilter){if(this.shieldCondition(t))return!this.rangeFilter||this.rangeCondition(t)}else if(this.rangeFilter)return this.rangeCondition(t);return!1}rangeCondition(t){return!!this.myself||!!t.haveTarget()&&t.calcDistance(t.target)<=this.range}shieldCondition(t){return this.myself?this.verifyShield(t):!!t.haveTarget()&&this.verifyShield(t.target)}verifyShield(t){return t.shield.value/t.shield.valueMax<=this.shield}clearNodes(){this.lNode=[]}moveToward(t){return t.advanceToTarget()}fleeFrom(t){return t.fleeFromTarget()}}class Game extends Phaser.Scene{constructor(t){super("Game"),this.father=t}preload(){this.gm=new GamingBoard(this),this.father.scene.add("GamingBoard",this.gm)}create(){this.selected=null,this.createButton(),this.scene.launch("GamingBoard"),this.scene.pause("GamingBoard");let t=WIDTH_WINDOW/4*3,e=WIDTH_WINDOW/10;this.tree=new RectangleNode(t,HEIGHT_WINDOW/10,this,"waria"),this.tree.addRect(new RectangleNode(t+e,HEIGHT_WINDOW/3,this,"move",!0)),this.tree.addRect(new RectangleNode(t,HEIGHT_WINDOW/3,this,"attack",1/3));let s=new RectangleNode(t-e,HEIGHT_WINDOW/3,this,"condition",!0,!0,!1,1/3,0);s.addRect(new RectangleNode(t,HEIGHT_WINDOW/1.5,this,"move",!1)),s.addRect(new RectangleNode(t-e,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.gm.listRobot[0].setSpeed(3)}update(t,e){super.update(t,e),this.tree.updateLine()}finish(){let t;console.log("FINISH"),t=this.gm.winner()?new Winner(this.father):new Looser(this.father),this.father.scene.add("Finish",t),this.scene.pause("Game"),this.scene.launch("Finish")}clickNode(){this.pencil.setVisible(!1),this.bin.setVisible(!1),this.plus.setVisible(!1),null!=this.selected&&this.selected.deselect(),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(t,e,s,i){e.setX(s),e.setY(i)}pauseScene(t){this.line=0,this.changeFrame(t,0),this.gm.pause()}resume(){this.line=1;const t=(t,e)=>t.getX()-e.getX();this.tree.lRect.sort(t),this.tree.lRect.forEach(function(e){void 0!==e.lRect&&e.lRect.sort(t)}),this.gm.modifyNodes(this.tree.getNodes()),this.gm.resume()}changeFrame(t,e){t.setFrame(2*this.line+e)}createButton(){let t=WIDTH_MAP+WIDTH_WINDOW/10,e=WIDTH_MAP+HEIGHT_WINDOW/10+5,s=HEIGHT_WINDOW/10,i=HEIGHT_WINDOW/15,h=this.add.sprite(t,e,"play").setOrigin(1,0).setInteractive(),a=this.add.sprite(10,10,"back").setOrigin(0,0).setInteractive();this.pencil=this.add.sprite(t-s,e,"pencil").setOrigin(1,0).setInteractive().setVisible(!1),this.bin=this.add.sprite(t-2*s,e,"bin").setOrigin(1,0).setInteractive().setVisible(!1),this.plus=this.add.sprite(t-3*s,e,"plus").setOrigin(1,0).setInteractive().setVisible(!1),this.line=0,h.displayHeight=h.displayWidth=i,a.displayHeight=a.displayWidth=i,this.pencil.displayHeight=this.pencil.displayWidth=i,this.bin.displayHeight=this.bin.displayWidth=i,this.plus.displayHeight=this.plus.displayWidth=i,this.creatBtnOutAndOver(h),this.creatBtnOutAndOver(a),this.creatBtnOutAndOver(this.pencil),this.creatBtnOutAndOver(this.bin),this.creatBtnOutAndOver(this.plus),h.on("pointerdown",()=>this.clickPlay(h)),a.on("pointerdown",()=>this.clickBack()),this.pencil.on("pointerdown",()=>this.clickPencil()),this.bin.on("pointerdown",()=>this.clickBin()),this.plus.on("pointerdown",()=>this.clickPlus()),this.input.on("pointerdown",()=>this.clickNode()),this.input.on("drag",this.doDrag),this.input.on("dragstart",()=>this.pauseScene(h))}creatBtnOutAndOver(t){t.on("pointerout",()=>this.changeFrame(t,0)),t.on("pointerover",()=>this.changeFrame(t,1))}clickPlay(t){this.scene.isPaused("GamingBoard")?this.resume():this.pauseScene(t),this.changeFrame(t,1)}clickPencil(){console.log("PENCIL"),this.changeFrame(this.pencil,0)}clickBin(){console.log("BIN"),this.tree.delete(this.selected),this.changeFrame(this.bin,0)}clickPlus(){console.log("PLUS"),this.father.scene.add("PlusNode",new PlusNode(this.father,this,this.selected)),this.scene.launch("PlusNode"),this.changeFrame(this.plus,0),this.scene.pause("Game")}clickBack(){console.log("BACK"),this.father.scene.stop("GamingBoard"),this.father.scene.remove("GamingBoard"),this.father.scene.stop("Game"),this.father.scene.start("Type")}}class GamingBoard extends Phaser.Scene{constructor(t){super("GamingBoard"),this.listRobot=[],this.father=t}preload(){this.cameras.main.setViewport(WIDTH_WINDOW/10,HEIGHT_WINDOW/10,WIDTH_MAP,WIDTH_MAP)}create(){this.end=!1,this.sound.add("shot"),this.sound.add("hit"),this.add.image(0,0,"background").alpha=.1;for(let t=0;t<this.listRobot.length;t++)this.chooseTarget(this.listRobot[t]);this.listRobot[0].drawRange(),this.events.on("resume",()=>this.resume()),this.time.addEvent({delay:2e3,callback:this.upShield,callbackScope:this})}update(t,e){super.update(t,e),this.listRobot.forEach(function(t){t.read()});for(let t=0;t<this.listRobot.length;t++)this.listRobot[t].isAlive()?this.listRobot[t].haveTarget()?this.listRobot[t].updateTarget():this.chooseTarget(this.listRobot[t]):(this.listRobot.splice(t,1),t-=1);this.listRobot.length<=1&&!this.end&&(this.end=!0,this.time.addEvent({delay:1e3,callback:this.finish,callbackScope:this}))}finish(){console.log("QUOI ?"),this.pause(),this.father.finish()}winner(){return 0!==this.listRobot.length&&"myself"===this.listRobot[0].name}pause(){this.scene.pause("GamingBoard"),this.sound.pauseAll()}resume(){this.scene.resume("GamingBoard"),this.sound.resumeAll()}addRobot(t){this.listRobot.push(t)}modifyNodes(t){for(let e=0;e<this.listRobot.length;e++)if(this.listRobot[e].name===MYSELF)return this.listRobot[e].cleanNodes(),t.forEach(t=>this.listRobot[0].addNode(t)),!0;return!1}chooseTarget(t){let e=2*WIDTH_MAP,s=[];this.listRobot.forEach(function(i){if(i!==t&&i.isAlive()){let h=Math.hypot(i.x-t.x,i.y-t.y);e>=h&&(e>h&&(e=h,s=[]),s.push(i))}}),this.listRobot.length>1?t.setTarget(s[Math.floor(Math.random()*(s.length+1))]):t.setTarget(s[0])}upShield(){this.listRobot.forEach(t=>t.addShield(SHIELD_PER_SECOND)),this.time.addEvent({delay:1e3,callback:this.upShield,callbackScope:this})}}class HealthBar{constructor(t,e,s,i,h,a,r){this.bar=new Phaser.GameObjects.Graphics(t),this.width=e,this.height=s,this.valueMax=a,this.value=a,this.color=r,this.draw(),this.setX(i),this.setY(h),t.add.existing(this.bar)}decrease(t){this.value-=t;let e=0;return this.value<0&&(e=-this.value,this.value=0),this.draw(),e}increase(t){this.value+=t,this.value>this.valueMax&&(this.value=this.valueMax),this.draw()}setX(t){this.bar.setX(t-this.width/2)}setY(t){this.bar.setY(t)}draw(){this.bar.clear(),this.bar.fillStyle(0),this.bar.fillRect(0,0,this.width,this.height),this.bar.fillStyle(16777215),this.bar.fillRect(2,2,this.width-4,this.height-4);let t=this.value/this.valueMax;t<1/3?this.bar.fillStyle(16711680):this.bar.fillStyle(this.color);let e=Math.floor(t*(this.width-4));this.bar.fillRect(2,2,e,this.height-4)}destroy(){this.bar.destroy()}}class Looser extends Finish{constructor(t){super(t)}create(){super.create(),super.addTitle(selectWord("GAME OVER","PARTIE PERDUE")),super.btnRetry(super.createButton(WIDTH_WINDOW/3,"retry")),super.btnHome(super.createButton(WIDTH_WINDOW/1.5,"home"))}}class Missile extends Phaser.GameObjects.Image{constructor(t,e,s,i){super(t,0,0,e),this.visible=!1,this.setOrigin(.5,.5),this.setScale(.02)}}class Move{constructor(t){this.toward=t}do(t){return!!t.haveTarget()&&(!0===this.toward?this.moveToward(t):this.fleeFrom(t))}moveToward(t){return t.advanceToTarget()}fleeFrom(t){return t.fleeFromTarget()}}class PlusNode extends Phaser.Scene{constructor(t,e,s){super("PlusNode"),this.father=t,this.gameR=e,this.selected=s}create(){this.add.rectangle(0,0,WIDTH_WINDOW,HEIGHT_WINDOW,0).setOrigin(0,0).setAlpha(.5),this.add.rectangle(0,HEIGHT_WINDOW/2,WIDTH_WINDOW,HEIGHT_WINDOW/2,3487290).setOrigin(0,.5),this.createNode(),this.createButton()}createNode(){let t=WIDTH_WINDOW/2,e=HEIGHT_WINDOW/2,s=WIDTH_WINDOW/3,i=HEIGHT_WINDOW/10,h={font:i.toString()+"px stencil",fill:"#e2e2e2"};this.add.text(t-s,e-i,selectWord("ATTACK","ATTAQUE"),h).setOrigin(.5,.5),this.add.text(t,e-i,selectWord("MOVE","DEPLACEMENT"),h).setOrigin(.5,.5),this.add.text(t+s,e-i,selectWord("CONDITION","CONDITION"),h).setOrigin(.5,.5);let a=this.add.sprite(t-s,e+i,"attack").setOrigin(.5,.5).setInteractive().on("pointerdown",()=>this.click("attack"));a.displayHeight=2*i,a.scaleX=a.scaleY,(a=this.add.sprite(t,e+i,"move").setOrigin(.5,.5).setInteractive().on("pointerdown",()=>this.click("move"))).displayHeight=2*i,a.scaleX=a.scaleY,(a=this.add.sprite(t+s,e+i,"condition").setOrigin(.5,.5).setInteractive().on("pointerdown",()=>this.click("condition"))).displayHeight=2*i,a.scaleX=a.scaleY}click(t){switch(t.toString()){case"attack":this.father.scene.add("AddNode",new AddAttack(this.father,this.gameR,this.selected));break;case"move":this.father.scene.add("AddNode",new AddMove(this.father,this.gameR,this.selected));break;case"condition":this.father.scene.add("AddNode",new AddCondition(this.father,this.gameR,this.selected))}this.scene.launch("AddNode"),this.scene.stop("PlusNode"),this.father.scene.remove("PlusNode")}createButton(){let t=WIDTH_WINDOW/2,e=HEIGHT_WINDOW-100,s=this.add.image(t,e,"cancel").setOrigin(.5,.5).setInteractive();s.on("pointerover",()=>s.setFrame(1)),s.on("pointerout",()=>s.setFrame(0)),s.on("pointerdown",()=>this.cancel()),s.displayHeight=HEIGHT_WINDOW/10,s.scaleX=s.scaleY}cancel(){this.scene.resume("Game"),this.scene.stop("PlusNode"),this.father.scene.remove("PlusNode")}}class RectangleNode{constructor(t,e,s,i,...h){switch(i.toString().toLowerCase()){case"attack":this.rect=new Phaser.GameObjects.Image(s,t,e,"attackNode"),this.node=new Attack(h[0]),this.canAddNode=!1,this.line=s.add.graphics(),console.log(3*this.node.percentRange),this.rect.setFrame(3*this.node.percentRange-1);break;case"move":this.rect=new Phaser.GameObjects.Image(s,t,e,"moveNode"),this.node=new Move(h[0]),this.canAddNode=!1,this.line=s.add.graphics(),!0===h[0]?this.rect.setFrame(0):this.rect.setFrame(2);break;case"condition":let a;this.rect=new Phaser.GameObjects.Image(s,t,e,"conditionNode"),this.node=new Condition(h[0],h[1],h[2],h[3],h[4]),this.canAddNode=!0,this.lRect=[],this.scene=s,this.line=s.add.graphics(),a=h[0]?0:1;let r=0;!0===h[1]&&(r=Math.floor(3*h[3])),h[2],this.rect.setFrame(4*a+r);break;case"waria":this.rect=new Phaser.GameObjects.Image(s,t,e,"logoWaria").setInteractive(),this.canAddNode=!0,this.lRect=[],this.scene=s,this.scene.add.existing(this.rect);break;default:return void console.log("Création d'un node echoué")}i.toString().toLowerCase(),this.rect.on("pointerdown",()=>this.click()),this.rect.setOrigin(.5,0),this.rect.displayHeight=HEIGHT_WINDOW/6,this.rect.scaleX=this.rect.scaleY}getSelected(){if(this.rect.isTinted)return this;if(this.canAddNode)for(let t=0;t<this.lRect.length;t++){let e=this.lRect[t].getSelected();if(null!=e)return e}return null}click(){this.rect.isTinted?this.deselect():this.rect.tint=15718407,!0===this.canAddNode&&console.log("THIS CAN ADD NODE")}deselect(){this.rect.clearTint()}getX(){return this.rect.x}getY(){return this.rect.y}addRect(t){if(!0===this.canAddNode){this.lRect.push(t),this.addLine(t);let e=this.scene.add.existing(t.rect);e.setInteractive(),this.scene.input.setDraggable(e),void 0!==this.node&&this.node.addNode(t.node)}}setLine(t,e){this.xOrigin=t,this.yOrigin=e,this.updateLine(!0)}updateLine(t){!0!==t&&this.xLine===this.rect.x&&this.yLine===this.rect.y||void 0===this.line||(this.xLine=this.rect.x,this.yLine=this.rect.y,this.line.clear(),this.line.lineStyle(10,16777215,1),this.line.lineBetween(this.xOrigin,this.yOrigin,this.rect.x,this.rect.y+this.rect.displayHeight/10)),!0===this.canAddNode&&this.lRect.forEach(t=>this.addLine(t))}addLine(t){t.setLine(this.rect.x,this.rect.y+.9*this.rect.displayHeight)}getNodes(){if(void 0===this.node){let t=[];return this.lRect.forEach(function(e){void 0!==e.node&&(void 0!==e.lRect&&(e.node.clearNodes(),e.lRect.forEach(t=>e.node.addNode(t.node))),t.push(e.node))}),t}}destroy(){this.line.destroy(),this.rect.destroy(),void 0!==this.lRect&&this.lRect.forEach(t=>t.destroy())}delete(t){let e=this.lRect.indexOf(t);if(-1!==e)return this.lRect.splice(e,1),t.destroy(),!0;for(let e=0;e<this.lRect.length;e++)if(this.lRect[e].canAddNode&&this.lRect[e].delete(t))return!0;return!1}}class Robot{constructor(t,e,s,i,h,a,r="enemy",n=1){this.speed=n,this.name=r,this.height=t,this.width=e,this.x=s,this.y=i,this.color=h,this.range=WIDTH_MAP/2,this.damage=DAMAGE,this.life=new HealthBar(a,2*this.width,this.width/3,this.x,this.y-this.width,LIFE,32768),this.shield=new HealthBar(a,2*this.width,this.width/3,this.x,this.y-1.5*this.width,SHIELD,255),this.circleRange=null,this.canAttack=!0,this.missile=new Missile(a,"bullet",this.width/5,this.width/4),a.add.existing(this.missile),this.addScene(a),this.lNode=[];let l=new Condition(!0,!0,!1,.5,0);l.addNode(new Move(!1)),this.addNode(l),this.addNode(new Attack),this.addNode(new Move(!0))}addScene(t){this.scene=t,this.circle=this.scene.add.circle(this.x,this.y,this.width/2,this.color).setInteractive(),this.circle.on("pointerdown",()=>this.click())}click(){null===this.circleRange?this.drawRange():this.eraseRange()}addShield(t){this.shield.increase(t)}setX(t){this.x=t,this.circle.setX(this.x),this.life.setX(this.x),this.shield.setX(this.x),this.drawCircleRange()}setY(t){this.y=t,this.life.setY(this.y-this.width),this.shield.setY(this.y-1.5*this.width),this.circle.setY(this.y),this.drawCircleRange()}setTarget(t){this.target=t,this.updateTarget()}updateTarget(){this.verifyTarget()&&this.setTargetPos(this.target.x,this.target.y)}setTargetPos(t,e){let s=this.target.x-this.x,i=this.target.y-this.y,h=Math.hypot(s,i);this.velocityX=s/h*WIDTH_MAP/1e3*SPEED*this.speed,this.velocityY=i/h*WIDTH_MAP/1e3*SPEED*this.speed}setSpeed(t){this.speed=t,this.updateTarget()}advanceToTarget(){return!!this.verifyTarget()&&(this.velocityX>=0&&this.x>=this.target.x||this.velocityX<=0&&this.x<=this.target.x?this.setX(this.target.x):this.setX(this.x+this.velocityX),this.velocityY>=0&&this.y>=this.target.y||this.velocityY<=0&&this.y<=this.target.y?this.setY(this.target.y):this.setY(this.y+this.velocityY),!0)}fleeFromTarget(){return!!this.verifyTarget()&&(this.velocityX>=0&&this.x-this.width/2<=0?this.setX(this.width/2):this.velocityX<=0&&this.x+this.width/2>=WIDTH_MAP?this.setX(WIDTH_MAP-this.width/2):this.setX(this.x-this.velocityX),this.velocityY>=0&&this.y-this.width/2<=0?this.setY(this.height/2):this.velocityY<=0&&this.y+this.width/2>=WIDTH_MAP?this.setY(WIDTH_MAP-this.height/2):this.setY(this.y-this.velocityY),!0)}attackTarget(t=0){return!!(this.verifyTarget()&&this.target.isAlive()&&this.isTargetInRange())&&(this.canAttack&&this.attack(this.target,t),!0)}verifyTarget(){return!!this.haveTarget()&&(!!this.target.isAlive()||(this.setTarget(null),!1))}attack(t,e){this.canAttack=!1,this.missile.setPosition(this.x,this.y).setVisible(!0),this.missile.setRotation(Math.atan2(this.y-this.target.y,this.x-this.target.x)-1.57),this.scene.sound.play("shot");let s=this.calcDistance(this.target)*WIDTH_MAP/1e3;this.scene.tweens.add({targets:this.missile,x:t.x,y:t.y,ease:"Linear",duration:s,onComplete:()=>this.finishAttack(t,e)}),this.scene.time.addEvent({delay:Phaser.Math.Between(1e3,3e3),callback:this.reload,callbackScope:this})}finishAttack(t,e){t.beAttack(this.damage*e)&&this.setTarget(null),this.missile.setVisible(!1)}reload(){this.canAttack=!0}beAttack(t){let e=this.shield.decrease(t),s=this.scene.add.text(this.x,this.y,t.toString(),{font:"40px stencil",fill:"#ffff00"}).setOrigin(0,1);return this.scene.tweens.add({targets:s,x:this.x+30,y:this.y-50,alpha:0,duration:DURATION_DAMAGE,ease:"Sine.easeOut",onComplete:()=>s.destroy()}),this.scene.sound.play("hit"),console.log("HIT"),e>0&&(console.log("Shield Broken"),this.life.decrease(e)),this.die()}isTargetInRange(t=1){return!!this.verifyTarget()&&this.calcDistance(this.target)<this.range*t}calcDistance(t){return Math.hypot(t.x-this.x,t.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 t=0;t<this.lNode.length&&!this.lNode[t].do(this);t++);}addNode(t){this.lNode.push(t)}drawRange(){this.circleRange=this.scene.add.graphics(),this.drawCircleRange()}eraseRange(){this.circleRange.clear(),this.circleRange=null}drawCircleRange(){if(null!==this.circleRange){this.circleRange.clear();let t=32768,e=4,s=1/3;this.circleRange.lineStyle(e,t,s);let i=this.range;this.circleRange.strokeCircle(this.x,this.y,i),t=16744192,s=2/3,this.circleRange.lineStyle(e,t,s),i=2*this.range/3,this.circleRange.strokeCircle(this.x,this.y,i),t=16711680,s=1,this.circleRange.lineStyle(e,t,s),i=this.range/3,this.circleRange.strokeCircle(this.x,this.y,i)}}cleanNodes(){this.lNode=[]}}class Type extends Phaser.Scene{constructor(t){super("Type"),this.father=t}preload(){}create(){this.add.text(WIDTH_WINDOW/2,HEIGHT_WINDOW/4,"WARIA",{font:"200px stencil",fill:"#e2e2e2"}).setOrigin(.5,1);let t=this.add.sprite(WIDTH_WINDOW/8*3,HEIGHT_WINDOW/4*2,"duel").setInteractive();this.createbutton(t);let e=this.add.sprite(WIDTH_WINDOW/8*5,HEIGHT_WINDOW/4*2,"last").setInteractive();this.createbutton(e);let s=this.add.sprite(WIDTH_WINDOW/8*2,HEIGHT_WINDOW/4*3,"team").setInteractive();this.createbutton(s);let i=this.add.sprite(WIDTH_WINDOW/8*4,HEIGHT_WINDOW/4*3,"flag").setInteractive();this.createbutton(i);let h=this.add.sprite(WIDTH_WINDOW/8*6,HEIGHT_WINDOW/4*3,"map").setInteractive();this.createbutton(h)}createbutton(t){t.displayHeight=HEIGHT_WINDOW/4,t.scaleX=t.scaleY,t.on("pointerout",()=>t.setFrame(0)),t.on("pointerover",()=>t.setFrame(1)),t.on("pointerdown",()=>this.clickPlay(t))}clickPlay(t){newGame(this.father),this.scene.start("Game")}}class Winner extends Finish{constructor(t){super(t)}create(){super.create(),super.addTitle(selectWord("WINNER","PARTIE GAGNÉE")),super.btnRetry(super.createButton(WIDTH_WINDOW/4,"retry")),super.btnHome(super.createButton(WIDTH_WINDOW/2,"home")),super.btnNext(super.createButton(WIDTH_WINDOW/4*3,"next"))}} |