Ajout de l'image myBot.png - Ajout des fonctions destroy dans bar, CategoryBar, InitStat et RectangleNode - Ajout de la possibilité de modifier 2 robots de manière indépendante, le robot sélectionné se teint en jaune

master
clmaisonha 5 years ago
parent 1e2e822e8f
commit f79c676102

Binary file not shown.

After

Width:  |  Height:  |  Size: 51 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 51 KiB

File diff suppressed because one or more lines are too long

@ -82,4 +82,10 @@ class Bar extends HealthBar {
json += '}'; json += '}';
return json; return json;
} }
destroy() {
super.destroy();
this.text.destroy();
this.scene.input.off('pointerdown', this.doDrag, this);
}
} }

@ -30,7 +30,7 @@ class Category {
} }
this.lValue.push(value); this.lValue.push(value);
this.lBtn.push(btn); this.lBtn.push(btn);
btn.tint = 0xEFD807; btn.tint = COLOR_SELECTED;
this.oneChange(); this.oneChange();
} }

@ -50,4 +50,8 @@ class CategoryBar {
draw() { draw() {
this.textScene.setText(this.text + this.point); this.textScene.setText(this.text + this.point);
} }
destroy() {
this.textScene.destroy();
}
} }

@ -83,39 +83,52 @@ class Game extends ManageLang {
} }
this.father.scene.add('GamingBoard', this.gm); this.father.scene.add('GamingBoard', this.gm);
this.scene.launch('GamingBoard'); this.scene.launch('GamingBoard');
this.scene.pause('GamingBoard'); this.gm.pause();
//this.scene.pause('GamingBoard');
} }
loadSave(level) { loadSave(level) {
this.loadBonus(level.lBonus); this.loadBonus(level.lBonus);
this.loadTeam(level); this.loadTeam(level);
let initStat; this.setRobotSelected(this.gm.getMyTeam().listRobot[0], level);
let tree; }
this.setRobotSelected(this.gm.getMyTeam().listRobot[0]);
if (this.initStat !== undefined) { setRobotSelected(robot, level) {
let tree;
let initStat;
if (this.robotSelected !== undefined && this.robotSelected !== robot && this.tree !== undefined && this.initStat !== undefined) {
this.robotSelected.clearTint();
this.tree.sort();
this.robotSelected.setNodes(this.tree.getNode());
initStat = JSON.parse(this.initStat.getJson()); initStat = JSON.parse(this.initStat.getJson());
this.robotSelected.setDamage(this.initStat.lBar[0].value); this.tree.destroy();
this.robotSelected.setSpeedReload(this.initStat.lBar[1].value); this.initStat.destroy();
this.robotSelected.setSpeed(this.initStat.lBar[2].value); tree = JSON.parse(robot.getTreeJson());
this.robotSelected.setRange(this.initStat.lBar[3].value);
} else {
initStat = level.initStat;
}
if (this.tree !== undefined) {
tree = JSON.parse(this.tree.getJson(true));
} else { } else {
tree = JSON.parse(this.robotSelected.getTreeJson()); if (this.initStat !== undefined) {
initStat = JSON.parse(this.initStat.getJson());
robot.setDamage(this.initStat.lBar[0].value);
robot.setSpeedReload(this.initStat.lBar[1].value);
robot.setSpeed(this.initStat.lBar[2].value);
robot.setRange(this.initStat.lBar[3].value);
this.initStat.destroy();
} else {
initStat = level.initStat;
}
if (this.tree !== undefined) {
tree = JSON.parse(this.tree.getJson(true));
this.tree.destroy();
} else {
tree = JSON.parse(robot.getTreeJson());
}
} }
this.tree = this.loadTree(tree); this.tree = this.loadTree(tree);
this.initStat = this.loadInitSave(initStat, this.robotSelected, this.robotSelected.damage - DAMAGE_BASE, this.robotSelected.speedReload - SPEED_RELOAD_BASE, this.robotSelected.speed - SPEED_BASE, this.robotSelected.range - RANGE_BASE); this.initStat = this.loadInitSave(initStat, robot, robot.damage - DAMAGE_BASE, robot.speedReload - SPEED_RELOAD_BASE, robot.speed - SPEED_BASE, robot.range - RANGE_BASE);
}
setRobotSelected(robot) {
if (this.robotSelected !== undefined) {
}
this.robotSelected = robot; this.robotSelected = robot;
if (this.robotSelected.team.listRobot.length > 1) {
this.robotSelected.setTint(COLOR_SELECTED);
}
} }
loadTree(element, posX = CENTERX_TREE, posY = OFFY_TREE / 2) { loadTree(element, posX = CENTERX_TREE, posY = OFFY_TREE / 2) {
@ -163,7 +176,7 @@ class Game extends ManageLang {
level.listTeam.forEach(team => { level.listTeam.forEach(team => {
init += this.loadT(team.name, team.freeForAll, team.robots, level.robotRandomPosition, init, team.color) init += this.loadT(team.name, team.freeForAll, team.robots, level.robotRandomPosition, init, team.color)
}); });
this.gm.addEventMyTeam(this.setRobotSelected, this);
} }
} }
@ -380,7 +393,7 @@ class Game extends ManageLang {
} }
clickPlay() { clickPlay() {
if (this.scene.isPaused('GamingBoard')) if (this.gm.paused)
this.resume(); this.resume();
else else
this.pauseScene(); this.pauseScene();

@ -5,6 +5,7 @@ class GamingBoard extends Phaser.Scene {
listBonus = []; listBonus = [];
this.father = father; this.father = father;
this.end = false; this.end = false;
this.paused = false;
} }
preload() { preload() {
@ -24,8 +25,8 @@ class GamingBoard extends Phaser.Scene {
} }
update(time, delta) { update(time, delta) {
super.update(time, delta); if (!this.end && !this.paused) {
if (!this.end) { super.update(time, delta);
this.listTeam.forEach(team => { this.listTeam.forEach(team => {
if (!team.actualise(this.getEnemyRobotTeam(team))) { if (!team.actualise(this.getEnemyRobotTeam(team))) {
this.listTeam.splice(this.listTeam.indexOf(team), 1); this.listTeam.splice(this.listTeam.indexOf(team), 1);
@ -43,6 +44,10 @@ class GamingBoard extends Phaser.Scene {
} }
} }
addEventMyTeam(event, context) {
this.getMyTeam().addEvent(event, context);
}
getEnemyRobotTeam(team) { getEnemyRobotTeam(team) {
let list = []; let list = [];
this.listTeam.forEach(element => { this.listTeam.forEach(element => {
@ -81,15 +86,15 @@ class GamingBoard extends Phaser.Scene {
} }
pause() { pause() {
this.scene.pause('GamingBoard');
this.sound.pauseAll(); this.sound.pauseAll();
this.paused = true;
} }
resume() { resume() {
this.scene.resume('GamingBoard');
this.sound.resumeAll(); this.sound.resumeAll();
this.setRobotVisible(true); this.setRobotVisible(true);
this.setBonusVisible(true); this.setBonusVisible(true);
this.paused = false;
} }
addTeam(team) { addTeam(team) {
@ -130,9 +135,10 @@ class GamingBoard extends Phaser.Scene {
upShield() { upShield() {
this.listTeam.forEach(team => team.listRobot.forEach(robot => { if (!this.paused)
robot.addShield(SHIELD_PER_SECOND); this.listTeam.forEach(team => team.listRobot.forEach(robot => {
})); robot.addShield(SHIELD_PER_SECOND);
}));
this.time.addEvent({delay: 1000 / SPEED_GAME, callback: this.upShield, callbackScope: this}); this.time.addEvent({delay: 1000 / SPEED_GAME, callback: this.upShield, callbackScope: this});
} }

@ -23,9 +23,14 @@ class InitStat {
json += toJson("valueMax", this.category.valueMax); json += toJson("valueMax", this.category.valueMax);
json += '"lBar":['; json += '"lBar":[';
for (let i = 0; i < this.lBar.length; i++) { for (let i = 0; i < this.lBar.length; i++) {
json += this.lBar[i].getJson(this.lText[i]) + ',' json += this.lBar[i].getJson(this.lText[i]) + ',';
} }
json = endLineJson(json) + ']}'; json = endLineJson(json) + ']}';
return json; return json;
} }
destroy() {
this.category.destroy();
this.lBar.forEach(bar => bar.destroy());
}
} }

@ -47,6 +47,7 @@ class LoadFile extends Phaser.Scene {
this.loadImage('bonusShield2', 'bonus/', true); this.loadImage('bonusShield2', 'bonus/', true);
this.loadImage('enemy', 'robots/'); this.loadImage('enemy', 'robots/');
this.loadImage('myBot', 'robots/');
this.loadSprite('playLetter', 550, 150, 'buttons/'); this.loadSprite('playLetter', 550, 150, 'buttons/');
this.loadSprite('cancel', 550, 150, 'buttons/'); this.loadSprite('cancel', 550, 150, 'buttons/');

@ -63,7 +63,7 @@ class RectangleNode {
if (this.rect.isTinted) { if (this.rect.isTinted) {
this.deselect(); this.deselect();
} else { } else {
this.rect.tint = 0xEFD807; this.rect.tint = COLOR_SELECTED;
} }
if (this.canAddNode === true) { if (this.canAddNode === true) {
console.log("THIS CAN ADD NODE"); console.log("THIS CAN ADD NODE");
@ -185,4 +185,14 @@ class RectangleNode {
json += '}'; json += '}';
return json; return json;
} }
destroy() {
this.rect.destroy();
if (this.line !== undefined) {
this.line.destroy();
}
if (this.lRect !== undefined) {
this.lRect.forEach(rect => rect.destroy());
}
}
} }

@ -30,15 +30,15 @@ class Robot {
} }
addScene(scene) { addScene(scene) {
this.scene = scene; this.scene = scene;
if (this.name === 'enemy') { if (this.name === 'enemy') {
this.circle = this.scene.add.image(this.x, this.y, 'enemy').setOrigin(0.5, 0.5).setInteractive(); this.circle = this.scene.add.image(this.x, this.y, 'enemy').setOrigin(0.5, 0.5).setInteractive();
this.circle.displayWidth = this.circle.displayHeight = this.width;
} else { } else {
this.circle = this.scene.add.circle(this.x, this.y, this.width / 2, COLOR_MYSELF).setInteractive(); this.circle = this.scene.add.image(this.x, this.y, 'myBot').setOrigin(0.5, 0.5).setInteractive();
} }
this.circle.displayWidth = this.width;
this.circle.displayHeight = this.height;
this.circle.on('pointerdown', () => this.click()); this.circle.on('pointerdown', () => this.click());
} }
@ -48,6 +48,19 @@ class Robot {
} else { } else {
this.eraseRange(); this.eraseRange();
} }
this.doEvent();
}
addEvent(eventClick, contextClick) {
this.eventClick = eventClick;
this.contextClick = contextClick;
}
doEvent() {
if (this.eventClick !== undefined && this.contextClick !== undefined) {
this.eventClick.call(this.contextClick, this);
}
} }
addShield(shield) { addShield(shield) {
@ -85,6 +98,10 @@ class Robot {
this.circle.setTint(color); this.circle.setTint(color);
} }
clearTint() {
this.circle.clearTint();
}
setTarget(target) { setTarget(target) {
this.target = target; this.target = target;
} }

@ -46,6 +46,12 @@ class Team {
} }
addEvent(event, context) {
this.listRobot.forEach(robot => {
robot.addEvent(event, context);
});
}
modifyValue(damage, speedReload, speed, range) { modifyValue(damage, speedReload, speed, range) {
this.setSpeed(speed); this.setSpeed(speed);
this.setRange(range); this.setRange(range);

@ -16,6 +16,7 @@ const COLOR_GREEN = 0x008000;
const COLOR_RANGE = 0x008000; const COLOR_RANGE = 0x008000;
const COLOR_SPEED_RELOAD = 0x7f00ff; const COLOR_SPEED_RELOAD = 0x7f00ff;
const NUMBER_LEVEL = 2; const NUMBER_LEVEL = 2;
const COLOR_SELECTED = 0xEFD807;
const COLOR_MYSELF = 0x6666ff; const COLOR_MYSELF = 0x6666ff;
const WIDTH_WINDOW = $(document).width() - 20; const WIDTH_WINDOW = $(document).width() - 20;

Loading…
Cancel
Save