diff --git a/Code/assets/nodes/attackNode.png b/Code/assets/nodes/attackNode.png new file mode 100644 index 0000000..33db8bf Binary files /dev/null and b/Code/assets/nodes/attackNode.png differ diff --git a/Code/assets/nodes/conditionNode.png b/Code/assets/nodes/conditionNode.png new file mode 100644 index 0000000..e7313b2 Binary files /dev/null and b/Code/assets/nodes/conditionNode.png differ diff --git a/Code/assets/nodes/moveNode.png b/Code/assets/nodes/moveNode.png new file mode 100644 index 0000000..dc23640 Binary files /dev/null and b/Code/assets/nodes/moveNode.png differ diff --git a/Code/public/js/app.min.js b/Code/public/js/app.min.js index bbe6588..751a78e 100644 --- a/Code/public/js/app.min.js +++ b/Code/public/js/app.min.js @@ -1 +1 @@ -const COLOR_ATTACK=16711680,COLOR_MOVE=255,WIDTH_WINDOW=$(document).width()-30,HEIGHT_WINDOW=$(document).height()-30,WIDTH_MAP=WIDTH_WINDOWt.setFrame(0)),t.on("pointerover",()=>t.setFrame(1)),t.on("pointerdown",()=>this.clickPlay(t))}clickPlay(t){t.setFrame(2),console.log("Play"),this.scene.start("Type")}}class Condition{constructor(t,e=!1,i=!1,s,h){this.shieldFilter=e,this.rangeFilter=i,this.shield=s,this.range=h,this.target=t,this.lNode=[]}addNode(t){this.lNode.push(t)}do(t){if(this.doCondition(t))for(let e=0;et.setFrame(0)),t.on("pointerover",()=>t.setFrame(1)),t.on("pointerdown",()=>this.clickPlay(t)),this.scene.launch("GamingBoard"),this.scene.pause("GamingBoard"),this.tree=new Tree(WIDTH_WINDOW/1.5,100,this),this.tree.addNode(new MoveRectangle(!0,WIDTH_WINDOW/1.2,400,100,100,this)),this.tree.addNode(new AttackRectangle(WIDTH_WINDOW/1.5,400,100,100,this)),this.input.on("drag",this.doDrag)}update(t,e){super.update(t,e),this.tree.updateLines()}doDrag(t,e,i,s){e.setX(i),e.setY(s)}clickPlay(t){t.setFrame(2),this.scene.isPaused("GamingBoard")?this.resume():this.scene.pause("GamingBoard")}resume(){this.tree.lNode.sort((t,e)=>t.getX()-e.getX()),this.gm.modifyNodes(this.tree.lNode),this.scene.resume("GamingBoard")}}class GamingBoard extends Phaser.Scene{constructor(){super("GamingBoard")}preload(){this.cameras.main.setViewport(WIDTH_WINDOW/10,HEIGHT_WINDOW/10,WIDTH_MAP,WIDTH_MAP)}create(){this.add.image(0,0,"background").alpha=.1,this.listRobot=[],this.listRobot.push(new Robot(.1*WIDTH_MAP,.1*WIDTH_MAP,.9*WIDTH_MAP,.9*WIDTH_MAP,6711039,this)),this.listRobot.push(new Robot(.1*WIDTH_MAP,.1*WIDTH_MAP,.2*WIDTH_MAP,.1*WIDTH_MAP,16724940,this)),this.listRobot.push(new Robot(.1*WIDTH_MAP,.1*WIDTH_MAP,.1*WIDTH_MAP,.9*WIDTH_MAP,16777215,this));for(let t=0;tthis.resume())}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])}}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}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<.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 MoveRectangle extends Move{constructor(t,e,i,s,h,a){super(t),this.color=COLOR_MOVE,this.rect=new Phaser.GameObjects.Rectangle(a,e,i,s,h,this.color),this.line=a.add.graphics()}getX(){return this.rect.x}addLine(t,e){this.xOrigin=t,this.yOrigin=e,this.updateLine()}updateLine(){this.xLine===this.rect.x&&this.yLine===this.rect.y||(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))}}class Robot{constructor(t,e,i,s,h,a){this.height=t,this.width=e,this.x=i,this.y=s,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.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 r=new Condition(this,!0,!1,.5,0);r.addNode(new Move(!1)),this.addNode(r),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)}setX(t){this.x=t,this.circle.setX(this.x),this.life.setX(this.x),this.shield.setX(this.x)}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)}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.velocityY=s/h*WIDTH_MAP/1e3*SPEED}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(){return!!this.verifyTarget()&&this.calcDistance(this.target)0}die(){return 0===this.life.value&&(this.circle.destroy(),this.shield.destroy(),this.life.destroy(),!0)}haveTarget(){return null!=this.target}read(){for(let t=0;tt.updateLine())}}class Type extends Phaser.Scene{constructor(){super("Type")}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,"btn_duel").setInteractive();this.createbutton(t);let e=this.add.sprite(WIDTH_WINDOW/8*5,HEIGHT_WINDOW/4*2,"btn_last").setInteractive();this.createbutton(e);let i=this.add.sprite(WIDTH_WINDOW/8*2,HEIGHT_WINDOW/4*3,"btn_team").setInteractive();this.createbutton(i);let s=this.add.sprite(WIDTH_WINDOW/8*4,HEIGHT_WINDOW/4*3,"btn_flag").setInteractive();this.createbutton(s);let h=this.add.sprite(WIDTH_WINDOW/8*6,HEIGHT_WINDOW/4*3,"btn_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){this.scene.start("Game")}} \ No newline at end of file +class Attack{constructor(){}do(t){return!(!t.haveTarget()||!t.isTargetInRange())&&t.attackTarget()}}class Boot extends Phaser.Scene{constructor(){super("Boot")}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.load.spritesheet("btn_play","assets/btnPlay.png",{frameWidth:650,frameHeight:170}),this.load.spritesheet("btn_duel","assets/btnDuel.png",{frameWidth:269,frameHeight:262}),this.load.spritesheet("btn_last","assets/btnLast.png",{frameWidth:269,frameHeight:262}),this.load.spritesheet("btn_team","assets/btnTeam.png",{frameWidth:269,frameHeight:262}),this.load.spritesheet("btn_flag","assets/btnFlag.png",{frameWidth:269,frameHeight:262}),this.load.spritesheet("btn_map","assets/btnMap.png",{frameWidth:269,frameHeight:262}),this.load.image("background","assets/background.png"),this.load.image("bullet","assets/bullet.png"),this.load.image("logoWaria","assets/logoWaria.png"),this.load.image("attackN","assets/nodes/attackNode.png"),this.load.image("moveN","assets/nodes/moveNode.png"),this.load.image("conditionN","assets/nodes/conditionNode.png")}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,"btn_play").setInteractive();t.on("pointerout",()=>t.setFrame(0)),t.on("pointerover",()=>t.setFrame(1)),t.on("pointerdown",()=>this.clickPlay(t))}clickPlay(t){t.setFrame(2),console.log("Play"),this.scene.start("Type")}}class Condition{constructor(t,e=!1,i=!1,s,h){this.shieldFilter=e,this.rangeFilter=i,this.shield=s,this.range=h,this.target=t,this.lNode=[]}addNode(t){this.lNode.push(t)}do(t){if(this.doCondition(t))for(let e=0;et.setFrame(0)),t.on("pointerover",()=>t.setFrame(1)),t.on("pointerdown",()=>this.clickPlay(t)),this.scene.launch("GamingBoard"),this.scene.pause("GamingBoard"),this.tree=new RectangleNode(WIDTH_WINDOW/1.5,100,this,"waria"),this.tree.addRect(new RectangleNode(WIDTH_WINDOW/1.2,400,this,"move",!0)),this.tree.addRect(new RectangleNode(WIDTH_WINDOW/1.5,400,this,"attack"));let e=new Robot(.1*WIDTH_MAP,.1*WIDTH_MAP,.9*WIDTH_MAP,.9*WIDTH_MAP,6711039,this.gm),i=new RectangleNode(WIDTH_WINDOW/1.7,400,this,"condition",e,!0,!1,.5,0);i.addRect(new RectangleNode(WIDTH_WINDOW/1.2,600,this,"move",!1)),i.addRect(new RectangleNode(WIDTH_WINDOW/1.5,600,this,"attack")),this.tree.addRect(i),this.gm.addRobot(e),this.gm.addRobot(new Robot(.1*WIDTH_MAP,.1*WIDTH_MAP,.2*WIDTH_MAP,.1*WIDTH_MAP,16724940,this.gm)),this.gm.addRobot(new Robot(.1*WIDTH_MAP,.1*WIDTH_MAP,.1*WIDTH_MAP,.9*WIDTH_MAP,16777215,this.gm)),this.input.on("drag",this.doDrag)}update(t,e){super.update(t,e),this.tree.updateLine()}doDrag(t,e,i,s){e.setX(i),e.setY(s)}clickPlay(t){t.setFrame(2),this.scene.isPaused("GamingBoard")?this.resume():this.scene.pause("GamingBoard")}resume(){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.scene.resume("GamingBoard")}}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())}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])}}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}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<.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 RectangleNode{constructor(t,e,i,s,...h){switch(s.toString().toLowerCase()){case"attack":this.rect=new Phaser.GameObjects.Image(i,t,e,"attackN"),this.node=new Attack,this.canAddNode=!1,this.line=i.add.graphics();break;case"move":this.rect=new Phaser.GameObjects.Image(i,t,e,"moveN"),this.node=new Move(h[0]),this.canAddNode=!1,this.line=i.add.graphics();break;case"condition":this.rect=new Phaser.GameObjects.Image(i,t,e,"conditionN"),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();break;case"waria":this.rect=new Phaser.GameObjects.Image(i,t,e,"logoWaria"),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.setOrigin(.5,0),this.rect.displayHeight=HEIGHT_WINDOW/6,this.rect.scaleX=this.rect.scaleY}getX(){return this.rect.x}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}}}class Robot{constructor(t,e,i,s,h,a){this.height=t,this.width=e,this.x=i,this.y=s,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.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 r=new Condition(this,!0,!1,.5,0);r.addNode(new Move(!1)),this.addNode(r),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)}setX(t){this.x=t,this.circle.setX(this.x),this.life.setX(this.x),this.shield.setX(this.x)}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)}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.velocityY=s/h*WIDTH_MAP/1e3*SPEED}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(){return!!this.verifyTarget()&&this.calcDistance(this.target)0}die(){return 0===this.life.value&&(this.circle.destroy(),this.shield.destroy(),this.life.destroy(),!0)}haveTarget(){return null!=this.target}read(){for(let t=0;tt.updateLine())}getNodes(){let t=[];return this.lRect.forEach(function(e){void 0!==e.node&&t.push(e.node)}),t}}class Type extends Phaser.Scene{constructor(){super("Type")}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,"btn_duel").setInteractive();this.createbutton(t);let e=this.add.sprite(WIDTH_WINDOW/8*5,HEIGHT_WINDOW/4*2,"btn_last").setInteractive();this.createbutton(e);let i=this.add.sprite(WIDTH_WINDOW/8*2,HEIGHT_WINDOW/4*3,"btn_team").setInteractive();this.createbutton(i);let s=this.add.sprite(WIDTH_WINDOW/8*4,HEIGHT_WINDOW/4*3,"btn_flag").setInteractive();this.createbutton(s);let h=this.add.sprite(WIDTH_WINDOW/8*6,HEIGHT_WINDOW/4*3,"btn_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){this.scene.start("Game")}} \ No newline at end of file diff --git a/Code/src/js/Init.js b/Code/src/js/Init.js index ea547d0..b1acf02 100644 --- a/Code/src/js/Init.js +++ b/Code/src/js/Init.js @@ -6,6 +6,7 @@ console.log(myself.height); const COLOR_ATTACK = 0xff0000; const COLOR_MOVE = 0x0000ff; +const COLOR_CONDITION = 0x0e0e0e; const WIDTH_WINDOW = $(document).width() - 30; const HEIGHT_WINDOW = $(document).height() - 30; const WIDTH_MAP = WIDTH_WINDOW < HEIGHT_WINDOW ? WIDTH_WINDOW * 0.8 : HEIGHT_WINDOW * 0.8; diff --git a/Code/src/js/classes/AttackRectangle.js b/Code/src/js/classes/AttackRectangle.js deleted file mode 100644 index e07db1e..0000000 --- a/Code/src/js/classes/AttackRectangle.js +++ /dev/null @@ -1,28 +0,0 @@ -class AttackRectangle extends Attack { - constructor(x, y, width, height, scene) { - super(); - this.color = COLOR_ATTACK; - this.rect = new Phaser.GameObjects.Rectangle(scene, x, y, width, height, this.color); - this.line = scene.add.graphics(); - } - - getX() { - return this.rect.x; - } - - addLine(x, y) { - this.xOrigin = x; - this.yOrigin = y; - this.updateLine(); - } - - updateLine() { - if (this.xLine !== this.rect.x || this.yLine !== this.rect.y) { - this.xLine = this.rect.x; - this.yLine = this.rect.y; - this.line.clear(); - this.line.lineStyle(10, 0xffffff, 1); - this.line.lineBetween(this.xOrigin, this.yOrigin, this.rect.x, this.rect.y); - } - } -} \ No newline at end of file diff --git a/Code/src/js/classes/Boot.js b/Code/src/js/classes/Boot.js index f207b5f..eae8cbf 100644 --- a/Code/src/js/classes/Boot.js +++ b/Code/src/js/classes/Boot.js @@ -33,6 +33,9 @@ class Boot extends Phaser.Scene { this.load.image('background', 'assets/background.png'); this.load.image('bullet', 'assets/bullet.png'); this.load.image('logoWaria', 'assets/logoWaria.png'); + this.load.image('attackN','assets/nodes/attackNode.png'); + this.load.image('moveN','assets/nodes/moveNode.png'); + this.load.image('conditionN','assets/nodes/conditionNode.png'); } create() { diff --git a/Code/src/js/classes/Condition.js b/Code/src/js/classes/Condition.js index ec25823..dd15106 100644 --- a/Code/src/js/classes/Condition.js +++ b/Code/src/js/classes/Condition.js @@ -49,6 +49,10 @@ class Condition { return false; } + clearNodes() { + this.lNode = []; + } + moveToward(robot) { return robot.advanceToTarget(); diff --git a/Code/src/js/classes/Game.js b/Code/src/js/classes/Game.js index 3ee48bd..1e3851e 100644 --- a/Code/src/js/classes/Game.js +++ b/Code/src/js/classes/Game.js @@ -19,15 +19,29 @@ class Game extends Phaser.Scene { btn.on('pointerdown', () => this.clickPlay(btn)); this.scene.launch('GamingBoard'); this.scene.pause('GamingBoard'); - this.tree = new Tree(WIDTH_WINDOW / 1.5, 100, this); - this.tree.addNode(new MoveRectangle(true, WIDTH_WINDOW/1.2, 400, 100, 100, this)) - this.tree.addNode(new AttackRectangle(WIDTH_WINDOW/1.5, 400, 100, 100, this)); + + + 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')); + + + let robot = new Robot(WIDTH_MAP * 0.1, WIDTH_MAP * 0.1, WIDTH_MAP * 0.9, WIDTH_MAP * 0.9, 0x6666ff, this.gm); + let condition = new RectangleNode(WIDTH_WINDOW / 1.7, 400, this, 'condition', robot, true, false, 0.5, 0); + condition.addRect(new RectangleNode(WIDTH_WINDOW / 1.2, 600, this, 'move', false)); + condition.addRect(new RectangleNode(WIDTH_WINDOW / 1.5, 600, this, 'attack')) + this.tree.addRect(condition); + + this.gm.addRobot(robot); + this.gm.addRobot(new Robot(WIDTH_MAP * 0.1, WIDTH_MAP * 0.1, WIDTH_MAP * 0.2, WIDTH_MAP * 0.1, 0xff33cc, this.gm)); + this.gm.addRobot(new Robot(WIDTH_MAP * 0.1, WIDTH_MAP * 0.1, WIDTH_MAP * 0.1, WIDTH_MAP * 0.9, 0xffffff, this.gm)); + this.input.on('drag', this.doDrag); } update(time, delta) { super.update(time, delta); - this.tree.updateLines(); + this.tree.updateLine(); } doDrag(pointer, target, dragX, dragY) { @@ -45,8 +59,13 @@ class Game extends Phaser.Scene { resume() { const sortDesc = (a, b) => a.getX() - b.getX(); - this.tree.lNode.sort(sortDesc); - this.gm.modifyNodes(this.tree.lNode); + this.tree.lRect.sort(sortDesc); + this.tree.lRect.forEach(function (element) { + if (element.lRect !== undefined) { + element.lRect.sort(sortDesc); + } + }) + this.gm.modifyNodes(this.tree.getNodes()); this.scene.resume('GamingBoard'); } } \ No newline at end of file diff --git a/Code/src/js/classes/GamingBoard.js b/Code/src/js/classes/GamingBoard.js index 433b26a..0635249 100644 --- a/Code/src/js/classes/GamingBoard.js +++ b/Code/src/js/classes/GamingBoard.js @@ -1,6 +1,7 @@ class GamingBoard extends Phaser.Scene { constructor() { super('GamingBoard'); + this.listRobot = []; } preload() { @@ -10,11 +11,6 @@ class GamingBoard extends Phaser.Scene { create() { this.add.image(0, 0, 'background').alpha = 0.1; - this.listRobot = []; - this.listRobot.push(new Robot(WIDTH_MAP * 0.1, WIDTH_MAP * 0.1, WIDTH_MAP * 0.9, WIDTH_MAP * 0.9, 0x6666ff, this)); - this.listRobot.push(new Robot(WIDTH_MAP * 0.1, WIDTH_MAP * 0.1, WIDTH_MAP * 0.2, WIDTH_MAP * 0.1, 0xff33cc, this)); - this.listRobot.push(new Robot(WIDTH_MAP * 0.1, WIDTH_MAP * 0.1, WIDTH_MAP * 0.1, WIDTH_MAP * 0.9, 0xffffff, this)); - for (let i = 0; i < this.listRobot.length; i++) { this.chooseTarget(this.listRobot[i]); } @@ -46,6 +42,10 @@ class GamingBoard extends Phaser.Scene { resume() { } + addRobot(robot){ + this.listRobot.push(robot); + } + modifyNodes(lNodes) { this.listRobot[0].cleanNodes(); lNodes.forEach(element => this.listRobot[0].addNode(element)); diff --git a/Code/src/js/classes/MoveRectangle.js b/Code/src/js/classes/MoveRectangle.js deleted file mode 100644 index d6b6627..0000000 --- a/Code/src/js/classes/MoveRectangle.js +++ /dev/null @@ -1,28 +0,0 @@ -class MoveRectangle extends Move { - constructor(toward, x, y, width, height, scene) { - super(toward); - this.color = COLOR_MOVE; - this.rect = new Phaser.GameObjects.Rectangle(scene, x, y, width, height, this.color); - this.line = scene.add.graphics(); - } - - getX() { - return this.rect.x; - } - - addLine(x, y) { - this.xOrigin = x; - this.yOrigin = y; - this.updateLine(); - } - - updateLine() { - if (this.xLine !== this.rect.x || this.yLine !== this.rect.y) { - this.xLine = this.rect.x; - this.yLine = this.rect.y; - this.line.clear(); - this.line.lineStyle(10, 0xffffff, 1); - this.line.lineBetween(this.xOrigin, this.yOrigin, this.rect.x, this.rect.y); - } - } -} \ No newline at end of file diff --git a/Code/src/js/classes/RectangleNode.js b/Code/src/js/classes/RectangleNode.js new file mode 100644 index 0000000..82d00af --- /dev/null +++ b/Code/src/js/classes/RectangleNode.js @@ -0,0 +1,98 @@ +class RectangleNode { + constructor(x, y, scene, type, ...option) { + switch (type.toString().toLowerCase()) { + case 'attack': + this.rect = new Phaser.GameObjects.Image(scene, x, y, 'attackN'); + this.node = new Attack(); + this.canAddNode = false; + this.line = scene.add.graphics(); + break; + case 'move' : + this.rect = new Phaser.GameObjects.Image(scene, x, y, 'moveN'); + this.node = new Move(option[0]); + this.canAddNode = false; + this.line = scene.add.graphics(); + break; + case 'condition': + this.rect = new Phaser.GameObjects.Image(scene, x, y, 'conditionN'); + this.node = new Condition(option[0], option[1], option[2], option[3], option[4]); + this.canAddNode = true; + this.lRect = []; + this.scene = scene; + this.line = scene.add.graphics(); + break; + case 'waria': + this.rect = new Phaser.GameObjects.Image(scene, x, y, 'logoWaria'); + this.canAddNode = true; + this.lRect = []; + this.scene = scene; + this.scene.add.existing(this.rect); + break; + default: + console.log("Création d'un node echoué"); + return; + } + if (type.toString().toLowerCase() !== 'waria') { + } + this.rect.setOrigin(0.5, 0); + this.rect.displayHeight = HEIGHT_WINDOW / 6; + this.rect.scaleX = this.rect.scaleY; + } + + getX() { + return this.rect.x; + } + + addRect(node) { + if (this.canAddNode === true) { + this.lRect.push(node); + this.addLine(node); + let rect = this.scene.add.existing(node.rect); + rect.setInteractive(); + this.scene.input.setDraggable(rect); + if (this.node !== undefined) { + this.node.addNode(node.node); + } + } + } + + setLine(x, y) { + this.xOrigin = x; + this.yOrigin = y; + this.updateLine(true); + } + + updateLine(force) { + if ((force === true || this.xLine !== this.rect.x || this.yLine !== this.rect.y) && this.line !== undefined) { + this.xLine = this.rect.x; + this.yLine = this.rect.y; + this.line.clear(); + this.line.lineStyle(10, 0xffffff, 1); + this.line.lineBetween(this.xOrigin, this.yOrigin, this.rect.x, this.rect.y + this.rect.displayHeight / 10); + } + if (this.canAddNode === true) { + this.lRect.forEach(node => this.addLine(node)); + } + } + + addLine(node) { + node.setLine(this.rect.x, this.rect.y + this.rect.displayHeight * 0.9); + } + + getNodes() { + if (this.node === undefined) { + let lNodes = []; + this.lRect.forEach(function (element) { + if (element.node !== undefined) { + if (element.lRect !== undefined) { + element.node.clearNodes(); + element.lRect.forEach(rect => element.node.addNode(rect.node)); + } + lNodes.push(element.node); + } + }); + return lNodes; + } + + } +} \ No newline at end of file diff --git a/Code/src/js/classes/Tree.js b/Code/src/js/classes/Tree.js deleted file mode 100644 index 96c74d1..0000000 --- a/Code/src/js/classes/Tree.js +++ /dev/null @@ -1,21 +0,0 @@ -class Tree { - constructor(x, y, scene) { - this.lNode = []; - this.scene = scene; - this.head = this.scene.add.image(x, y, 'logoWaria').setOrigin(0.5, 0.5); - this.head.displayHeight = HEIGHT_WINDOW / 4; - this.head.scaleX = this.head.scaleY; - } - - addNode(node) { - this.lNode.push(node); - node.addLine(this.head.x, this.head.y + this.head.displayHeight / 2.2); - let rect = this.scene.add.existing(node.rect); - rect.setInteractive(); - this.scene.input.setDraggable(rect); - } - - updateLines() { - this.lNode.forEach(node => node.updateLine()); - } -} \ No newline at end of file