Création du premier bonus (SpeedBonus) - Implémentation du bonus sur la carte - Implémentation de l'action aller vers le bonus pour le robot - Lorsque deux robots sont les uns sur les autres, l'attaque est possible. Par contre, les déplacments pour fuir ou pour avancer sont impossible
parent
66c292a919
commit
c1509d8ccb
@ -1 +1 @@
|
||||
function selectWord(e,t){switch(LANG){case"fr":return t;default:return e}}function newGame(e){-1!==e.scene.getIndex("Game")&&e.scene.remove("Game"),e.scene.add("Game",new Game(e))}var LANG=navigator.language.substr(0,2).toLowerCase();const MYSELF="myself",SHIELD_PER_SECOND=5,COLOR_ATTACK=16711680,COLOR_MOVE=255,COLOR_CONDITION=921102,DURATION_DAMAGE=700,WIDTH_WINDOW=$(document).width()-20,HEIGHT_WINDOW=$(document).height()-20,WIDTH_MAP=WIDTH_WINDOW<HEIGHT_WINDOW?.8*WIDTH_WINDOW:.8*HEIGHT_WINDOW,SPEED=2,LIFE=100,DAMAGE=40,SHIELD=100,RANGE=WIDTH_MAP/2;var config={type:Phaser.AUTO,width:WIDTH_WINDOW,height:HEIGHT_WINDOW,parent:"all",backgroundColor:"#35363A"};let father=new Phaser.Game(config);father.scene.add("Boot",new Boot(father)),father.scene.start("Boot");
|
||||
function selectWord(e,t){switch(LANG){case"fr":return t;default:return e}}function newGame(e){-1!==e.scene.getIndex("Game")&&e.scene.remove("Game"),e.scene.add("Game",new Game(e))}function chooseTarget(e,t){let n=2*WIDTH_MAP,a=[];return t.forEach(function(t){if(t!==e){let o=Math.hypot(t.x-e.x,t.y-e.y);n>=o&&(n>o&&(n=o,a=[]),a.push(t))}}),a.length>1?a[Math.floor(Math.random()*(a.length+1))]:a[0]}var listBonus=[],LANG=navigator.language.substr(0,2).toLowerCase();const MYSELF="myself",SHIELD_PER_SECOND=5,COLOR_ATTACK=16711680,COLOR_MOVE=255,COLOR_CONDITION=921102,DURATION_DAMAGE=700,WIDTH_WINDOW=$(document).width()-20,HEIGHT_WINDOW=$(document).height()-20,WIDTH_MAP=WIDTH_WINDOW<HEIGHT_WINDOW?.8*WIDTH_WINDOW:.8*HEIGHT_WINDOW,SPEED=2,LIFE=100,DAMAGE=40,SHIELD=100,RANGE=WIDTH_MAP/2;var config={type:Phaser.AUTO,width:WIDTH_WINDOW,height:HEIGHT_WINDOW,parent:"all",backgroundColor:"#35363A"};let father=new Phaser.Game(config);father.scene.add("Boot",new Boot(father)),father.scene.start("Boot");
|
File diff suppressed because one or more lines are too long
@ -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,s,i,r=new Category,o){let a=this.createButton(e,t,n,s,i);return a.on("pointerdown",()=>this.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;e<this.lCategory.length;e++)if(!this.lCategory[e].validate())return!1;return!0}cancel(){this.scene.resume("Game"),this.scene.stop("AddNode"),this.father.scene.remove("AddNode")}}class Finish extends Phaser.Scene{constructor(e){super("Finish"),this.father=e}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)}addTitle(e){let t={font:(HEIGHT_WINDOW/6).toString()+"px stencil",fill:"#e2e2e2"};this.add.text(WIDTH_WINDOW/2,HEIGHT_WINDOW/2,e,t).setOrigin(.5,.5)}createButton(e,t){let n=this.add.image(e,HEIGHT_WINDOW/8*7,t).setOrigin(.5,.5).setInteractive();return n.on("pointerover",()=>n.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")}}
|
||||
class AddNode extends Phaser.Scene{constructor(e,t,s){super("AddNode"),this.father=e,this.gameR=t,this.selected=s,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,s,n,i,r=new Category,a){let o=this.createButton(e,t,s,n,i);return o.on("pointerdown",()=>this.click(o,r,a)),o}createButton(e,t,s,n,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=n,null===s?r.scaleX=r.scaleY:r.displayWidth=s,r}click(e,t,s){e.isTinted?t.remove(e):t.add(e,s)}newCategory(e,t,s){let n=new Category(e,t,s);return this.lCategory.push(n),n}addTitle(e,t,s){let n={font:(HEIGHT_WINDOW/12).toString()+"px stencil",fill:"#e2e2e2"};this.add.text(e,t,s,n).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;e<this.lCategory.length;e++)if(!this.lCategory[e].validate())return!1;return!0}cancel(){this.scene.resume("Game"),this.scene.stop("AddNode"),this.father.scene.remove("AddNode")}}class Bonus extends Phaser.GameObjects.Image{constructor(e,t,s,n,i,r){super(t,s,n,i),this.setOrigin(.5,.5),t.add.existing(this),this.name=e,this.value=r,this.scene=t}}class Finish extends Phaser.Scene{constructor(e){super("Finish"),this.father=e}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)}addTitle(e){let t={font:(HEIGHT_WINDOW/6).toString()+"px stencil",fill:"#e2e2e2"};this.add.text(WIDTH_WINDOW/2,HEIGHT_WINDOW/2,e,t).setOrigin(.5,.5)}createButton(e,t){let s=this.add.image(e,HEIGHT_WINDOW/8*7,t).setOrigin(.5,.5).setInteractive();return s.on("pointerover",()=>s.setFrame(1)),s.on("pointerout",()=>s.setFrame(0)),s.displayHeight=HEIGHT_WINDOW/9,s.scaleX=s.scaleY,s}btnRetry(e){e.on("pointerdown",()=>this.retry())}retry(){console.log("RETRY"),this.close(),newGame(this.father),this.father.scene.start("Game")}btnHome(e){e.on("pointerdown",()=>this.home())}home(){console.log("HOME"),this.close(),this.father.scene.start("Type")}btnNext(e){e.on("pointerdown",()=>this.next())}next(){console.log("NEXT")}close(){this.sound.stopAll(),this.father.scene.remove("GamingBoard"),this.father.scene.remove("Game"),this.father.scene.remove("Finish")}}
|
@ -1,13 +1,12 @@
|
||||
class BonusSpeed extends Bonus {
|
||||
constructor(name, scene, x, y, value, time) {
|
||||
super(name, scene, x, y, 'bonusSpeed', value);
|
||||
super(name, scene, x, y, 'play', value);
|
||||
this.time = time;
|
||||
}
|
||||
|
||||
useOn(robot) {
|
||||
let oldSpeed = robot.speed;
|
||||
robot.setSpeed(oldSpeed + this.value);
|
||||
this.scene.time.addEvent({delay: this.time, callback: robot.setSpeed(oldSpeed)});
|
||||
robot.increaseSpeed(this.value);
|
||||
this.scene.time.addEvent({delay: this.time, callback: () => robot.decreaseSpeed(this.value)});
|
||||
this.destroy();
|
||||
}
|
||||
}
|
@ -1,24 +1,43 @@
|
||||
class Move {
|
||||
constructor(toward) { //true = move toward / false = flee from
|
||||
constructor(toward, enemyBot = true) { //true = move toward / false = flee from
|
||||
this.toward = toward;
|
||||
this.enemyBot = enemyBot;
|
||||
}
|
||||
|
||||
do(robot) {
|
||||
if (robot.haveTarget()) {
|
||||
if (this.toward === true) {
|
||||
return this.moveToward(robot);
|
||||
} else {
|
||||
return this.fleeFrom(robot);
|
||||
if (this.enemyBot) {
|
||||
if (robot.verifyTarget()) {
|
||||
if (this.toward === true) {
|
||||
return this.moveToward(robot);
|
||||
} else {
|
||||
return this.fleeFrom(robot);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
let bonusTarget = chooseTarget(robot, listBonus);
|
||||
if (bonusTarget !== undefined) {
|
||||
let ret;
|
||||
if (this.toward === true) {
|
||||
ret = this.moveToward(robot, bonusTarget);
|
||||
} else {
|
||||
ret = this.fleeFrom(robot, bonusTarget);
|
||||
}
|
||||
if (!ret) {
|
||||
bonusTarget.useOn(robot);
|
||||
listBonus.splice(listBonus.indexOf(bonusTarget), 1);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
moveToward(robot) {
|
||||
return robot.advanceToTarget();
|
||||
moveToward(robot, target = robot.target) {
|
||||
return robot.advanceTo(target);
|
||||
|
||||
}
|
||||
|
||||
fleeFrom(robot) {
|
||||
return robot.fleeFromTarget();
|
||||
fleeFrom(robot, target = robot.target) {
|
||||
return robot.fleeFrom(target);
|
||||
}
|
||||
}
|
@ -1,7 +1,10 @@
|
||||
class Bonus extends Phaser.GameObjects.Image {
|
||||
constructor(name, scene, x, y, texture, value) {
|
||||
super(scene, x, y, texture);
|
||||
this.setOrigin(0.5, 0.5);
|
||||
scene.add.existing(this);
|
||||
this.name = name;
|
||||
this.value = value;
|
||||
this.scene = scene;
|
||||
}
|
||||
}
|
Loading…
Reference in new issue