diff --git a/Code/assets/logoWaria.png b/Code/assets/logoWaria.png new file mode 100644 index 0000000..e36defc Binary files /dev/null and b/Code/assets/logoWaria.png differ diff --git a/Code/public/js/app.min.js b/Code/public/js/app.min.js index 0cf60c3..bbe6588 100644 --- a/Code/public/js/app.min.js +++ b/Code/public/js/app.min.js @@ -1 +1 @@ -const 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,s=!1,i,h){this.shieldFilter=e,this.rangeFilter=s,this.shield=i,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");let e=this.add.rectangle(WIDTH_WINDOW/2,500,100,100,16777215);e.setInteractive(),this.input.setDraggable(e),this.input.on("drag",this.doDrag)}startDrag(t,e){this.input.off("pointerdown",this.startDrag,this),this.dragObj=e[0],this.input.on("pointermove",this.doDrag,this),this.input.on("pointerup",this.stopDrag,this)}doDrag(t,e,s,i){e.x=s,e.y=i}clickPlay(t){this.scene.isPaused("GamingBoard")?this.scene.resume("GamingBoard"):this.scene.pause("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;t=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])}}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}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,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 Robot{constructor(t,e,s,i,h,a){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.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 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.velocityY=i/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.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 AttackRectangle extends Attack{constructor(t,e,i,s,h){super(),this.color=COLOR_ATTACK,this.rect=new Phaser.GameObjects.Rectangle(h,t,e,i,s,this.color),this.line=h.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 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")}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 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 diff --git a/Code/src/js/Init.js b/Code/src/js/Init.js index e9a5e99..ea547d0 100644 --- a/Code/src/js/Init.js +++ b/Code/src/js/Init.js @@ -4,6 +4,8 @@ EnemyBots.push(new Robot(1, 1)); console.log(myself.height); */ +const COLOR_ATTACK = 0xff0000; +const COLOR_MOVE = 0x0000ff; 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 new file mode 100644 index 0000000..e07db1e --- /dev/null +++ b/Code/src/js/classes/AttackRectangle.js @@ -0,0 +1,28 @@ +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 e1d46aa..f207b5f 100644 --- a/Code/src/js/classes/Boot.js +++ b/Code/src/js/classes/Boot.js @@ -4,6 +4,26 @@ class Boot extends Phaser.Scene { } preload() { + let progressBar = this.add.graphics(); + let progressBox = this.add.graphics(); + let width = 320; + let height = 50; + let x = WIDTH_WINDOW / 2 - width / 2; + let y = HEIGHT_WINDOW / 2 - height / 2; + + progressBox.fillStyle(0x222222, 0.8); + progressBox.fillRect(x, y, 320, height); + this.load.on('progress', function (value) { + progressBar.clear(); + progressBar.fillStyle(0xffffff, 1); + progressBar.fillRect(x + 10, y + 10, (width - 20) * value, height - 20); + }); + this.load.on('complete', function () { + progressBar.destroy(); + progressBox.destroy(); + }); + + this.load.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}); @@ -11,7 +31,8 @@ class Boot extends Phaser.Scene { 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('bullet', 'assets/bullet.png'); + this.load.image('logoWaria', 'assets/logoWaria.png'); } create() { diff --git a/Code/src/js/classes/Game.js b/Code/src/js/classes/Game.js index 4609081..3ee48bd 100644 --- a/Code/src/js/classes/Game.js +++ b/Code/src/js/classes/Game.js @@ -19,28 +19,34 @@ class Game extends Phaser.Scene { btn.on('pointerdown', () => this.clickPlay(btn)); this.scene.launch('GamingBoard'); this.scene.pause('GamingBoard'); - let rect = this.add.rectangle(WIDTH_WINDOW / 2, 500, 100, 100, 0xffffff); - rect.setInteractive(); - this.input.setDraggable(rect); + 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.input.on('drag', this.doDrag); } - startDrag(pointer, targets) { - this.input.off('pointerdown', this.startDrag, this); - this.dragObj = targets[0]; - this.input.on('pointermove', this.doDrag, this); - this.input.on('pointerup', this.stopDrag, this); + update(time, delta) { + super.update(time, delta); + this.tree.updateLines(); } doDrag(pointer, target, dragX, dragY) { - target.x = dragX; - target.y = dragY; + target.setX(dragX); + target.setY(dragY); } clickPlay(btn) { + btn.setFrame(2); if (this.scene.isPaused('GamingBoard')) - this.scene.resume('GamingBoard'); + this.resume(); else this.scene.pause('GamingBoard'); } + + resume() { + const sortDesc = (a, b) => a.getX() - b.getX(); + this.tree.lNode.sort(sortDesc); + this.gm.modifyNodes(this.tree.lNode); + 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 625ecfe..433b26a 100644 --- a/Code/src/js/classes/GamingBoard.js +++ b/Code/src/js/classes/GamingBoard.js @@ -44,7 +44,11 @@ class GamingBoard extends Phaser.Scene { } resume() { - //this.myself2.updateTarget(); + } + + modifyNodes(lNodes) { + this.listRobot[0].cleanNodes(); + lNodes.forEach(element => this.listRobot[0].addNode(element)); } chooseTarget(robot) { diff --git a/Code/src/js/classes/MoveRectangle.js b/Code/src/js/classes/MoveRectangle.js new file mode 100644 index 0000000..d6b6627 --- /dev/null +++ b/Code/src/js/classes/MoveRectangle.js @@ -0,0 +1,28 @@ +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/Robot.js b/Code/src/js/classes/Robot.js index d0a4d7e..cba5e12 100644 --- a/Code/src/js/classes/Robot.js +++ b/Code/src/js/classes/Robot.js @@ -198,4 +198,8 @@ class Robot { addNode(node) { this.lNode.push(node); } + + cleanNodes() { + this.lNode = []; + } } diff --git a/Code/src/js/classes/Tree.js b/Code/src/js/classes/Tree.js new file mode 100644 index 0000000..96c74d1 --- /dev/null +++ b/Code/src/js/classes/Tree.js @@ -0,0 +1,21 @@ +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