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 += '}';
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.lBtn.push(btn);
btn.tint = 0xEFD807;
btn.tint = COLOR_SELECTED;
this.oneChange();
}

@ -50,4 +50,8 @@ class CategoryBar {
draw() {
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.scene.launch('GamingBoard');
this.scene.pause('GamingBoard');
this.gm.pause();
//this.scene.pause('GamingBoard');
}
loadSave(level) {
this.loadBonus(level.lBonus);
this.loadTeam(level);
let initStat;
let tree;
this.setRobotSelected(this.gm.getMyTeam().listRobot[0]);
this.setRobotSelected(this.gm.getMyTeam().listRobot[0], level);
}
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());
this.robotSelected.setDamage(this.initStat.lBar[0].value);
this.robotSelected.setSpeedReload(this.initStat.lBar[1].value);
this.robotSelected.setSpeed(this.initStat.lBar[2].value);
this.robotSelected.setRange(this.initStat.lBar[3].value);
} else {
initStat = level.initStat;
}
if (this.tree !== undefined) {
tree = JSON.parse(this.tree.getJson(true));
this.tree.destroy();
this.initStat.destroy();
tree = JSON.parse(robot.getTreeJson());
} 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.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);
}
setRobotSelected(robot) {
if (this.robotSelected !== undefined) {
this.initStat = this.loadInitSave(initStat, robot, robot.damage - DAMAGE_BASE, robot.speedReload - SPEED_RELOAD_BASE, robot.speed - SPEED_BASE, robot.range - RANGE_BASE);
}
this.robotSelected = robot;
if (this.robotSelected.team.listRobot.length > 1) {
this.robotSelected.setTint(COLOR_SELECTED);
}
}
loadTree(element, posX = CENTERX_TREE, posY = OFFY_TREE / 2) {
@ -163,7 +176,7 @@ class Game extends ManageLang {
level.listTeam.forEach(team => {
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() {
if (this.scene.isPaused('GamingBoard'))
if (this.gm.paused)
this.resume();
else
this.pauseScene();

@ -5,6 +5,7 @@ class GamingBoard extends Phaser.Scene {
listBonus = [];
this.father = father;
this.end = false;
this.paused = false;
}
preload() {
@ -24,8 +25,8 @@ class GamingBoard extends Phaser.Scene {
}
update(time, delta) {
super.update(time, delta);
if (!this.end) {
if (!this.end && !this.paused) {
super.update(time, delta);
this.listTeam.forEach(team => {
if (!team.actualise(this.getEnemyRobotTeam(team))) {
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) {
let list = [];
this.listTeam.forEach(element => {
@ -81,15 +86,15 @@ class GamingBoard extends Phaser.Scene {
}
pause() {
this.scene.pause('GamingBoard');
this.sound.pauseAll();
this.paused = true;
}
resume() {
this.scene.resume('GamingBoard');
this.sound.resumeAll();
this.setRobotVisible(true);
this.setBonusVisible(true);
this.paused = false;
}
addTeam(team) {
@ -130,9 +135,10 @@ class GamingBoard extends Phaser.Scene {
upShield() {
this.listTeam.forEach(team => team.listRobot.forEach(robot => {
robot.addShield(SHIELD_PER_SECOND);
}));
if (!this.paused)
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});
}

@ -23,9 +23,14 @@ class InitStat {
json += toJson("valueMax", this.category.valueMax);
json += '"lBar":[';
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) + ']}';
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('enemy', 'robots/');
this.loadImage('myBot', 'robots/');
this.loadSprite('playLetter', 550, 150, 'buttons/');
this.loadSprite('cancel', 550, 150, 'buttons/');

@ -63,7 +63,7 @@ class RectangleNode {
if (this.rect.isTinted) {
this.deselect();
} else {
this.rect.tint = 0xEFD807;
this.rect.tint = COLOR_SELECTED;
}
if (this.canAddNode === true) {
console.log("THIS CAN ADD NODE");
@ -185,4 +185,14 @@ class RectangleNode {
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) {
this.scene = scene;
if (this.name === 'enemy') {
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 {
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());
}
@ -48,6 +48,19 @@ class Robot {
} else {
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) {
@ -85,6 +98,10 @@ class Robot {
this.circle.setTint(color);
}
clearTint() {
this.circle.clearTint();
}
setTarget(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) {
this.setSpeed(speed);
this.setRange(range);

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

Loading…
Cancel
Save