Ajout de la possibilité d'ajouter une attaque ou un déplacement - Ajout des différentes distances d'attaques sur les robot - Ajout de la possibilité d'afficher ou non la distance d'attaque des robots en cliquant dessus (pour le moment, on ne peut cliquer dessus uniquement lorsque le jeux est en marche) - Ajout de la visibilité des trois distances d'attaque à l'aide d'un code couleur (vert, orange, rouge) - Fix d'un problème d'affichage lorsque les robots mourraient (les cercles de distance restaient affichés) - Ajout de la possibilité de modifier la vitesse des robots - Reclassification des dossiers du code sous forme de niveau de création (niveau 1 - 2 - 3)

master
clmaisonha 5 years ago
parent 8169ee92ae
commit 4c8a6d4adc

@ -12,8 +12,9 @@ module.exports = function (grunt) {
uglify: { uglify: {
my_target: { my_target: {
files: { files: {
'public/js//app.min.js': ['src/js/*.js'], 'public/js//level1.min.js': ['src/js/level1/*.js'],
'public/js//class.min.js': ['src/js/classes/*.js'] 'public/js//level2.min.js': ['src/js/level2/*.js'],
'public/js//level3.min.js': ['src/js/level3/*.js']
} }
} }
}, },

@ -13,8 +13,8 @@
<body> <body>
<div id='all'></div> <div id='all'></div>
<script src="public/js/AddNode.js"></script> <script src="public/js/level3.min.js"></script>
<script src="public/js/class.min.js"></script> <script src="public/js/level2.min.js"></script>
<script src="public/js/app.min.js"></script> <script src="public/js/level1.min.js"></script>
</body> </body>
</html> </html>

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

@ -0,0 +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,r,i,a=new Category,s){let d=this.createButton(e,t,n,r,i);return d.on("pointerdown",()=>this.click(d,a,s)),d}createButton(e,t,n,r,i){let a=this.add.image(e,t,i).setOrigin(.5,.5).setInteractive();return a.on("pointerover",()=>a.setFrame(1)),a.on("pointerout",()=>a.setFrame(0)),a.displayHeight=r,null===n?a.scaleX=a.scaleY:a.displayWidth=n,a}click(e,t,n){e.isTinted?t.remove(e):t.add(e,n)}newCategory(e,t,n){let r=new Category(e,t,n);return this.lCategory.push(r),r}addTitle(e,t,n){let r={font:(HEIGHT_WINDOW/12).toString()+"px stencil",fill:"#e2e2e2"};this.add.text(e,t,n,r).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")}}

@ -1,15 +0,0 @@
class AddAttack extends AddNode {
constructor(father, game, selected) {
super(father, game, selected);
}
create() {
console.log("ATTACK");
super.create(this);
super.addTitle(WIDTH_WINDOW / 2, HEIGHT_WINDOW / 16, selectWord("ADD NODE : ATTACK", "AJOUTER ACTION : ATTAQUE"));
super.addTitle(WIDTH_WINDOW / 2, HEIGHT_WINDOW / (16 / 3), selectWord("WHO ?", "QUI ?"));
super.addButton(WIDTH_WINDOW / 2, HEIGHT_WINDOW / (16 / 5), null, HEIGHT_WINDOW / 8, 'enemyBot');
}
}

@ -1,12 +0,0 @@
class Attack {
constructor() {
}
do(robot) {
if (robot.haveTarget() && robot.isTargetInRange()) {
return robot.attackTarget();
}
return false;
}
}

@ -0,0 +1,27 @@
class AddAttack extends AddNode {
constructor(father, game, selected) {
super(father, game, selected);
}
create() {
console.log("ATTACK");
super.create(this);
super.addTitle(WIDTH_WINDOW / 2, HEIGHT_WINDOW / 16, selectWord("ADD NODE : ATTACK", "AJOUTER ACTION : ATTAQUE"));
super.addTitle(WIDTH_WINDOW / 2, HEIGHT_WINDOW / (16 / 3), selectWord("WHO ?", "QUI ?"));
super.addTitle(WIDTH_WINDOW / 2, HEIGHT_WINDOW / (16 / 7), selectWord("TARGET FILTERS (OPTIONAL)", "FILTRES CIBLES (FACULTATIF)"));
super.addButton(WIDTH_WINDOW / 2, HEIGHT_WINDOW / (16 / 5), null, HEIGHT_WINDOW / 8, 'enemyBot', super.newCategory('target', true, true), false);
let c2 = super.newCategory('range', true, true);
super.addButton(WIDTH_WINDOW / 3, HEIGHT_WINDOW / (16 / 9), null, HEIGHT_WINDOW / 8, 'shortRange', c2, 1 / 3);
super.addButton(WIDTH_WINDOW / 1.5, HEIGHT_WINDOW / (16 / 9), null, HEIGHT_WINDOW / 8, 'mediumRange', c2, 2 / 3);
super.addButton(WIDTH_WINDOW / 2, HEIGHT_WINDOW / (16 / 12), null, HEIGHT_WINDOW / 8, 'longRange', c2, 1);
}
addNode() {
if (super.verifyCategory()) {
this.selected.addRect(new RectangleNode(this.selected.getX(), this.selected.getY() + 200, this.gameR, 'attack', this.lCategory[1].getValue()));
super.cancel();
}
}
}

@ -21,7 +21,6 @@ class AddCondition extends AddNode {
addNode() { addNode() {
if (super.verifyCategory()) { if (super.verifyCategory()) {
console.log(this.lCategory[0].getValue());
this.selected.addRect(new RectangleNode(this.selected.getX(), this.selected.getY() + 200, this.gameR, 'condition', this.lCategory[0].getValue(), true, false, this.lCategory[1].getValue(), 0)); this.selected.addRect(new RectangleNode(this.selected.getX(), this.selected.getY() + 200, this.gameR, 'condition', this.lCategory[0].getValue(), true, false, this.lCategory[1].getValue(), 0));
super.cancel(); super.cancel();
} }

@ -6,13 +6,19 @@ class AddMove extends AddNode {
create() { create() {
console.log("MOVE"); console.log("MOVE");
super.create(this); super.create(this);
let c1 = new Category('direction', true);
super.addTitle(WIDTH_WINDOW / 2, HEIGHT_WINDOW / 16, selectWord("ADD NODE : MOVE", "AJOUTER ACTION : DEPLACEMENT")); super.addTitle(WIDTH_WINDOW / 2, HEIGHT_WINDOW / 16, selectWord("ADD NODE : MOVE", "AJOUTER ACTION : DEPLACEMENT"));
super.addTitle(WIDTH_WINDOW / 4, HEIGHT_WINDOW / (16 / 3), selectWord("FLEE OR MOVE ?", "RECULER OU AVANCER ?")); super.addTitle(WIDTH_WINDOW / 4, HEIGHT_WINDOW / (16 / 3), selectWord("FLEE OR MOVE ?", "RECULER OU AVANCER ?"));
super.addButton(WIDTH_WINDOW / 6, HEIGHT_WINDOW / (16 / 5), null, HEIGHT_WINDOW / 8, 'fleeFrom', c1); let c1 = super.newCategory('direction', true, true);
super.addButton(WIDTH_WINDOW / 3, HEIGHT_WINDOW / (16 / 5), null, HEIGHT_WINDOW / 8, 'moveToward', c1); super.addButton(WIDTH_WINDOW / 6, HEIGHT_WINDOW / (16 / 5), null, HEIGHT_WINDOW / 8, 'fleeFrom', c1, false);
super.addButton(WIDTH_WINDOW / 3, HEIGHT_WINDOW / (16 / 5), null, HEIGHT_WINDOW / 8, 'moveToward', c1, true);
super.addTitle(WIDTH_WINDOW / 4 * 3, HEIGHT_WINDOW / (16 / 3), selectWord("WHO ?", "QUI ?")); super.addTitle(WIDTH_WINDOW / 4 * 3, HEIGHT_WINDOW / (16 / 3), selectWord("WHO ?", "QUI ?"));
super.addButton(WIDTH_WINDOW / 4 * 3, HEIGHT_WINDOW / (16 / 5), null, HEIGHT_WINDOW / 8, 'enemyBot'); super.addButton(WIDTH_WINDOW / 4 * 3, HEIGHT_WINDOW / (16 / 5), null, HEIGHT_WINDOW / 8, 'enemyBot', super.newCategory('target', true, true), false);
} }
addNode() {
if (super.verifyCategory()) {
this.selected.addRect(new RectangleNode(this.selected.getX(), this.selected.getY() + 200, this.gameR, 'move', this.lCategory[0].getValue()));
super.cancel();
}
}
} }

@ -0,0 +1,21 @@
class Attack {
constructor(percentRange = 1) {
if (percentRange > 1 / 3) {
if (percentRange > 2 / 3) {
percentRange = 1;
} else {
percentRange = 2 / 3;
}
} else {
percentRange = 1 / 3;
}
this.percentRange = percentRange;
}
do(robot) {
if (robot.haveTarget() && robot.isTargetInRange(this.percentRange)) {
return robot.attackTarget();
}
return false;
}
}

@ -42,14 +42,18 @@ class Condition {
if (this.myself) { if (this.myself) {
return true; return true;
} }
return robot.calcDistance(robot.target) <= this.range; if (robot.haveTarget())
return robot.calcDistance(robot.target) <= this.range;
return false;
} }
shieldCondition(robot) { shieldCondition(robot) {
if (this.myself) { if (this.myself) {
return this.verifyShield(robot); return this.verifyShield(robot);
} else { } else {
return this.verifyShield(robot.target); if (robot.haveTarget())
return this.verifyShield(robot.target);
return false;
} }
} }

@ -20,18 +20,19 @@ class Game extends Phaser.Scene {
this.tree = new RectangleNode(WIDTH_WINDOW / 1.5, 100, this, 'waria'); this.tree = new RectangleNode(WIDTH_WINDOW / 1.5, 100, this, 'waria');
this.tree.addRect(new RectangleNode(WIDTH_WINDOW / 1.2, 400, this, 'move', true)) this.tree.addRect(new RectangleNode(WIDTH_WINDOW / 1.2, 400, this, 'move', true))
this.tree.addRect(new RectangleNode(WIDTH_WINDOW / 1.5, 400, this, 'attack')); this.tree.addRect(new RectangleNode(WIDTH_WINDOW / 1.5, 400, this, 'attack', 1 / 3));
let robot = new Robot(WIDTH_MAP * 0.1, WIDTH_MAP * 0.1, WIDTH_MAP * 0.9, WIDTH_MAP * 0.9, 0x6666ff, this.gm, 'myself');
let condition = new RectangleNode(WIDTH_WINDOW / 1.7, 400, this, 'condition', true, true, false, 1 / 3, 0); let condition = new RectangleNode(WIDTH_WINDOW / 1.7, 400, this, 'condition', true, true, false, 1 / 3, 0);
condition.addRect(new RectangleNode(WIDTH_WINDOW / 1.2, 600, this, 'move', false)); condition.addRect(new RectangleNode(WIDTH_WINDOW / 1.2, 600, this, 'move', false));
condition.addRect(new RectangleNode(WIDTH_WINDOW / 1.5, 600, this, 'attack')) condition.addRect(new RectangleNode(WIDTH_WINDOW / 1.5, 600, this, 'attack'))
this.tree.addRect(condition); this.tree.addRect(condition);
this.gm.addRobot(robot); this.gm.addRobot(new Robot(WIDTH_MAP * 0.1, WIDTH_MAP * 0.1, WIDTH_MAP * 0.9, WIDTH_MAP * 0.9, 0x6666ff, this.gm, 'myself'));
this.gm.addRobot(new Robot(WIDTH_MAP * 0.1, WIDTH_MAP * 0.1, WIDTH_MAP * 0.2, WIDTH_MAP * 0.1, 0xff0000, this.gm)); this.gm.addRobot(new Robot(WIDTH_MAP * 0.1, WIDTH_MAP * 0.1, WIDTH_MAP * 0.2, WIDTH_MAP * 0.1, 0xff0000, this.gm));
this.gm.addRobot(new Robot(WIDTH_MAP * 0.1, WIDTH_MAP * 0.1, WIDTH_MAP * 0.1, WIDTH_MAP * 0.9, 0xff0000, this.gm)); this.gm.addRobot(new Robot(WIDTH_MAP * 0.1, WIDTH_MAP * 0.1, WIDTH_MAP * 0.1, WIDTH_MAP * 0.9, 0xff0000, this.gm));
this.gm.listRobot[0].setSpeed(3);
} }
update(time, delta) { update(time, delta) {
@ -40,7 +41,7 @@ class Game extends Phaser.Scene {
} }
OK() { clickNode() {
this.pencil.setVisible(false); this.pencil.setVisible(false);
this.bin.setVisible(false); this.bin.setVisible(false);
this.plus.setVisible(false); this.plus.setVisible(false);
@ -121,7 +122,7 @@ class Game extends Phaser.Scene {
this.bin.on('pointerdown', () => this.clickBin()); this.bin.on('pointerdown', () => this.clickBin());
this.plus.on('pointerdown', () => this.clickPlus()); this.plus.on('pointerdown', () => this.clickPlus());
this.input.on('pointerdown', () => this.OK()); this.input.on('pointerdown', () => this.clickNode());
this.input.on('drag', this.doDrag); this.input.on('drag', this.doDrag);
this.input.on('dragstart', () => this.pauseScene(play)); this.input.on('dragstart', () => this.pauseScene(play));
} }

@ -4,8 +4,6 @@ class PlusNode extends Phaser.Scene {
this.father = father; this.father = father;
this.gameR = game; this.gameR = game;
this.selected = selected; this.selected = selected;
console.log(this.gameR);
} }
create() { create() {

@ -3,9 +3,11 @@ class RectangleNode {
switch (type.toString().toLowerCase()) { switch (type.toString().toLowerCase()) {
case 'attack': case 'attack':
this.rect = new Phaser.GameObjects.Image(scene, x, y, 'attackNode'); this.rect = new Phaser.GameObjects.Image(scene, x, y, 'attackNode');
this.node = new Attack(); this.node = new Attack(option[0]);
this.canAddNode = false; this.canAddNode = false;
this.line = scene.add.graphics(); this.line = scene.add.graphics();
console.log(this.node.percentRange * 3);
this.rect.setFrame(this.node.percentRange * 3 - 1);
break; break;
case 'move' : case 'move' :
this.rect = new Phaser.GameObjects.Image(scene, x, y, 'moveNode'); this.rect = new Phaser.GameObjects.Image(scene, x, y, 'moveNode');

@ -1,5 +1,6 @@
class Robot { class Robot {
constructor(height, width, posX, posY, color, scene, name = 'enemy') { constructor(height, width, posX, posY, color, scene, name = 'enemy', speed = 1) {
this.speed = speed;
this.name = name; this.name = name;
this.height = height; this.height = height;
this.width = width; this.width = width;
@ -29,7 +30,16 @@ class Robot {
addScene(scene) { addScene(scene) {
this.scene = scene; this.scene = scene;
this.circle = this.scene.add.circle(this.x, this.y, this.width / 2, this.color); this.circle = this.scene.add.circle(this.x, this.y, this.width / 2, this.color).setInteractive();
this.circle.on('pointerdown', () => this.click());
}
click() {
if (this.circleRange === null) {
this.drawRange();
} else {
this.eraseRange();
}
} }
addShield(shield) { addShield(shield) {
@ -66,8 +76,13 @@ class Robot {
let diffX = this.target.x - this.x; let diffX = this.target.x - this.x;
let diffY = this.target.y - this.y; let diffY = this.target.y - this.y;
let hypot = Math.hypot(diffX, diffY); let hypot = Math.hypot(diffX, diffY);
this.velocityX = diffX / hypot * WIDTH_MAP / 1000 * SPEED; this.velocityX = diffX / hypot * WIDTH_MAP / 1000 * SPEED * this.speed;
this.velocityY = diffY / hypot * WIDTH_MAP / 1000 * SPEED; this.velocityY = diffY / hypot * WIDTH_MAP / 1000 * SPEED * this.speed;
}
setSpeed(speed) {
this.speed = speed;
this.updateTarget();
} }
advanceToTarget() { advanceToTarget() {
@ -166,9 +181,9 @@ class Robot {
return this.die(); return this.die();
} }
isTargetInRange() { isTargetInRange(percentRange = 1) {
if (this.verifyTarget()) { if (this.verifyTarget()) {
return this.calcDistance(this.target) < this.range; return this.calcDistance(this.target) < this.range * percentRange;
} }
return false; return false;
} }
@ -183,6 +198,8 @@ class Robot {
die() { die() {
if (this.life.value === 0) { if (this.life.value === 0) {
if (this.circleRange !== null)
this.circleRange.destroy();
this.circle.destroy(); this.circle.destroy();
this.shield.destroy(); this.shield.destroy();
this.life.destroy(); this.life.destroy();
@ -213,21 +230,37 @@ class Robot {
this.drawCircleRange(); this.drawCircleRange();
} }
eraseRange() {
this.circleRange.clear();
this.circleRange = null;
}
drawCircleRange() { drawCircleRange() {
if (this.circleRange !== null) { if (this.circleRange !== null) {
this.circleRange.clear(); this.circleRange.clear();
let color = 0xffff00;
let color = 0x008000;
let thickness = 4; let thickness = 4;
let alpha = 1; let alpha = 1;
this.circleRange.lineStyle(thickness, color, alpha); this.circleRange.lineStyle(thickness, color, alpha);
let a = new Phaser.Geom.Point(this.x, this.y);
let radius = this.range; let radius = this.range;
this.circleRange.strokeCircle(this.x, this.y, radius);
this.circleRange.strokeCircle(a.x, a.y, radius); color = 0xff7f00;
this.circleRange.lineStyle(thickness, color, alpha);
radius = this.range * 2 / 3;
this.circleRange.strokeCircle(this.x, this.y, radius);
color = 0xff0000;
this.circleRange.lineStyle(thickness, color, alpha);
radius = this.range / 3;
this.circleRange.strokeCircle(this.x, this.y, radius);
} }
} }
cleanNodes() { cleanNodes() {
this.lNode = []; this.lNode = [];
} }

@ -12,7 +12,6 @@ class AddNode extends Phaser.Scene {
this.add.rectangle(0, 0, WIDTH_WINDOW, HEIGHT_WINDOW, 0x000000).setOrigin(0, 0).setAlpha(0.5); this.add.rectangle(0, 0, WIDTH_WINDOW, HEIGHT_WINDOW, 0x000000).setOrigin(0, 0).setAlpha(0.5);
this.add.rectangle(0, HEIGHT_WINDOW / 2, WIDTH_WINDOW, height, 0x35363A).setOrigin(0, 0.5); this.add.rectangle(0, HEIGHT_WINDOW / 2, WIDTH_WINDOW, height, 0x35363A).setOrigin(0, 0.5);
this.createButtonCancel(); this.createButtonCancel();
console.log(son);
this.createButtonAdd(son); this.createButtonAdd(son);
} }
Loading…
Cancel
Save