diff --git a/Code/assets/en/buttons/home.png b/Code/assets/en/buttons/home.png new file mode 100644 index 0000000..d1f6b6f Binary files /dev/null and b/Code/assets/en/buttons/home.png differ diff --git a/Code/assets/en/buttons/next.png b/Code/assets/en/buttons/next.png new file mode 100644 index 0000000..939add4 Binary files /dev/null and b/Code/assets/en/buttons/next.png differ diff --git a/Code/assets/en/buttons/retry.png b/Code/assets/en/buttons/retry.png new file mode 100644 index 0000000..bcc60ae Binary files /dev/null and b/Code/assets/en/buttons/retry.png differ diff --git a/Code/assets/fr/buttons/home.png b/Code/assets/fr/buttons/home.png new file mode 100644 index 0000000..90555ad Binary files /dev/null and b/Code/assets/fr/buttons/home.png differ diff --git a/Code/assets/fr/buttons/next.png b/Code/assets/fr/buttons/next.png new file mode 100644 index 0000000..42afdb1 Binary files /dev/null and b/Code/assets/fr/buttons/next.png differ diff --git a/Code/assets/fr/buttons/retry.png b/Code/assets/fr/buttons/retry.png new file mode 100644 index 0000000..13fea72 Binary files /dev/null and b/Code/assets/fr/buttons/retry.png differ diff --git a/Code/assets/sounds/hit.ogg b/Code/assets/sounds/hit.ogg new file mode 100644 index 0000000..e274916 Binary files /dev/null and b/Code/assets/sounds/hit.ogg differ diff --git a/Code/assets/sounds/shot.ogg b/Code/assets/sounds/shot.ogg new file mode 100644 index 0000000..d910ca1 Binary files /dev/null and b/Code/assets/sounds/shot.ogg differ diff --git a/Code/public/js/level1.min.js b/Code/public/js/level1.min.js index 4146eae..fcdbfdf 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}}var LANG=navigator.language.substr(0,2).toLowerCase();const 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?t>2/3?1:2/3:1/3,this.percentRange=t}do(t){return!(!t.haveTarget()||!t.isTargetInRange(this.percentRange))&&t.attackTarget()}}class Boot extends Phaser.Scene{constructor(t){super("Boot"),this.father=t}preload(){let t=this.add.graphics(),e=this.add.graphics(),i=WIDTH_WINDOW/2-160,s=HEIGHT_WINDOW/2-25;e.fillStyle(2236962,.8),e.fillRect(i,s,320,50),this.load.on("progress",function(e){t.clear(),t.fillStyle(16777215,1),t.fillRect(i+10,s+10,300*e,30)}),this.load.on("complete",function(){t.destroy(),e.destroy()}),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("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.scene.start("Type")}loadSprite(t,e,i,s="",h=!1){this.deleteLoad(t),h?this.load.spritesheet(t,"assets/"+s+t+".png",{frameWidth:e,frameHeight:i}):this.load.spritesheet(t,"assets/"+LANG+"/"+s+t+".png",{frameWidth:e,frameHeight:i})}loadImage(t,e="",i=!1){this.deleteLoad(t),i?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,i=!0){this.name=t,this.single=e,this.lBtn=[],this.lValue=[],this.obligatory=i}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,i=!1,s,h){this.shieldFilter=e,this.rangeFilter=i,this.shield=s,this.range=h,this.myself=t,this.lNode=[]}addNode(t){this.lNode.push(t)}do(t){if(this.doCondition(t))for(let e=0;et.getX()-e.getX();this.tree.lRect.sort(t),this.tree.lRect.forEach(function(e){void 0!==e.lRect&&e.lRect.sort(t)}),this.gm.modifyNodes(this.tree.getNodes()),this.scene.resume("GamingBoard")}createButton(){let t=WIDTH_MAP+WIDTH_WINDOW/10,e=WIDTH_MAP+HEIGHT_WINDOW/10+5,i=HEIGHT_WINDOW/10,s=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-i,e,"pencil").setOrigin(1,0).setInteractive().setVisible(!1),this.bin=this.add.sprite(t-2*i,e,"bin").setOrigin(1,0).setInteractive().setVisible(!1),this.plus=this.add.sprite(t-3*i,e,"plus").setOrigin(1,0).setInteractive().setVisible(!1),this.line=0,h.displayHeight=h.displayWidth=s,a.displayHeight=a.displayWidth=s,this.pencil.displayHeight=this.pencil.displayWidth=s,this.bin.displayHeight=this.bin.displayWidth=s,this.plus.displayHeight=this.plus.displayWidth=s,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(){super("GamingBoard"),this.listRobot=[]}preload(){this.cameras.main.setViewport(WIDTH_WINDOW/10,HEIGHT_WINDOW/10,WIDTH_MAP,WIDTH_MAP)}create(){this.add.image(0,0,"background").alpha=.1;for(let t=0;tthis.resume()),this.time.addEvent({delay:2e3,callback:this.upShield,callbackScope:this})}update(t,e){super.update(t,e),this.listRobot.forEach(function(t){t.read()});for(let t=0;tthis.listRobot[0].addNode(t))}chooseTarget(t){let e=2*WIDTH_MAP,i=[];this.listRobot.forEach(function(s){if(s!==t&&s.isAlive()){let h=Math.hypot(s.x-t.x,s.y-t.y);e>=h&&(e>h&&(e=h,i=[]),i.push(s))}}),this.listRobot.length>1?t.setTarget(i[Math.floor(Math.random()*(i.length+1))]):t.setTarget(i[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,i,s,h,a,r){this.bar=new Phaser.GameObjects.Graphics(t),this.width=e,this.height=i,this.valueMax=a,this.value=a,this.color=r,this.draw(),this.setX(s),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 Missile extends Phaser.GameObjects.Image{constructor(t,e,i,s){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,i){super("PlusNode"),this.father=t,this.gameR=e,this.selected=i}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,i=WIDTH_WINDOW/3,s=HEIGHT_WINDOW/10,h={font:s.toString()+"px stencil",fill:"#e2e2e2"};this.add.text(t-i,e-s,selectWord("ATTACK","ATTAQUE"),h).setOrigin(.5,.5),this.add.text(t,e-s,selectWord("MOVE","DEPLACEMENT"),h).setOrigin(.5,.5),this.add.text(t+i,e-s,selectWord("CONDITION","CONDITION"),h).setOrigin(.5,.5);let a=this.add.sprite(t-i,e+s,"attack").setOrigin(.5,.5).setInteractive().on("pointerdown",()=>this.click("attack"));a.displayHeight=2*s,a.scaleX=a.scaleY,(a=this.add.sprite(t,e+s,"move").setOrigin(.5,.5).setInteractive().on("pointerdown",()=>this.click("move"))).displayHeight=2*s,a.scaleX=a.scaleY,(a=this.add.sprite(t+i,e+s,"condition").setOrigin(.5,.5).setInteractive().on("pointerdown",()=>this.click("condition"))).displayHeight=2*s,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,i=this.add.image(t,e,"cancel").setOrigin(.5,.5).setInteractive();i.on("pointerover",()=>i.setFrame(1)),i.on("pointerout",()=>i.setFrame(0)),i.on("pointerdown",()=>this.cancel()),i.displayHeight=HEIGHT_WINDOW/10,i.scaleX=i.scaleY}cancel(){this.scene.resume("Game"),this.scene.stop("PlusNode"),this.father.scene.remove("PlusNode")}}class RectangleNode{constructor(t,e,i,s,...h){switch(s.toString().toLowerCase()){case"attack":this.rect=new Phaser.GameObjects.Image(i,t,e,"attackNode"),this.node=new Attack(h[0]),this.canAddNode=!1,this.line=i.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(i,t,e,"moveNode"),this.node=new Move(h[0]),this.canAddNode=!1,this.line=i.add.graphics(),!0===h[0]?this.rect.setFrame(0):this.rect.setFrame(2);break;case"condition":let a;this.rect=new Phaser.GameObjects.Image(i,t,e,"conditionNode"),this.node=new Condition(h[0],h[1],h[2],h[3],h[4]),this.canAddNode=!0,this.lRect=[],this.scene=i,this.line=i.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(i,t,e,"logoWaria").setInteractive(),this.canAddNode=!0,this.lRect=[],this.scene=i,this.scene.add.existing(this.rect);break;default:return void console.log("Création d'un node echoué")}s.toString().toLowerCase(),this.rect.on("pointerdown",()=>this.click()),this.rect.setOrigin(.5,0),this.rect.displayHeight=HEIGHT_WINDOW/6,this.rect.scaleX=this.rect.scaleY}getSelected(){if(this.rect.isTinted)return this;if(this.canAddNode)for(let t=0;tthis.addLine(t))}addLine(t){t.setLine(this.rect.x,this.rect.y+.9*this.rect.displayHeight)}getNodes(){if(void 0===this.node){let t=[];return this.lRect.forEach(function(e){void 0!==e.node&&(void 0!==e.lRect&&(e.node.clearNodes(),e.lRect.forEach(t=>e.node.addNode(t.node))),t.push(e.node))}),t}}destroy(){this.line.destroy(),this.rect.destroy(),void 0!==this.lRect&&this.lRect.forEach(t=>t.destroy())}delete(t){let e=this.lRect.indexOf(t);if(-1!==e)return this.lRect.splice(e,1),t.destroy(),!0;for(let e=0;ethis.click())}click(){null===this.circleRange?this.drawRange():this.eraseRange()}addShield(t){this.shield.increase(t)}setX(t){this.x=t,this.circle.setX(this.x),this.life.setX(this.x),this.shield.setX(this.x),this.drawCircleRange()}setY(t){this.y=t,this.life.setY(this.y-this.width),this.shield.setY(this.y-1.5*this.width),this.circle.setY(this.y),this.drawCircleRange()}setTarget(t){this.target=t,this.updateTarget()}updateTarget(){this.verifyTarget()&&this.setTargetPos(this.target.x,this.target.y)}setTargetPos(t,e){let i=this.target.x-this.x,s=this.target.y-this.y,h=Math.hypot(i,s);this.velocityX=i/h*WIDTH_MAP/1e3*SPEED*this.speed,this.velocityY=s/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(){return!!(this.verifyTarget()&&this.target.isAlive()&&this.isTargetInRange())&&(this.canAttack&&this.attack(this.target),!0)}verifyTarget(){return!!this.haveTarget()&&(!!this.target.isAlive()||(this.setTarget(null),!1))}attack(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.tweens.add({targets:this.missile,x:t.x,y:t.y,ease:"Linear",duration:200,onComplete:()=>this.finishAttack(t)}),this.scene.time.addEvent({delay:Phaser.Math.Between(1e3,3e3),callback:this.reload,callbackScope:this})}finishAttack(t){t.beAttack(this.damage)&&this.setTarget(null),this.missile.setVisible(!1)}reload(){this.canAttack=!0}beAttack(t){let e=this.shield.decrease(t);return e>0&&(console.log("Shield Broken"),this.life.decrease(e)),this.die()}isTargetInRange(t=1){return!!this.verifyTarget()&&this.calcDistance(this.target)0}die(){return 0===this.life.value&&(null!==this.circleRange&&this.circleRange.destroy(),this.circle.destroy(),this.shield.destroy(),this.life.destroy(),!0)}haveTarget(){return null!=this.target}read(){for(let t=0;tt.setFrame(0)),t.on("pointerover",()=>t.setFrame(1)),t.on("pointerdown",()=>this.clickPlay(t))}clickPlay(t){this.scene.start("Game")}} \ No newline at end of file +class AddAttack extends AddNode{constructor(t,e,s){super(t,e,s)}create(){console.log("ATTACK"),super.create(this),super.addTitle(WIDTH_WINDOW/2,HEIGHT_WINDOW/16,selectWord("ADD NODE : ATTACK","AJOUTER ACTION : ATTAQUE")),super.addTitle(WIDTH_WINDOW/2,HEIGHT_WINDOW/(16/3),selectWord("WHO ?","QUI ?")),super.addTitle(WIDTH_WINDOW/2,HEIGHT_WINDOW/(16/7),selectWord("TARGET FILTERS (OPTIONAL)","FILTRES CIBLES (FACULTATIF)")),super.addButton(WIDTH_WINDOW/2,HEIGHT_WINDOW/3.2,null,HEIGHT_WINDOW/8,"enemyBot",super.newCategory("target",!0,!0),!1);let t=super.newCategory("range",!0,!0);super.addButton(WIDTH_WINDOW/3,HEIGHT_WINDOW/(16/9),null,HEIGHT_WINDOW/8,"shortRange",t,1/3),super.addButton(WIDTH_WINDOW/1.5,HEIGHT_WINDOW/(16/9),null,HEIGHT_WINDOW/8,"mediumRange",t,2/3),super.addButton(WIDTH_WINDOW/2,HEIGHT_WINDOW/(16/12),null,HEIGHT_WINDOW/8,"longRange",t,1)}addNode(){super.verifyCategory()&&(this.selected.addRect(new RectangleNode(this.selected.getX(),this.selected.getY()+200,this.gameR,"attack",this.lCategory[1].getValue())),super.cancel())}}class AddCondition extends AddNode{constructor(t,e,s){super(t,e,s)}create(){super.create(this),console.log("CONDITION"),super.addTitle(WIDTH_WINDOW/2,HEIGHT_WINDOW/16,selectWord("ADD NODE : CONDITION","AJOUTER ACTION : CONDITION")),super.addTitle(WIDTH_WINDOW/2,HEIGHT_WINDOW/(16/3),selectWord("WHO ?","QUI ?")),super.addTitle(WIDTH_WINDOW/2,HEIGHT_WINDOW/(16/7),selectWord("TARGET FILTERS (OPTIONAL)","FILTRES CIBLES (FACULTATIF)"));let t=super.newCategory("target",!0,!0);super.addButton(WIDTH_WINDOW/3,HEIGHT_WINDOW/3.2,null,HEIGHT_WINDOW/8,"enemyBot",t,!1),super.addButton(WIDTH_WINDOW/1.5,HEIGHT_WINDOW/3.2,null,HEIGHT_WINDOW/8,"myself",t,!0);let e=super.newCategory("shield",!0,!0);super.addButton(WIDTH_WINDOW/3,HEIGHT_WINDOW/(16/9),null,HEIGHT_WINDOW/8,"shield0",e,0),super.addButton(WIDTH_WINDOW/1.5,HEIGHT_WINDOW/(16/9),null,HEIGHT_WINDOW/8,"shield33",e,1/3),super.addButton(WIDTH_WINDOW/3,HEIGHT_WINDOW/(16/12),null,HEIGHT_WINDOW/8,"shield66",e,2/3),super.addButton(WIDTH_WINDOW/1.5,HEIGHT_WINDOW/(16/12),null,HEIGHT_WINDOW/8,"shield100",e,1)}addNode(){super.verifyCategory()&&(this.selected.addRect(new RectangleNode(this.selected.getX(),this.selected.getY()+200,this.gameR,"condition",this.lCategory[0].getValue(),!0,!1,this.lCategory[1].getValue(),0)),super.cancel())}}class AddMove extends AddNode{constructor(t,e,s){super(t,e,s)}create(){console.log("MOVE"),super.create(this),super.addTitle(WIDTH_WINDOW/2,HEIGHT_WINDOW/16,selectWord("ADD NODE : MOVE","AJOUTER ACTION : DEPLACEMENT")),super.addTitle(WIDTH_WINDOW/4,HEIGHT_WINDOW/(16/3),selectWord("FLEE OR MOVE ?","RECULER OU AVANCER ?"));let t=super.newCategory("direction",!0,!0);super.addButton(WIDTH_WINDOW/6,HEIGHT_WINDOW/3.2,null,HEIGHT_WINDOW/8,"fleeFrom",t,!1),super.addButton(WIDTH_WINDOW/3,HEIGHT_WINDOW/3.2,null,HEIGHT_WINDOW/8,"moveToward",t,!0),super.addTitle(WIDTH_WINDOW/4*3,HEIGHT_WINDOW/(16/3),selectWord("WHO ?","QUI ?")),super.addButton(WIDTH_WINDOW/4*3,HEIGHT_WINDOW/3.2,null,HEIGHT_WINDOW/8,"enemyBot",super.newCategory("target",!0,!0),!1)}addNode(){super.verifyCategory()&&(this.selected.addRect(new RectangleNode(this.selected.getX(),this.selected.getY()+200,this.gameR,"move",this.lCategory[0].getValue())),super.cancel())}}class Attack{constructor(t=1){t>1/3?t>2/3?(t=1,this.percentBonus=1):(t=2/3,this.percentBonus=1.5):(t=1/3,this.percentBonus=2),this.percentRange=t}do(t){return!(!t.haveTarget()||!t.isTargetInRange(this.percentRange))&&t.attackTarget(this.percentBonus)}}class Boot extends Phaser.Scene{constructor(t){super("Boot"),this.father=t}preload(){let t=this.add.graphics(),e=this.add.graphics(),s=WIDTH_WINDOW/2-160,i=HEIGHT_WINDOW/2-25;e.fillStyle(2236962,.8),e.fillRect(s,i,320,50),this.load.on("progress",function(e){t.clear(),t.fillStyle(16777215,1),t.fillRect(s+10,i+10,300*e,30)}),this.load.on("complete",function(){t.destroy(),e.destroy()}),this.load.audio("shot","assets/sounds/shot.ogg"),this.load.audio("hit","assets/sounds/hit.ogg"),this.loadImage("en","flags/",!0),this.loadImage("fr","flags/",!0),this.loadSprite("playLetter",550,150,"buttons/"),this.loadSprite("cancel",550,150,"buttons/"),this.loadSprite("add",550,150,"buttons/"),this.loadSprite("home",550,150,"buttons/"),this.loadSprite("next",550,150,"buttons/"),this.loadSprite("retry",550,150,"buttons/"),this.loadSprite("duel",269,262,"buttons/"),this.loadSprite("last",269,262,"buttons/"),this.loadSprite("team",269,262,"buttons/"),this.loadSprite("flag",269,262,"buttons/"),this.loadSprite("map",269,262,"buttons/"),this.loadSprite("play",100,100,"buttons/"),this.loadSprite("bin",100,100,"buttons/"),this.loadSprite("plus",100,100,"buttons/"),this.loadSprite("pencil",100,100,"buttons/"),this.loadSprite("back",200,200,"buttons/"),this.loadSprite("shortRange",300,150,"buttons/"),this.loadSprite("mediumRange",300,150,"buttons/"),this.loadSprite("longRange",300,150,"buttons/"),this.loadSprite("shield0",300,150,"buttons/"),this.loadSprite("shield33",300,150,"buttons/"),this.loadSprite("shield66",300,150,"buttons/"),this.loadSprite("shield100",300,150,"buttons/"),this.loadSprite("myself",300,150,"buttons/"),this.loadSprite("enemyBot",300,150,"buttons/"),this.loadSprite("moveToward",300,150,"buttons/"),this.loadSprite("fleeFrom",300,150,"buttons/"),this.loadSprite("attackNode",180,190,"nodes/"),this.loadSprite("moveNode",180,190,"nodes/"),this.loadSprite("conditionNode",180,190,"nodes/"),this.loadImage("background"),this.loadImage("bullet"),this.loadImage("logoWaria"),this.loadImage("attack","nodes/"),this.loadImage("move","nodes/"),this.loadImage("condition","nodes/")}create(){this.add.text(WIDTH_WINDOW/2,HEIGHT_WINDOW/3,"WARIA",{font:"200px stencil",fill:"#e2e2e2"}).setOrigin(.5,.5);let t=this.add.sprite(WIDTH_WINDOW/2,HEIGHT_WINDOW/3*2,"playLetter").setInteractive();t.on("pointerout",()=>t.setFrame(0)),t.on("pointerover",()=>t.setFrame(1)),t.on("pointerdown",()=>this.clickPlay(t)),this.createFlags()}createFlags(){this.diffXFlag=0,this.createFlag("fr"),this.createFlag("en")}createFlag(t){let e=this.add.image(WIDTH_WINDOW-10-this.diffXFlag,10,t).setOrigin(1,0).setInteractive();e.displayHeight=40,e.scaleX=e.scaleY,this.diffXFlag=this.diffXFlag+e.displayWidth+10,e.on("pointerdown",()=>this.setLang(t))}setLang(t){t!==LANG&&(LANG=t,console.log("Set Lang : "+t),this.scene.restart())}clickPlay(t){t.setFrame(2),console.log("Play"),this.father.scene.add("Type",new Type(this.father)),this.scene.start("Type")}loadSprite(t,e,s,i="",h=!1){this.deleteLoad(t),h?this.load.spritesheet(t,"assets/"+i+t+".png",{frameWidth:e,frameHeight:s}):this.load.spritesheet(t,"assets/"+LANG+"/"+i+t+".png",{frameWidth:e,frameHeight:s})}loadImage(t,e="",s=!1){this.deleteLoad(t),s?this.load.image(t,"assets/"+e+t+".png"):this.load.image(t,"assets/"+LANG+"/"+e+t+".png")}deleteLoad(t){this.textures.exists(t)&&this.textures.remove(t)}}class Category{constructor(t="undefined",e=!0,s=!0){this.name=t,this.single=e,this.lBtn=[],this.lValue=[],this.obligatory=s}add(t,e){0!==this.lBtn.length&&this.single&&(this.lBtn[0].clearTint(),this.lValue=[],this.lBtn=[]),this.lValue.push(e),this.lBtn.push(t),t.tint=15718407}getValue(){return this.single?this.lValue[0]:this.lValue}validate(){return!(0===this.lBtn.length&&this.obligatory)}remove(t){let e=this.lBtn.indexOf(t);-1!==e&&(this.lBtn.splice(e,1),this.lValue.splice(e,1)),t.clearTint()}}class Condition{constructor(t,e=!1,s=!1,i,h){this.shieldFilter=e,this.rangeFilter=s,this.shield=i,this.range=h,this.myself=t,this.lNode=[]}addNode(t){this.lNode.push(t)}do(t){if(this.doCondition(t))for(let e=0;et.getX()-e.getX();this.tree.lRect.sort(t),this.tree.lRect.forEach(function(e){void 0!==e.lRect&&e.lRect.sort(t)}),this.gm.modifyNodes(this.tree.getNodes()),this.gm.resume()}changeFrame(t,e){t.setFrame(2*this.line+e)}createButton(){let t=WIDTH_MAP+WIDTH_WINDOW/10,e=WIDTH_MAP+HEIGHT_WINDOW/10+5,s=HEIGHT_WINDOW/10,i=HEIGHT_WINDOW/15,h=this.add.sprite(t,e,"play").setOrigin(1,0).setInteractive(),a=this.add.sprite(10,10,"back").setOrigin(0,0).setInteractive();this.pencil=this.add.sprite(t-s,e,"pencil").setOrigin(1,0).setInteractive().setVisible(!1),this.bin=this.add.sprite(t-2*s,e,"bin").setOrigin(1,0).setInteractive().setVisible(!1),this.plus=this.add.sprite(t-3*s,e,"plus").setOrigin(1,0).setInteractive().setVisible(!1),this.line=0,h.displayHeight=h.displayWidth=i,a.displayHeight=a.displayWidth=i,this.pencil.displayHeight=this.pencil.displayWidth=i,this.bin.displayHeight=this.bin.displayWidth=i,this.plus.displayHeight=this.plus.displayWidth=i,this.creatBtnOutAndOver(h),this.creatBtnOutAndOver(a),this.creatBtnOutAndOver(this.pencil),this.creatBtnOutAndOver(this.bin),this.creatBtnOutAndOver(this.plus),h.on("pointerdown",()=>this.clickPlay(h)),a.on("pointerdown",()=>this.clickBack()),this.pencil.on("pointerdown",()=>this.clickPencil()),this.bin.on("pointerdown",()=>this.clickBin()),this.plus.on("pointerdown",()=>this.clickPlus()),this.input.on("pointerdown",()=>this.clickNode()),this.input.on("drag",this.doDrag),this.input.on("dragstart",()=>this.pauseScene(h))}creatBtnOutAndOver(t){t.on("pointerout",()=>this.changeFrame(t,0)),t.on("pointerover",()=>this.changeFrame(t,1))}clickPlay(t){this.scene.isPaused("GamingBoard")?this.resume():this.pauseScene(t),this.changeFrame(t,1)}clickPencil(){console.log("PENCIL"),this.changeFrame(this.pencil,0)}clickBin(){console.log("BIN"),this.tree.delete(this.selected),this.changeFrame(this.bin,0)}clickPlus(){console.log("PLUS"),this.father.scene.add("PlusNode",new PlusNode(this.father,this,this.selected)),this.scene.launch("PlusNode"),this.changeFrame(this.plus,0),this.scene.pause("Game")}clickBack(){console.log("BACK"),this.father.scene.stop("GamingBoard"),this.father.scene.remove("GamingBoard"),this.father.scene.stop("Game"),this.father.scene.start("Type")}}class GamingBoard extends Phaser.Scene{constructor(t){super("GamingBoard"),this.listRobot=[],this.father=t}preload(){this.cameras.main.setViewport(WIDTH_WINDOW/10,HEIGHT_WINDOW/10,WIDTH_MAP,WIDTH_MAP)}create(){this.end=!1,this.sound.add("shot"),this.sound.add("hit"),this.add.image(0,0,"background").alpha=.1;for(let t=0;tthis.resume()),this.time.addEvent({delay:2e3,callback:this.upShield,callbackScope:this})}update(t,e){super.update(t,e),this.listRobot.forEach(function(t){t.read()});for(let t=0;tthis.listRobot[0].addNode(t)),!0;return!1}chooseTarget(t){let e=2*WIDTH_MAP,s=[];this.listRobot.forEach(function(i){if(i!==t&&i.isAlive()){let h=Math.hypot(i.x-t.x,i.y-t.y);e>=h&&(e>h&&(e=h,s=[]),s.push(i))}}),this.listRobot.length>1?t.setTarget(s[Math.floor(Math.random()*(s.length+1))]):t.setTarget(s[0])}upShield(){this.listRobot.forEach(t=>t.addShield(SHIELD_PER_SECOND)),this.time.addEvent({delay:1e3,callback:this.upShield,callbackScope:this})}}class HealthBar{constructor(t,e,s,i,h,a,r){this.bar=new Phaser.GameObjects.Graphics(t),this.width=e,this.height=s,this.valueMax=a,this.value=a,this.color=r,this.draw(),this.setX(i),this.setY(h),t.add.existing(this.bar)}decrease(t){this.value-=t;let e=0;return this.value<0&&(e=-this.value,this.value=0),this.draw(),e}increase(t){this.value+=t,this.value>this.valueMax&&(this.value=this.valueMax),this.draw()}setX(t){this.bar.setX(t-this.width/2)}setY(t){this.bar.setY(t)}draw(){this.bar.clear(),this.bar.fillStyle(0),this.bar.fillRect(0,0,this.width,this.height),this.bar.fillStyle(16777215),this.bar.fillRect(2,2,this.width-4,this.height-4);let t=this.value/this.valueMax;t<1/3?this.bar.fillStyle(16711680):this.bar.fillStyle(this.color);let e=Math.floor(t*(this.width-4));this.bar.fillRect(2,2,e,this.height-4)}destroy(){this.bar.destroy()}}class Looser extends Finish{constructor(t){super(t)}create(){super.create(),super.addTitle(selectWord("GAME OVER","PARTIE PERDUE")),super.btnRetry(super.createButton(WIDTH_WINDOW/3,"retry")),super.btnHome(super.createButton(WIDTH_WINDOW/1.5,"home"))}}class Missile extends Phaser.GameObjects.Image{constructor(t,e,s,i){super(t,0,0,e),this.visible=!1,this.setOrigin(.5,.5),this.setScale(.02)}}class Move{constructor(t){this.toward=t}do(t){return!!t.haveTarget()&&(!0===this.toward?this.moveToward(t):this.fleeFrom(t))}moveToward(t){return t.advanceToTarget()}fleeFrom(t){return t.fleeFromTarget()}}class PlusNode extends Phaser.Scene{constructor(t,e,s){super("PlusNode"),this.father=t,this.gameR=e,this.selected=s}create(){this.add.rectangle(0,0,WIDTH_WINDOW,HEIGHT_WINDOW,0).setOrigin(0,0).setAlpha(.5),this.add.rectangle(0,HEIGHT_WINDOW/2,WIDTH_WINDOW,HEIGHT_WINDOW/2,3487290).setOrigin(0,.5),this.createNode(),this.createButton()}createNode(){let t=WIDTH_WINDOW/2,e=HEIGHT_WINDOW/2,s=WIDTH_WINDOW/3,i=HEIGHT_WINDOW/10,h={font:i.toString()+"px stencil",fill:"#e2e2e2"};this.add.text(t-s,e-i,selectWord("ATTACK","ATTAQUE"),h).setOrigin(.5,.5),this.add.text(t,e-i,selectWord("MOVE","DEPLACEMENT"),h).setOrigin(.5,.5),this.add.text(t+s,e-i,selectWord("CONDITION","CONDITION"),h).setOrigin(.5,.5);let a=this.add.sprite(t-s,e+i,"attack").setOrigin(.5,.5).setInteractive().on("pointerdown",()=>this.click("attack"));a.displayHeight=2*i,a.scaleX=a.scaleY,(a=this.add.sprite(t,e+i,"move").setOrigin(.5,.5).setInteractive().on("pointerdown",()=>this.click("move"))).displayHeight=2*i,a.scaleX=a.scaleY,(a=this.add.sprite(t+s,e+i,"condition").setOrigin(.5,.5).setInteractive().on("pointerdown",()=>this.click("condition"))).displayHeight=2*i,a.scaleX=a.scaleY}click(t){switch(t.toString()){case"attack":this.father.scene.add("AddNode",new AddAttack(this.father,this.gameR,this.selected));break;case"move":this.father.scene.add("AddNode",new AddMove(this.father,this.gameR,this.selected));break;case"condition":this.father.scene.add("AddNode",new AddCondition(this.father,this.gameR,this.selected))}this.scene.launch("AddNode"),this.scene.stop("PlusNode"),this.father.scene.remove("PlusNode")}createButton(){let t=WIDTH_WINDOW/2,e=HEIGHT_WINDOW-100,s=this.add.image(t,e,"cancel").setOrigin(.5,.5).setInteractive();s.on("pointerover",()=>s.setFrame(1)),s.on("pointerout",()=>s.setFrame(0)),s.on("pointerdown",()=>this.cancel()),s.displayHeight=HEIGHT_WINDOW/10,s.scaleX=s.scaleY}cancel(){this.scene.resume("Game"),this.scene.stop("PlusNode"),this.father.scene.remove("PlusNode")}}class RectangleNode{constructor(t,e,s,i,...h){switch(i.toString().toLowerCase()){case"attack":this.rect=new Phaser.GameObjects.Image(s,t,e,"attackNode"),this.node=new Attack(h[0]),this.canAddNode=!1,this.line=s.add.graphics(),console.log(3*this.node.percentRange),this.rect.setFrame(3*this.node.percentRange-1);break;case"move":this.rect=new Phaser.GameObjects.Image(s,t,e,"moveNode"),this.node=new Move(h[0]),this.canAddNode=!1,this.line=s.add.graphics(),!0===h[0]?this.rect.setFrame(0):this.rect.setFrame(2);break;case"condition":let a;this.rect=new Phaser.GameObjects.Image(s,t,e,"conditionNode"),this.node=new Condition(h[0],h[1],h[2],h[3],h[4]),this.canAddNode=!0,this.lRect=[],this.scene=s,this.line=s.add.graphics(),a=h[0]?0:1;let r=0;!0===h[1]&&(r=Math.floor(3*h[3])),h[2],this.rect.setFrame(4*a+r);break;case"waria":this.rect=new Phaser.GameObjects.Image(s,t,e,"logoWaria").setInteractive(),this.canAddNode=!0,this.lRect=[],this.scene=s,this.scene.add.existing(this.rect);break;default:return void console.log("Création d'un node echoué")}i.toString().toLowerCase(),this.rect.on("pointerdown",()=>this.click()),this.rect.setOrigin(.5,0),this.rect.displayHeight=HEIGHT_WINDOW/6,this.rect.scaleX=this.rect.scaleY}getSelected(){if(this.rect.isTinted)return this;if(this.canAddNode)for(let t=0;tthis.addLine(t))}addLine(t){t.setLine(this.rect.x,this.rect.y+.9*this.rect.displayHeight)}getNodes(){if(void 0===this.node){let t=[];return this.lRect.forEach(function(e){void 0!==e.node&&(void 0!==e.lRect&&(e.node.clearNodes(),e.lRect.forEach(t=>e.node.addNode(t.node))),t.push(e.node))}),t}}destroy(){this.line.destroy(),this.rect.destroy(),void 0!==this.lRect&&this.lRect.forEach(t=>t.destroy())}delete(t){let e=this.lRect.indexOf(t);if(-1!==e)return this.lRect.splice(e,1),t.destroy(),!0;for(let e=0;ethis.click())}click(){null===this.circleRange?this.drawRange():this.eraseRange()}addShield(t){this.shield.increase(t)}setX(t){this.x=t,this.circle.setX(this.x),this.life.setX(this.x),this.shield.setX(this.x),this.drawCircleRange()}setY(t){this.y=t,this.life.setY(this.y-this.width),this.shield.setY(this.y-1.5*this.width),this.circle.setY(this.y),this.drawCircleRange()}setTarget(t){this.target=t,this.updateTarget()}updateTarget(){this.verifyTarget()&&this.setTargetPos(this.target.x,this.target.y)}setTargetPos(t,e){let s=this.target.x-this.x,i=this.target.y-this.y,h=Math.hypot(s,i);this.velocityX=s/h*WIDTH_MAP/1e3*SPEED*this.speed,this.velocityY=i/h*WIDTH_MAP/1e3*SPEED*this.speed}setSpeed(t){this.speed=t,this.updateTarget()}advanceToTarget(){return!!this.verifyTarget()&&(this.velocityX>=0&&this.x>=this.target.x||this.velocityX<=0&&this.x<=this.target.x?this.setX(this.target.x):this.setX(this.x+this.velocityX),this.velocityY>=0&&this.y>=this.target.y||this.velocityY<=0&&this.y<=this.target.y?this.setY(this.target.y):this.setY(this.y+this.velocityY),!0)}fleeFromTarget(){return!!this.verifyTarget()&&(this.velocityX>=0&&this.x-this.width/2<=0?this.setX(this.width/2):this.velocityX<=0&&this.x+this.width/2>=WIDTH_MAP?this.setX(WIDTH_MAP-this.width/2):this.setX(this.x-this.velocityX),this.velocityY>=0&&this.y-this.width/2<=0?this.setY(this.height/2):this.velocityY<=0&&this.y+this.width/2>=WIDTH_MAP?this.setY(WIDTH_MAP-this.height/2):this.setY(this.y-this.velocityY),!0)}attackTarget(t=0){return!!(this.verifyTarget()&&this.target.isAlive()&&this.isTargetInRange())&&(this.canAttack&&this.attack(this.target,t),!0)}verifyTarget(){return!!this.haveTarget()&&(!!this.target.isAlive()||(this.setTarget(null),!1))}attack(t,e){this.canAttack=!1,this.missile.setPosition(this.x,this.y).setVisible(!0),this.missile.setRotation(Math.atan2(this.y-this.target.y,this.x-this.target.x)-1.57),this.scene.sound.play("shot");let s=this.calcDistance(this.target)*WIDTH_MAP/1e3;this.scene.tweens.add({targets:this.missile,x:t.x,y:t.y,ease:"Linear",duration:s,onComplete:()=>this.finishAttack(t,e)}),this.scene.time.addEvent({delay:Phaser.Math.Between(1e3,3e3),callback:this.reload,callbackScope:this})}finishAttack(t,e){t.beAttack(this.damage*e)&&this.setTarget(null),this.missile.setVisible(!1)}reload(){this.canAttack=!0}beAttack(t){let e=this.shield.decrease(t),s=this.scene.add.text(this.x,this.y,t.toString(),{font:"40px stencil",fill:"#ffff00"}).setOrigin(0,1);return this.scene.tweens.add({targets:s,x:this.x+30,y:this.y-50,alpha:0,duration:DURATION_DAMAGE,ease:"Sine.easeOut",onComplete:()=>s.destroy()}),this.scene.sound.play("hit"),console.log("HIT"),e>0&&(console.log("Shield Broken"),this.life.decrease(e)),this.die()}isTargetInRange(t=1){return!!this.verifyTarget()&&this.calcDistance(this.target)0}die(){return 0===this.life.value&&(null!==this.circleRange&&this.circleRange.destroy(),this.circle.destroy(),this.shield.destroy(),this.life.destroy(),!0)}haveTarget(){return null!=this.target}read(){for(let t=0;tt.setFrame(0)),t.on("pointerover",()=>t.setFrame(1)),t.on("pointerdown",()=>this.clickPlay(t))}clickPlay(t){newGame(this.father),this.scene.start("Game")}}class Winner extends Finish{constructor(t){super(t)}create(){super.create(),super.addTitle(selectWord("WINNER","GAGNER")),super.btnRetry(super.createButton(WIDTH_WINDOW/4,"retry")),super.btnHome(super.createButton(WIDTH_WINDOW/2,"home")),super.btnNext(super.createButton(WIDTH_WINDOW/4*3,"next"))}} \ No newline at end of file diff --git a/Code/public/js/level3.min.js b/Code/public/js/level3.min.js index bf76dca..5acbbac 100644 --- a/Code/public/js/level3.min.js +++ b/Code/public/js/level3.min.js @@ -1 +1 @@ -class AddNode extends Phaser.Scene{constructor(e,t,n){super("AddNode"),this.father=e,this.gameR=t,this.selected=n,this.lCategory=[]}create(e){let t=HEIGHT_WINDOW/(4/3);this.add.rectangle(0,0,WIDTH_WINDOW,HEIGHT_WINDOW,0).setOrigin(0,0).setAlpha(.5),this.add.rectangle(0,HEIGHT_WINDOW/2,WIDTH_WINDOW,t,3487290).setOrigin(0,.5),this.createButtonCancel(),this.createButtonAdd(e)}addButton(e,t,n,r,i,a=new Category,s){let d=this.createButton(e,t,n,r,i);return d.on("pointerdown",()=>this.click(d,a,s)),d}createButton(e,t,n,r,i){let a=this.add.image(e,t,i).setOrigin(.5,.5).setInteractive();return a.on("pointerover",()=>a.setFrame(1)),a.on("pointerout",()=>a.setFrame(0)),a.displayHeight=r,null===n?a.scaleX=a.scaleY:a.displayWidth=n,a}click(e,t,n){e.isTinted?t.remove(e):t.add(e,n)}newCategory(e,t,n){let r=new Category(e,t,n);return this.lCategory.push(r),r}addTitle(e,t,n){let r={font:(HEIGHT_WINDOW/12).toString()+"px stencil",fill:"#e2e2e2"};this.add.text(e,t,n,r).setOrigin(.5,.5)}createButtonCancel(){this.createButton(WIDTH_WINDOW/3,HEIGHT_WINDOW/(16/15),null,HEIGHT_WINDOW/9,"cancel").on("pointerdown",()=>this.cancel())}createButtonAdd(e){this.createButton(WIDTH_WINDOW/1.5,HEIGHT_WINDOW/(16/15),null,HEIGHT_WINDOW/9,"add").on("pointerdown",()=>e.addNode())}verifyCategory(){for(let e=0;ethis.click(a,r,o)),a}createButton(e,t,n,s,i){let r=this.add.image(e,t,i).setOrigin(.5,.5).setInteractive();return r.on("pointerover",()=>r.setFrame(1)),r.on("pointerout",()=>r.setFrame(0)),r.displayHeight=s,null===n?r.scaleX=r.scaleY:r.displayWidth=n,r}click(e,t,n){e.isTinted?t.remove(e):t.add(e,n)}newCategory(e,t,n){let s=new Category(e,t,n);return this.lCategory.push(s),s}addTitle(e,t,n){let s={font:(HEIGHT_WINDOW/12).toString()+"px stencil",fill:"#e2e2e2"};this.add.text(e,t,n,s).setOrigin(.5,.5)}createButtonCancel(){this.createButton(WIDTH_WINDOW/3,HEIGHT_WINDOW/(16/15),null,HEIGHT_WINDOW/9,"cancel").on("pointerdown",()=>this.cancel())}createButtonAdd(e){this.createButton(WIDTH_WINDOW/1.5,HEIGHT_WINDOW/(16/15),null,HEIGHT_WINDOW/9,"add").on("pointerdown",()=>e.addNode())}verifyCategory(){for(let e=0;en.setFrame(1)),n.on("pointerout",()=>n.setFrame(0)),n.displayHeight=HEIGHT_WINDOW/9,n.scaleX=n.scaleY,n}btnRetry(e){e.on("pointerdown",()=>this.retry())}retry(){console.log("RETRY"),this.close(),newGame(this.father),this.father.scene.start("Game")}btnHome(e){e.on("pointerdown",()=>this.home())}home(){console.log("HOME"),this.close(),this.father.scene.start("Type")}btnNext(e){e.on("pointerdown",()=>this.next())}next(){console.log("NEXT")}close(){this.sound.stopAll(),this.father.scene.remove("GamingBoard"),this.father.scene.remove("Game"),this.father.scene.remove("Finish")}} \ No newline at end of file diff --git a/Code/src/js/level1/Init.js b/Code/src/js/level1/Init.js index 9654bd2..71986c1 100644 --- a/Code/src/js/level1/Init.js +++ b/Code/src/js/level1/Init.js @@ -7,11 +7,20 @@ function selectWord(en, fr) { } } +function newGame(father) { + if (father.scene.getIndex('Game') !== -1) { + father.scene.remove('Game'); + } + father.scene.add('Game', new Game(father)); +} + var LANG = navigator.language.substr(0, 2).toLowerCase(); +const MYSELF = 'myself'; const SHIELD_PER_SECOND = 5; const COLOR_ATTACK = 0xff0000; const COLOR_MOVE = 0x0000ff; const COLOR_CONDITION = 0x0e0e0e; +const DURATION_DAMAGE = 700; 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; @@ -33,6 +42,4 @@ var config = { let father = new Phaser.Game(config); father.scene.add('Boot', new Boot(father)); -father.scene.add('Type', Type); -father.scene.add('Game', new Game(father)); father.scene.start('Boot'); diff --git a/Code/src/js/level2/Attack.js b/Code/src/js/level2/Attack.js index ef38f8e..19a4c7e 100644 --- a/Code/src/js/level2/Attack.js +++ b/Code/src/js/level2/Attack.js @@ -3,18 +3,21 @@ class Attack { if (percentRange > 1 / 3) { if (percentRange > 2 / 3) { percentRange = 1; + this.percentBonus = 1; } else { percentRange = 2 / 3; + this.percentBonus = 1.5; } } else { percentRange = 1 / 3; + this.percentBonus = 2; } this.percentRange = percentRange; } do(robot) { if (robot.haveTarget() && robot.isTargetInRange(this.percentRange)) { - return robot.attackTarget(); + return robot.attackTarget(this.percentBonus); } return false; } diff --git a/Code/src/js/level2/Boot.js b/Code/src/js/level2/Boot.js index d4d4393..ff729ac 100644 --- a/Code/src/js/level2/Boot.js +++ b/Code/src/js/level2/Boot.js @@ -24,12 +24,18 @@ class Boot extends Phaser.Scene { progressBox.destroy(); }); + this.load.audio('shot', 'assets/sounds/shot.ogg'); + this.load.audio('hit', 'assets/sounds/hit.ogg'); + this.loadImage('en', 'flags/', true); this.loadImage('fr', 'flags/', true); this.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/'); @@ -109,6 +115,7 @@ class Boot extends Phaser.Scene { clickPlay(btn) { btn.setFrame(2); console.log("Play"); + this.father.scene.add('Type', new Type(this.father)); this.scene.start('Type'); } diff --git a/Code/src/js/level2/Game.js b/Code/src/js/level2/Game.js index 532514c..848c6b7 100644 --- a/Code/src/js/level2/Game.js +++ b/Code/src/js/level2/Game.js @@ -5,7 +5,7 @@ class Game extends Phaser.Scene { } preload() { - this.gm = new GamingBoard(); + this.gm = new GamingBoard(this); this.father.scene.add('GamingBoard', this.gm); } @@ -17,18 +17,19 @@ class Game extends Phaser.Scene { this.scene.launch('GamingBoard'); this.scene.pause('GamingBoard'); + let centerX = WIDTH_WINDOW / 4 * 3; + let diffX = WIDTH_WINDOW / 10; + this.tree = new RectangleNode(centerX, HEIGHT_WINDOW / 10, this, 'waria'); + this.tree.addRect(new RectangleNode(centerX + diffX, HEIGHT_WINDOW / 3, this, 'move', true)) + this.tree.addRect(new RectangleNode(centerX, HEIGHT_WINDOW / 3, this, 'attack', 1 / 3)); - this.tree = new RectangleNode(WIDTH_WINDOW / 1.5, 100, this, 'waria'); - this.tree.addRect(new RectangleNode(WIDTH_WINDOW / 1.2, 400, this, 'move', true)) - this.tree.addRect(new RectangleNode(WIDTH_WINDOW / 1.5, 400, this, 'attack', 1 / 3)); - - let condition = new RectangleNode(WIDTH_WINDOW / 1.7, 400, this, 'condition', true, true, false, 1 / 3, 0); - condition.addRect(new RectangleNode(WIDTH_WINDOW / 1.2, 600, this, 'move', false)); - condition.addRect(new RectangleNode(WIDTH_WINDOW / 1.5, 600, this, 'attack')) + let condition = new RectangleNode(centerX - diffX, HEIGHT_WINDOW / 3, this, 'condition', true, true, false, 1 / 3, 0); + condition.addRect(new RectangleNode(centerX, HEIGHT_WINDOW / 1.5, this, 'move', false)); + condition.addRect(new RectangleNode(centerX - diffX, HEIGHT_WINDOW / 1.5, this, 'attack')) this.tree.addRect(condition); - this.gm.addRobot(new Robot(WIDTH_MAP * 0.1, WIDTH_MAP * 0.1, WIDTH_MAP * 0.9, WIDTH_MAP * 0.9, 0x6666ff, this.gm, 'myself')); + this.gm.addRobot(new Robot(WIDTH_MAP * 0.1, WIDTH_MAP * 0.1, WIDTH_MAP * 0.9, WIDTH_MAP * 0.9, 0x6666ff, this.gm, MYSELF)); this.gm.addRobot(new Robot(WIDTH_MAP * 0.1, WIDTH_MAP * 0.1, WIDTH_MAP * 0.2, WIDTH_MAP * 0.1, 0xff0000, this.gm)); this.gm.addRobot(new Robot(WIDTH_MAP * 0.1, WIDTH_MAP * 0.1, WIDTH_MAP * 0.1, WIDTH_MAP * 0.9, 0xff0000, this.gm)); @@ -40,6 +41,21 @@ class Game extends Phaser.Scene { this.tree.updateLine(); } + finish() { + console.log("FINISH"); + let winner; + if (this.gm.winner()) { + winner = new Winner(this.father); + } else { + winner = new Looser(this.father); + } + this.father.scene.add('Finish', winner); + + this.scene.pause('Game'); + + this.scene.launch('Finish'); + } + clickNode() { this.pencil.setVisible(false); @@ -67,15 +83,12 @@ class Game extends Phaser.Scene { target.setY(dragY); } + pauseScene(btn) { this.line = 0; - this.scene.pause('GamingBoard'); this.changeFrame(btn, 0); - } - - changeFrame(btn, bonus) { - btn.setFrame(this.line * 2 + bonus); + this.gm.pause(); } resume() { @@ -88,7 +101,13 @@ class Game extends Phaser.Scene { } }) this.gm.modifyNodes(this.tree.getNodes()); - this.scene.resume('GamingBoard'); + + this.gm.resume(); + } + + + changeFrame(btn, bonus) { + btn.setFrame(this.line * 2 + bonus); } createButton() { diff --git a/Code/src/js/level2/GamingBoard.js b/Code/src/js/level2/GamingBoard.js index afe6419..104eb89 100644 --- a/Code/src/js/level2/GamingBoard.js +++ b/Code/src/js/level2/GamingBoard.js @@ -1,7 +1,8 @@ class GamingBoard extends Phaser.Scene { - constructor() { + constructor(father) { super('GamingBoard'); this.listRobot = []; + this.father = father; } preload() { @@ -9,6 +10,10 @@ class GamingBoard extends Phaser.Scene { } create() { + this.end = false; + this.sound.add('shot'); + this.sound.add('hit'); + this.add.image(0, 0, 'background').alpha = 0.1; for (let i = 0; i < this.listRobot.length; i++) { @@ -41,9 +46,31 @@ class GamingBoard extends Phaser.Scene { } } } + + if (this.listRobot.length <= 1 && !this.end) { + this.end = true; + this.time.addEvent({delay: 1000, callback: this.finish, callbackScope: this}); + } + } + + finish() { + console.log("QUOI ?"); + this.pause(); + this.father.finish(); + } + + winner() { + return this.listRobot.length !== 0 && this.listRobot[0].name === 'myself'; + } + + pause() { + this.scene.pause('GamingBoard'); + this.sound.pauseAll(); } resume() { + this.scene.resume('GamingBoard'); + this.sound.resumeAll(); } addRobot(robot) { @@ -51,8 +78,14 @@ class GamingBoard extends Phaser.Scene { } modifyNodes(lNodes) { - this.listRobot[0].cleanNodes(); - lNodes.forEach(element => this.listRobot[0].addNode(element)); + 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 false; } chooseTarget(robot) { diff --git a/Code/src/js/level2/Looser.js b/Code/src/js/level2/Looser.js new file mode 100644 index 0000000..b467af9 --- /dev/null +++ b/Code/src/js/level2/Looser.js @@ -0,0 +1,12 @@ +class Looser extends Finish { + constructor(father) { + super(father); + } + + 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')); + } +} \ No newline at end of file diff --git a/Code/src/js/level2/Robot.js b/Code/src/js/level2/Robot.js index f182bca..9a1b2f3 100644 --- a/Code/src/js/level2/Robot.js +++ b/Code/src/js/level2/Robot.js @@ -122,10 +122,10 @@ class Robot { } - attackTarget() { + attackTarget(percentBonus = 0) { if (this.verifyTarget() && this.target.isAlive() && this.isTargetInRange()) { if (this.canAttack) - this.attack(this.target); + this.attack(this.target, percentBonus); return true; } return false; @@ -142,27 +142,31 @@ class Robot { return false; } - attack(target) { + attack(target, percentBonus) { this.canAttack = false; this.missile.setPosition(this.x, this.y).setVisible(true); this.missile.setRotation(Math.atan2(this.y - this.target.y, this.x - this.target.x) - 3.14 / 2); + this.scene.sound.play('shot'); + + let duration = this.calcDistance(this.target) * WIDTH_MAP / 1000; + this.scene.tweens.add({ targets: this.missile, x: target.x, y: target.y, ease: 'Linear', - duration: 200, - onComplete: () => this.finishAttack(target) + duration: duration, + onComplete: () => this.finishAttack(target, percentBonus) }); this.scene.time.addEvent({delay: Phaser.Math.Between(1000, 3000), callback: this.reload, callbackScope: this}); } - finishAttack(target) { - if (target.beAttack(this.damage)) { + finishAttack(target, percentBonus) { + if (target.beAttack(this.damage * percentBonus)) { this.setTarget(null); } this.missile.setVisible(false); @@ -173,7 +177,24 @@ class Robot { } beAttack(damage) { - let diff = this.shield.decrease(damage) + let diff = this.shield.decrease(damage); + + let style = {font: '40px stencil', fill: "#ffff00"}; + let text = this.scene.add.text(this.x, this.y, damage.toString(), style).setOrigin(0, 1); + + this.scene.tweens.add({ + targets: text, + x: this.x + 30, + y: this.y - 50, + alpha: 0, + duration: DURATION_DAMAGE, + ease: 'Sine.easeOut', + onComplete: () => text.destroy() + }) + + this.scene.sound.play('hit'); + console.log('HIT'); + if (diff > 0) { console.log("Shield Broken"); this.life.decrease(diff); @@ -242,18 +263,19 @@ class Robot { let color = 0x008000; let thickness = 4; - let alpha = 1; - + let alpha = 1 / 3; this.circleRange.lineStyle(thickness, color, alpha); let radius = this.range; this.circleRange.strokeCircle(this.x, this.y, radius); color = 0xff7f00; + alpha = 2 / 3; this.circleRange.lineStyle(thickness, color, alpha); radius = this.range * 2 / 3; this.circleRange.strokeCircle(this.x, this.y, radius); color = 0xff0000; + alpha = 1; this.circleRange.lineStyle(thickness, color, alpha); radius = this.range / 3; this.circleRange.strokeCircle(this.x, this.y, radius); diff --git a/Code/src/js/level2/Type.js b/Code/src/js/level2/Type.js index 79c8fed..a06d3f3 100644 --- a/Code/src/js/level2/Type.js +++ b/Code/src/js/level2/Type.js @@ -1,6 +1,7 @@ class Type extends Phaser.Scene { - constructor() { + constructor(father) { super('Type'); + this.father = father; } preload() { @@ -35,6 +36,7 @@ class Type extends Phaser.Scene { } clickPlay(btn) { + newGame(this.father); this.scene.start('Game'); } } \ No newline at end of file diff --git a/Code/src/js/level2/Winner.js b/Code/src/js/level2/Winner.js new file mode 100644 index 0000000..a3e297f --- /dev/null +++ b/Code/src/js/level2/Winner.js @@ -0,0 +1,13 @@ +class Winner extends Finish { + constructor(father) { + super(father); + } + + create() { + super.create(); + super.addTitle(selectWord("WINNER", "GAGNER")); + super.btnRetry(super.createButton(WIDTH_WINDOW / 4, 'retry')); + super.btnHome(super.createButton(WIDTH_WINDOW / 2, 'home')); + super.btnNext(super.createButton(WIDTH_WINDOW / 4 * 3, 'next')); + } +} \ No newline at end of file diff --git a/Code/src/js/level3/Finish.js b/Code/src/js/level3/Finish.js new file mode 100644 index 0000000..2d3be98 --- /dev/null +++ b/Code/src/js/level3/Finish.js @@ -0,0 +1,64 @@ +class Finish extends Phaser.Scene { + constructor(father) { + super('Finish'); + this.father = father; + } + + create() { + this.add.rectangle(0, 0, WIDTH_WINDOW, HEIGHT_WINDOW, 0x000000).setOrigin(0, 0).setAlpha(0.5); + this.add.rectangle(0, HEIGHT_WINDOW / 2, WIDTH_WINDOW, HEIGHT_WINDOW / 2, 0x35363A).setOrigin(0, 0.5); + } + + addTitle(title) { + let sizeText = HEIGHT_WINDOW / 6; + let style = {font: sizeText.toString() + 'px stencil', fill: "#e2e2e2"}; + this.add.text(WIDTH_WINDOW / 2, HEIGHT_WINDOW / 2, title, style).setOrigin(0.5, 0.5); + } + + createButton(x, texture) { + let btn = this.add.image(x, HEIGHT_WINDOW / 8 * 7, texture).setOrigin(0.5, 0.5).setInteractive(); + btn.on('pointerover', () => btn.setFrame(1)); + btn.on('pointerout', () => btn.setFrame(0)); + + btn.displayHeight = HEIGHT_WINDOW / 9; + btn.scaleX = btn.scaleY; + + return btn; + } + + btnRetry(btn) { + btn.on('pointerdown', () => this.retry()); + } + + retry() { + console.log("RETRY"); + this.close(); + newGame(this.father); + this.father.scene.start('Game'); + } + + btnHome(btn) { + btn.on('pointerdown', () => this.home()); + } + + home() { + console.log("HOME"); + this.close(); + this.father.scene.start('Type'); + } + + btnNext(btn) { + btn.on('pointerdown', () => this.next()); + } + + next() { + console.log("NEXT"); + } + + close() { + this.sound.stopAll(); + this.father.scene.remove('GamingBoard'); + this.father.scene.remove('Game'); + this.father.scene.remove('Finish'); + } +} \ No newline at end of file diff --git a/Image/home.png b/Image/home.png new file mode 100644 index 0000000..eb063af Binary files /dev/null and b/Image/home.png differ diff --git a/Image/next.png b/Image/next.png new file mode 100644 index 0000000..c52ca83 Binary files /dev/null and b/Image/next.png differ diff --git a/Image/retry.png b/Image/retry.png new file mode 100644 index 0000000..9fe082e Binary files /dev/null and b/Image/retry.png differ