Création d'un fichier Variable.js dans le but de regrouper toutes les constantes et les variables - Création d'un fichier Function.js qui regroupe les fonctions globales - Création de la classe Bar qui est a pour père la classe HealthBar, elle permet la création d'une barre plus personnalisable, modifiable en temps réel... - Implémentation de cette barre pour la gestion des variables du robot (attaque, vitesse d'attaque, vitesse, portée)

master
clmaisonha 5 years ago
parent b08d2c8df9
commit 5af7388a95

@ -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))}function chooseTarget(e,t){let a=2*WIDTH_MAP,n=[];return t.forEach(function(t){if(t!==e){let o=Math.hypot(t.x-e.x,t.y-e.y);a>=o&&(a>o&&(a=o,n=[]),n.push(t))}}),n.length>1?n[Math.floor(Math.random()*(n.length+1))]:n[0]}var listBonus=[],LANG=navigator.language.substr(0,2).toLowerCase(),SPEED_GAME=1;const MYSELF="myself",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_WINDOW<HEIGHT_WINDOW?.8*WIDTH_WINDOW:.8*HEIGHT_WINDOW,SPEED=2,LIFE=100,DAMAGE=40,SHIELD=100,RANGE=WIDTH_MAP/2,HEIGHT_BONUS=WIDTH_MAP/10,HEIGHT_DAMAGE=WIDTH_MAP/20,DURATION_DAMAGE=700,TIME_RELOAD=1e3;var config={type:Phaser.AUTO,width:WIDTH_WINDOW,height:HEIGHT_WINDOW,parent:"all",backgroundColor:"#35363A"};let father=new Phaser.Game(config);father.scene.add("LoadFile",new LoadFile(father,"Boot",new Boot(father))),father.scene.start("LoadFile"); let config={type:Phaser.AUTO,width:WIDTH_WINDOW,height:HEIGHT_WINDOW,parent:"all",backgroundColor:"#35363A"},father=new Phaser.Game(config);father.scene.add("LoadFile",new LoadFile(father,"Boot",new Boot(father))),father.scene.start("LoadFile");

File diff suppressed because one or more lines are too long

@ -1 +1 @@
class AddNode extends Phaser.Scene{constructor(e,t,s){super("AddNode"),this.father=e,this.gameR=t,this.selected=s,this.lCategory=[];let i=HEIGHT_WINDOW/14;this.style={font:i.toString()+"px stencil",fill:"#e2e2e2"},this.heightButton=HEIGHT_WINDOW/8}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,i=new Category,a){let n=this.createButton(e,t,s);return n.on("pointerdown",()=>this.click(n,i,a)),n}createButton(e,t,s,i=this.heightButton,a=null){let n=this.add.image(e,t,s).setOrigin(.5,.5).setInteractive();return n.on("pointerover",()=>n.setFrame(1)),n.on("pointerout",()=>n.setFrame(0)),n.displayHeight=i,null===a?n.scaleX=n.scaleY:n.displayWidth=a,n}click(e,t,s){e.isTinted?t.remove(e):t.add(e,s)}newCategory(e,t,s){let i=new Category(e,t,s);return this.lCategory.push(i),i}addTitle(e,t,s){this.add.text(e,t,s,this.style).setOrigin(.5,.5)}createButtonCancel(){this.createButton(WIDTH_WINDOW/3,HEIGHT_WINDOW/(16/15),"cancel",HEIGHT_WINDOW/9).on("pointerdown",()=>this.cancel())}createButtonAdd(e){this.createButton(WIDTH_WINDOW/1.5,HEIGHT_WINDOW/(16/15),"add",HEIGHT_WINDOW/9).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,i,a,n){super(t,s,i,a),this.setOrigin(.5,.5),this.displayHeight=HEIGHT_BONUS,this.scaleX=this.scaleY,t.add.existing(this),this.name=e,this.value=n,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")}}class ManageLang extends Phaser.Scene{constructor(e,t){super(e),this.name=e,this.father=t,this.otherScenes=[]}addOtherScenes(e){this.otherScenes.push(e)}create(){this.createFlags()}createFlags(){this.diffXFlag=0,this.createFlag("fr"),this.createFlag("en")}createFlag(e){let t=this.add.image(WIDTH_WINDOW-10-this.diffXFlag,10,e).setOrigin(1,0).setInteractive();t.displayHeight=40,t.scaleX=t.scaleY,this.diffXFlag=this.diffXFlag+t.displayWidth+10,t.on("pointerdown",()=>this.setLang(e))}setLang(e){e!==LANG&&(LANG=e,this.father.scene.add("LoadFile",new LoadFile(this.father,this.name)),this.father.scene.start("LoadFile"),this.otherScenes.forEach(e=>this.father.scene.stop(e)))}} class AddNode extends Phaser.Scene{constructor(t,e,s){super("AddNode"),this.father=t,this.gameR=e,this.selected=s,this.lCategory=[];let i=HEIGHT_WINDOW/14;this.style={font:i.toString()+"px stencil",fill:"#e2e2e2"},this.heightButton=HEIGHT_WINDOW/8}create(t){let e=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,e,3487290).setOrigin(0,.5),this.createButtonCancel(),this.createButtonAdd(t)}addButton(t,e,s,i=new Category,a){let h=this.createButton(t,e,s);return h.on("pointerdown",()=>this.click(h,i,a)),h}createButton(t,e,s,i=this.heightButton,a=null){let h=this.add.image(t,e,s).setOrigin(.5,.5).setInteractive();return h.on("pointerover",()=>h.setFrame(1)),h.on("pointerout",()=>h.setFrame(0)),h.displayHeight=i,null===a?h.scaleX=h.scaleY:h.displayWidth=a,h}click(t,e,s){t.isTinted?e.remove(t):e.add(t,s)}newCategory(t,e,s){let i=new Category(t,e,s);return this.lCategory.push(i),i}addTitle(t,e,s){this.add.text(t,e,s,this.style).setOrigin(.5,.5)}createButtonCancel(){this.createButton(WIDTH_WINDOW/3,HEIGHT_WINDOW/(16/15),"cancel",HEIGHT_WINDOW/9).on("pointerdown",()=>this.cancel())}createButtonAdd(t){this.createButton(WIDTH_WINDOW/1.5,HEIGHT_WINDOW/(16/15),"add",HEIGHT_WINDOW/9).on("pointerdown",()=>t.addNode())}verifyCategory(){for(let t=0;t<this.lCategory.length;t++)if(!this.lCategory[t].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(t,e,s,i,a,h){super(e,s,i,a),this.setOrigin(.5,.5),this.displayHeight=HEIGHT_BONUS,this.scaleX=this.scaleY,e.add.existing(this),this.name=t,this.value=h,this.scene=e}}class Finish extends Phaser.Scene{constructor(t){super("Finish"),this.father=t}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(t){let e={font:(HEIGHT_WINDOW/6).toString()+"px stencil",fill:"#e2e2e2"};this.add.text(WIDTH_WINDOW/2,HEIGHT_WINDOW/2,t,e).setOrigin(.5,.5)}createButton(t,e){let s=this.add.image(t,HEIGHT_WINDOW/8*7,e).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(t){t.on("pointerdown",()=>this.retry())}retry(){console.log("RETRY"),this.close(),newGame(this.father),this.father.scene.start("Game")}btnHome(t){t.on("pointerdown",()=>this.home())}home(){console.log("HOME"),this.close(),this.father.scene.start("Type")}btnNext(t){t.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 HealthBar{constructor(t,e,s,i,a,h,r,n=COLOR_RED){this.bar=new Phaser.GameObjects.Graphics(t),this.width=Math.floor(e),this.height=Math.floor(s),this.valueMax=h,this.value=h,this.color=r,this.colorMin=n,this.draw(),this.setX(i),this.setY(a),t.add.existing(this.bar)}setValue(t){t<0&&(t=0),t>this.valueMax&&(t=this.valueMax),t!==this.value&&(this.value=t,this.draw())}decrease(t){this.value-=t;let e=0;return this.value<0&&(e=-this.value,this.value=0),this.draw(),e}getBar(){return this.bar}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(this.colorMin):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 ManageLang extends Phaser.Scene{constructor(t,e){super(t),this.name=t,this.father=e,this.otherScenes=[]}addOtherScenes(t){this.otherScenes.push(t)}create(){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,this.father.scene.add("LoadFile",new LoadFile(this.father,this.name)),this.father.scene.start("LoadFile"),this.otherScenes.forEach(t=>this.father.scene.stop(t)))}}

@ -1,65 +1,4 @@
function selectWord(en, fr) { let config = {
switch (LANG) {
case 'fr':
return fr;
default:
return en;
}
}
function newGame(father) {
if (father.scene.getIndex('Game') !== -1) {
father.scene.remove('Game');
}
father.scene.add('Game', new Game(father));
}
function chooseTarget(robot, list) {
let minDist = WIDTH_MAP * 2;
let l = [];
list.forEach(function (item) {
if (item !== robot) {
let hypot = Math.hypot(item.x - robot.x, item.y - robot.y);
if (minDist >= hypot) {
if (minDist > hypot) {
minDist = hypot;
l = [];
}
l.push(item);
}
}
});
if (l.length > 1) {
return l[Math.floor(Math.random() * (l.length + 1))];
} else {
return l[0];
}
}
var listBonus = [];
var LANG = navigator.language.substr(0, 2).toLowerCase();
var SPEED_GAME = 1;
const MYSELF = 'myself';
const SHIELD_PER_SECOND = 5;
const COLOR_ATTACK = 0xff0000;
const COLOR_MOVE = 0x0000ff;
const COLOR_CONDITION = 0x0e0e0e;
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;
const SPEED = 2;
const LIFE = 100;
const DAMAGE = 40;
const SHIELD = 100;
const RANGE = WIDTH_MAP / 2;
const HEIGHT_BONUS = WIDTH_MAP / 10;
const HEIGHT_DAMAGE = WIDTH_MAP / 20;
const DURATION_DAMAGE = 700;
const TIME_RELOAD = 1000;
var config = {
type: Phaser.AUTO, type: Phaser.AUTO,
width: WIDTH_WINDOW, width: WIDTH_WINDOW,
height: HEIGHT_WINDOW, height: HEIGHT_WINDOW,

@ -0,0 +1,47 @@
class Bar extends HealthBar {
constructor(scene, width, height, x, y, startValue, valueMax, color) {
super(scene, width, height, x, y, valueMax, color, color);
this.scene = scene;
this.scene.input.on('pointerdown', this.doDrag, this);
let style = {font: height.toString() + 'px stencil', fill: "#e2e2e2"};
this.text = this.scene.add.text(this.bar.x + this.width + 10, this.bar.y, this.value.toString(), style).setOrigin(0, 0);
this.setValue(startValue);
}
doDrag() {
let pointer = this.scene.input;
if (pointer.x >= this.bar.x && pointer.x <= this.bar.x + this.width && pointer.y >= this.bar.y && pointer.y <= this.bar.y + this.height) {
this.scene.pauseScene();
this.clickOn();
}
}
clickOn() {
this.onMove();
this.scene.input.on('pointermove', () => this.onMove());
this.scene.input.on('pointerup', () => this.stopClick());
}
stopClick() {
this.scene.input.off('pointermove');
this.scene.input.off('pointerup');
}
onMove() {
this.setValWithX(this.scene.input.x);
}
setValWithX(posX) {
this.setValue(Math.round((posX - this.bar.x) / this.width * this.valueMax));
}
draw() {
super.draw();
let posX = this.value / this.valueMax * this.width - 5;
this.bar.fillStyle(0x969696);
this.bar.fillRect(posX, 0, 10, this.height);
if (this.text !== undefined) {
this.text.setText(this.value.toString());
}
}
}

@ -0,0 +1,37 @@
function selectWord(en, fr) {
switch (LANG) {
case 'fr':
return fr;
default:
return en;
}
}
function newGame(father) {
if (father.scene.getIndex('Game') !== -1) {
father.scene.remove('Game');
}
father.scene.add('Game', new Game(father));
}
function chooseTarget(robot, list) {
let minDist = WIDTH_MAP * 2;
let l = [];
list.forEach(function (item) {
if (item !== robot) {
let hypot = Math.hypot(item.x - robot.x, item.y - robot.y);
if (minDist >= hypot) {
if (minDist > hypot) {
minDist = hypot;
l = [];
}
l.push(item);
}
}
});
if (l.length > 1) {
return l[Math.floor(Math.random() * (l.length + 1))];
} else {
return l[0];
}
}

@ -18,6 +18,12 @@ class Game extends ManageLang {
this.selected = null; this.selected = null;
this.damageRobot = new Bar(this, 200, 30, OFFX_MAP + WIDTH_MAP / 4, OFFY_MAP / 2, DAMAGE_BEGIN, 5, COLOR_ATTACK);
this.speedReloadRobot = new Bar(this, 200, 30, OFFX_MAP + WIDTH_MAP / 4, 0, SPEED_RELOAD_BEGIN, 5, COLOR_SPEED_RELOAD);
this.speedRobot = new Bar(this, 200, 30, OFFX_MAP + WIDTH_MAP / 4 * 3, 0, SPEED, 5, COLOR_MOVE);
this.rangeRobot = new Bar(this, 200, 30, OFFX_MAP + WIDTH_MAP / 4 * 3, OFFY_MAP / 2, RANGE_BEGIN, 5, COLOR_RANGE);
this.createButton(); this.createButton();
let centerX = WIDTH_WINDOW / 4 * 3; let centerX = WIDTH_WINDOW / 4 * 3;
@ -66,6 +72,7 @@ class Game extends ManageLang {
clickNode() { clickNode() {
console.log("NODE");
this.tryClick(); this.tryClick();
this.selected = this.tree.getSelected(); this.selected = this.tree.getSelected();
@ -86,11 +93,11 @@ class Game extends ManageLang {
target.setY(dragY); target.setY(dragY);
} }
dragStart(btn) { dragStart() {
console.log("START DRAG"); console.log("START DRAG");
this.doLine = true; this.doLine = true;
this.pauseScene(btn); this.pauseScene();
} }
dragEnd() { dragEnd() {
@ -100,9 +107,9 @@ class Game extends ManageLang {
} }
pauseScene(btn) { pauseScene() {
this.linePlay = 0; this.linePlay = 0;
this.changeFrame(btn, 0); this.changeFrame(this.play, 0);
this.gm.pause(); this.gm.pause();
} }
@ -113,6 +120,7 @@ class Game extends ManageLang {
let sortDesc = (a, b) => a.getX() - b.getX(); let sortDesc = (a, b) => a.getX() - b.getX();
this.tree.sort(sortDesc); this.tree.sort(sortDesc);
this.gm.modifyNodes(this.tree.getNode()); this.gm.modifyNodes(this.tree.getNode());
this.gm.modifyValue(this.speedRobot.value, this.rangeRobot.value, this.speedReloadRobot.value, this.damageRobot.value);
this.gm.resume(); this.gm.resume();
} }
@ -130,7 +138,7 @@ class Game extends ManageLang {
let back = this.add.sprite(10, 10, 'back').setOrigin(0, 0).setInteractive(); let back = this.add.sprite(10, 10, 'back').setOrigin(0, 0).setInteractive();
let play = this.add.sprite(x, y, 'play').setOrigin(1, 0).setInteractive(); this.play = this.add.sprite(x, y, 'play').setOrigin(1, 0).setInteractive();
let speed = this.add.sprite(x - diffX, y, 'speed').setOrigin(1, 0).setInteractive(); let speed = this.add.sprite(x - diffX, y, 'speed').setOrigin(1, 0).setInteractive();
this.pencil = this.add.sprite(x - diffX * 2, y, 'pencil').setOrigin(1, 0).setInteractive().setVisible(false); this.pencil = this.add.sprite(x - diffX * 2, y, 'pencil').setOrigin(1, 0).setInteractive().setVisible(false);
@ -155,15 +163,15 @@ class Game extends ManageLang {
back.displayHeight = back.displayWidth = width; back.displayHeight = back.displayWidth = width;
play.displayHeight = play.displayWidth = width; this.play.displayHeight = this.play.displayWidth = width;
speed.displayHeight = speed.displayWidth = width; speed.displayHeight = speed.displayWidth = width;
mute.displayHeight = mute.displayWidth = width; mute.displayHeight = mute.displayWidth = width;
this.pencil.displayHeight = this.pencil.displayWidth = width; this.pencil.displayHeight = this.pencil.displayWidth = width;
this.bin.displayHeight = this.bin.displayWidth = width; this.bin.displayHeight = this.bin.displayWidth = width;
this.plus.displayHeight = this.plus.displayWidth = width; this.plus.displayHeight = this.plus.displayWidth = width;
play.on('pointerout', () => this.changeFrame(play, 0, this.linePlay)); this.play.on('pointerout', () => this.changeFrame(this.play, 0, this.linePlay));
play.on('pointerover', () => this.changeFrame(play, 1, this.linePlay)); this.play.on('pointerover', () => this.changeFrame(this.play, 1, this.linePlay));
speed.on('pointerout', () => this.changeFrame(speed, 0, this.lineSpeed)); speed.on('pointerout', () => this.changeFrame(speed, 0, this.lineSpeed));
speed.on('pointerover', () => this.changeFrame(speed, 1, this.lineSpeed)); speed.on('pointerover', () => this.changeFrame(speed, 1, this.lineSpeed));
mute.on('pointerout', () => this.changeFrame(mute, 0, this.lineMute)); mute.on('pointerout', () => this.changeFrame(mute, 0, this.lineMute));
@ -173,7 +181,7 @@ class Game extends ManageLang {
this.creatBtnOutAndOver(this.bin); this.creatBtnOutAndOver(this.bin);
this.creatBtnOutAndOver(this.plus); this.creatBtnOutAndOver(this.plus);
play.on('pointerdown', () => this.clickPlay(play)); this.play.on('pointerdown', () => this.clickPlay());
speed.on('pointerdown', () => this.clickSpeed(speed)); speed.on('pointerdown', () => this.clickSpeed(speed));
back.on('pointerdown', () => this.clickBack()); back.on('pointerdown', () => this.clickBack());
mute.on('pointerdown', () => this.clickMute(mute)); mute.on('pointerdown', () => this.clickMute(mute));
@ -183,7 +191,7 @@ class Game extends ManageLang {
this.input.on('pointerdown', () => this.clickNode()); this.input.on('pointerdown', () => this.clickNode());
this.input.on('drag', this.doDrag); this.input.on('drag', this.doDrag);
this.input.on('dragstart', () => this.dragStart(play)); this.input.on('dragstart', () => this.dragStart());
this.input.on('dragend', () => this.dragEnd()); this.input.on('dragend', () => this.dragEnd());
} }
@ -192,13 +200,13 @@ class Game extends ManageLang {
btn.on('pointerover', () => this.changeFrame(btn, 1)); btn.on('pointerover', () => this.changeFrame(btn, 1));
} }
clickPlay(btn) { clickPlay() {
if (this.scene.isPaused('GamingBoard')) if (this.scene.isPaused('GamingBoard'))
this.resume(); this.resume();
else else
this.pauseScene(btn); this.pauseScene();
this.changeFrame(btn, 1, this.linePlay); this.changeFrame(this.play, 1, this.linePlay);
} }
clickSpeed(btn) { clickSpeed(btn) {

@ -8,7 +8,7 @@ class GamingBoard extends Phaser.Scene {
} }
preload() { preload() {
this.cameras.main.setViewport(WIDTH_WINDOW / 10, HEIGHT_WINDOW / 10, WIDTH_MAP, WIDTH_MAP); this.cameras.main.setViewport(OFFX_MAP, OFFY_MAP, WIDTH_MAP, WIDTH_MAP);
this.sound.add('shot'); this.sound.add('shot');
this.sound.add('hit'); this.sound.add('hit');
} }
@ -58,7 +58,7 @@ class GamingBoard extends Phaser.Scene {
} }
winner() { winner() {
return this.listRobot.length !== 0 && this.listRobot[0].name === 'myself'; return this.getMyRobot() !== undefined;
} }
pause() { pause() {
@ -76,14 +76,34 @@ class GamingBoard extends Phaser.Scene {
} }
modifyNodes(lNodes) { modifyNodes(lNodes) {
let myRobot = this.getMyRobot();
if (myRobot !== undefined) {
myRobot.cleanNodes();
lNodes.forEach(element => myRobot.addNode(element));
return true;
}
return false;
}
modifyValue(speed, range, speedReload, damage) {
let myRobot = this.getMyRobot();
if (myRobot !== undefined) {
myRobot.setSpeed(speed);
myRobot.setRange(range);
myRobot.setSpeedReload(speedReload);
myRobot.setDamage(damage);
return true;
}
return false;
}
getMyRobot() {
for (let i = 0; i < this.listRobot.length; i++) { for (let i = 0; i < this.listRobot.length; i++) {
if (this.listRobot[i].name === MYSELF) { if (this.listRobot[i].name === MYSELF) {
this.listRobot[i].cleanNodes(); return this.listRobot[i];
lNodes.forEach(element => this.listRobot[0].addNode(element));
return true;
} }
} }
return false; return undefined;
} }

@ -1,6 +1,7 @@
class Robot { class Robot {
constructor(height, width, posX, posY, color, scene, name = 'enemy', speed = 1) { constructor(height, width, posX, posY, color, scene, name = 'enemy', speed = 1) {
this.speed = speed; this.speed = speed;
this.speedReload = SPEED_RELOAD_BEGIN;
this.timeReload = TIME_RELOAD; this.timeReload = TIME_RELOAD;
this.name = name; this.name = name;
this.height = height; this.height = height;
@ -8,8 +9,8 @@ class Robot {
this.x = posX; this.x = posX;
this.y = posY; this.y = posY;
this.color = color; this.color = color;
this.range = WIDTH_MAP / 2; this.range = RANGE_BEGIN;
this.damage = DAMAGE; this.damage = DAMAGE_BEGIN;
this.life = new HealthBar(scene, this.width * 2, this.width / 3, this.x, this.y - this.width, LIFE, 0x008000); this.life = new HealthBar(scene, this.width * 2, this.width / 3, this.x, this.y - this.width, LIFE, 0x008000);
this.shield = new HealthBar(scene, this.width * 2, this.width / 3, this.x, this.y - this.width * 1.5, SHIELD, 0x0000FF); this.shield = new HealthBar(scene, this.width * 2, this.width / 3, this.x, this.y - this.width * 1.5, SHIELD, 0x0000FF);
this.circleRange = null; this.circleRange = null;
@ -80,10 +81,23 @@ class Robot {
setTargetPos(x, y) { setTargetPos(x, y) {
} }
setSpeed(speed) { setDamage(damage = this.damage) {
this.damage = damage;
}
setRange(range = this.range) {
this.range = range;
this.drawCircleRange();
}
setSpeed(speed = this.speed) {
this.speed = speed; this.speed = speed;
} }
setSpeedReload(speedReload = this.speedReload) {
this.speedReload = speedReload;
}
increaseSpeed(amount) { increaseSpeed(amount) {
this.speed += amount; this.speed += amount;
} }
@ -217,14 +231,14 @@ class Robot {
}); });
this.scene.time.addEvent({ this.scene.time.addEvent({
delay: this.timeReload / SPEED_GAME, delay: TIME_RELOAD / this.speedReload / SPEED_GAME,
callback: this.reload, callback: this.reload,
callbackScope: this callbackScope: this
}); });
} }
finishAttack(target, percentBonus) { finishAttack(target, percentBonus) {
if (target.beAttack(this.damage * percentBonus)) { if (target.beAttack(this.damage * DAMAGE * percentBonus)) {
this.setTarget(null); this.setTarget(null);
} }
this.missile.setVisible(false); this.missile.setVisible(false);
@ -262,7 +276,7 @@ class Robot {
isTargetInRange(percentRange = 1) { isTargetInRange(percentRange = 1) {
if (this.haveTarget()) { if (this.haveTarget()) {
return this.calcDistance(this.target) < this.range * percentRange; return this.calcDistance(this.target) <= this.range * RANGE * percentRange;
} }
return false; return false;
} }
@ -319,23 +333,23 @@ class Robot {
this.circleRange.clear(); this.circleRange.clear();
let color = 0x008000; let color = COLOR_GREEN;
let thickness = 4; let thickness = 4;
let alpha = 1 / 3; let alpha = 1 / 3;
this.circleRange.lineStyle(thickness, color, alpha); this.circleRange.lineStyle(thickness, color, alpha);
let radius = this.range; let radius = this.range * RANGE;
this.circleRange.strokeCircle(this.x, this.y, radius); this.circleRange.strokeCircle(this.x, this.y, radius);
color = 0xff7f00; color = COLOR_ORANGE;
alpha = 2 / 3; alpha = 2 / 3;
this.circleRange.lineStyle(thickness, color, alpha); this.circleRange.lineStyle(thickness, color, alpha);
radius = this.range * 2 / 3; radius = this.range * RANGE * 2 / 3;
this.circleRange.strokeCircle(this.x, this.y, radius); this.circleRange.strokeCircle(this.x, this.y, radius);
color = 0xff0000; color = COLOR_RED;
alpha = 1; alpha = 1;
this.circleRange.lineStyle(thickness, color, alpha); this.circleRange.lineStyle(thickness, color, alpha);
radius = this.range / 3; radius = this.range * RANGE / 3;
this.circleRange.strokeCircle(this.x, this.y, radius); this.circleRange.strokeCircle(this.x, this.y, radius);
} }
} }

@ -0,0 +1,30 @@
var listBonus = [];
var LANG = navigator.language.substr(0, 2).toLowerCase();
var SPEED_GAME = 1;
const MYSELF = 'myself';
const SHIELD_PER_SECOND = 5;
const COLOR_ATTACK = 0xff0000;
const COLOR_MOVE = 0x0000ff;
const COLOR_CONDITION = 0x0e0e0e;
const COLOR_RED = 0xff0000;
const COLOR_ORANGE = 0xff7f00;
const COLOR_GREEN = 0x008000;
const COLOR_RANGE = 0x008000;
const COLOR_SPEED_RELOAD = 0x7f00ff;
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;
const OFFX_MAP = WIDTH_WINDOW / 20;
const OFFY_MAP = WIDTH_WINDOW / 20;
const SPEED = 2;
const LIFE = 100;
const DAMAGE = 10;
const DAMAGE_BEGIN = 3;
const SHIELD = 100;
const RANGE_BEGIN = 2;
const RANGE = WIDTH_MAP / 4;
const HEIGHT_BONUS = WIDTH_MAP / 10;
const HEIGHT_DAMAGE = WIDTH_MAP / 20;
const DURATION_DAMAGE = 700;
const TIME_RELOAD = 4000;
const SPEED_RELOAD_BEGIN = 2;

@ -1,5 +1,5 @@
class HealthBar { class HealthBar {
constructor(scene, width, height, x, y, valueMax, color) { constructor(scene, width, height, x, y, valueMax, color, colorMin = COLOR_RED) {
this.bar = new Phaser.GameObjects.Graphics(scene); this.bar = new Phaser.GameObjects.Graphics(scene);
this.width = Math.floor(width); this.width = Math.floor(width);
@ -7,6 +7,7 @@ class HealthBar {
this.valueMax = valueMax; this.valueMax = valueMax;
this.value = valueMax; this.value = valueMax;
this.color = color; this.color = color;
this.colorMin = colorMin;
this.draw(); this.draw();
@ -15,6 +16,19 @@ class HealthBar {
scene.add.existing(this.bar); scene.add.existing(this.bar);
} }
setValue(value) {
if (value < 0) {
value = 0;
}
if (value > this.valueMax) {
value = this.valueMax;
}
if (value !== this.value) {
this.value = value;
this.draw();
}
}
decrease(amount) { decrease(amount) {
this.value -= amount; this.value -= amount;
@ -29,6 +43,10 @@ class HealthBar {
return diff; return diff;
} }
getBar() {
return this.bar;
}
increase(amount) { increase(amount) {
this.value += amount; this.value += amount;
if (this.value > this.valueMax) { if (this.value > this.valueMax) {
@ -60,7 +78,7 @@ class HealthBar {
let percent = this.value / this.valueMax; let percent = this.value / this.valueMax;
if (percent < 1 / 3) { if (percent < 1 / 3) {
this.bar.fillStyle(0xff0000); this.bar.fillStyle(this.colorMin);
} else { } else {
this.bar.fillStyle(this.color); this.bar.fillStyle(this.color);
} }
Loading…
Cancel
Save