Ajout d'un visuel de dommage (les dégats reçu s'affiche pendant un court instant) - Ajout des sons pour les tirs et les dégats reçus - Ajout d'une page de fin (Gagner ou Perdu) - Ajout de la possibilité de retourner au menu ou de recommencer sur cette page de fin - Création des boutons, en Fr et en En, Home - Next - Retry - Le bouton Next est pour le moment inutilisable

master
clmaisonha 5 years ago
parent 4c8a6d4adc
commit bcd8e876a9

Binary file not shown.

After

Width:  |  Height:  |  Size: 27 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

Binary file not shown.

@ -1 +1 @@
function selectWord(e,t){switch(LANG){case"fr":return t;default:return e}}var LANG=navigator.language.substr(0,2).toLowerCase();const 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;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.add("Type",Type),father.scene.add("Game",new Game(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))}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");

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,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")}}
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")}}

@ -7,11 +7,20 @@ function selectWord(en, fr) {
}
}
function newGame(father) {
if (father.scene.getIndex('Game') !== -1) {
father.scene.remove('Game');
}
father.scene.add('Game', new Game(father));
}
var LANG = navigator.language.substr(0, 2).toLowerCase();
const MYSELF = 'myself';
const SHIELD_PER_SECOND = 5;
const COLOR_ATTACK = 0xff0000;
const COLOR_MOVE = 0x0000ff;
const COLOR_CONDITION = 0x0e0e0e;
const DURATION_DAMAGE = 700;
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;
@ -33,6 +42,4 @@ var config = {
let father = new Phaser.Game(config);
father.scene.add('Boot', new Boot(father));
father.scene.add('Type', Type);
father.scene.add('Game', new Game(father));
father.scene.start('Boot');

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

@ -24,12 +24,18 @@ class Boot extends Phaser.Scene {
progressBox.destroy();
});
this.load.audio('shot', 'assets/sounds/shot.ogg');
this.load.audio('hit', 'assets/sounds/hit.ogg');
this.loadImage('en', 'flags/', true);
this.loadImage('fr', 'flags/', true);
this.loadSprite('playLetter', 550, 150, 'buttons/');
this.loadSprite('cancel', 550, 150, 'buttons/');
this.loadSprite('add', 550, 150, 'buttons/');
this.loadSprite('home', 550, 150, 'buttons/');
this.loadSprite('next', 550, 150, 'buttons/');
this.loadSprite('retry', 550, 150, 'buttons/');
this.loadSprite('duel', 269, 262, 'buttons/');
this.loadSprite('last', 269, 262, 'buttons/');
@ -109,6 +115,7 @@ class Boot extends Phaser.Scene {
clickPlay(btn) {
btn.setFrame(2);
console.log("Play");
this.father.scene.add('Type', new Type(this.father));
this.scene.start('Type');
}

@ -5,7 +5,7 @@ class Game extends Phaser.Scene {
}
preload() {
this.gm = new GamingBoard();
this.gm = new GamingBoard(this);
this.father.scene.add('GamingBoard', this.gm);
}
@ -17,18 +17,19 @@ class Game extends Phaser.Scene {
this.scene.launch('GamingBoard');
this.scene.pause('GamingBoard');
let centerX = WIDTH_WINDOW / 4 * 3;
let diffX = WIDTH_WINDOW / 10;
this.tree = new RectangleNode(centerX, HEIGHT_WINDOW / 10, this, 'waria');
this.tree.addRect(new RectangleNode(centerX + diffX, HEIGHT_WINDOW / 3, this, 'move', true))
this.tree.addRect(new RectangleNode(centerX, HEIGHT_WINDOW / 3, this, 'attack', 1 / 3));
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.5, 400, this, 'attack', 1 / 3));
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.5, 600, this, 'attack'))
let condition = new RectangleNode(centerX - diffX, HEIGHT_WINDOW / 3, this, 'condition', true, true, false, 1 / 3, 0);
condition.addRect(new RectangleNode(centerX, HEIGHT_WINDOW / 1.5, this, 'move', false));
condition.addRect(new RectangleNode(centerX - diffX, HEIGHT_WINDOW / 1.5, this, 'attack'))
this.tree.addRect(condition);
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.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.1, WIDTH_MAP * 0.9, 0xff0000, this.gm));
@ -40,6 +41,21 @@ class Game extends Phaser.Scene {
this.tree.updateLine();
}
finish() {
console.log("FINISH");
let winner;
if (this.gm.winner()) {
winner = new Winner(this.father);
} else {
winner = new Looser(this.father);
}
this.father.scene.add('Finish', winner);
this.scene.pause('Game');
this.scene.launch('Finish');
}
clickNode() {
this.pencil.setVisible(false);
@ -67,15 +83,12 @@ class Game extends Phaser.Scene {
target.setY(dragY);
}
pauseScene(btn) {
this.line = 0;
this.scene.pause('GamingBoard');
this.changeFrame(btn, 0);
}
changeFrame(btn, bonus) {
btn.setFrame(this.line * 2 + bonus);
this.gm.pause();
}
resume() {
@ -88,7 +101,13 @@ class Game extends Phaser.Scene {
}
})
this.gm.modifyNodes(this.tree.getNodes());
this.scene.resume('GamingBoard');
this.gm.resume();
}
changeFrame(btn, bonus) {
btn.setFrame(this.line * 2 + bonus);
}
createButton() {

@ -1,7 +1,8 @@
class GamingBoard extends Phaser.Scene {
constructor() {
constructor(father) {
super('GamingBoard');
this.listRobot = [];
this.father = father;
}
preload() {
@ -9,6 +10,10 @@ class GamingBoard extends Phaser.Scene {
}
create() {
this.end = false;
this.sound.add('shot');
this.sound.add('hit');
this.add.image(0, 0, 'background').alpha = 0.1;
for (let i = 0; i < this.listRobot.length; i++) {
@ -41,9 +46,31 @@ class GamingBoard extends Phaser.Scene {
}
}
}
if (this.listRobot.length <= 1 && !this.end) {
this.end = true;
this.time.addEvent({delay: 1000, callback: this.finish, callbackScope: this});
}
}
finish() {
console.log("QUOI ?");
this.pause();
this.father.finish();
}
winner() {
return this.listRobot.length !== 0 && this.listRobot[0].name === 'myself';
}
pause() {
this.scene.pause('GamingBoard');
this.sound.pauseAll();
}
resume() {
this.scene.resume('GamingBoard');
this.sound.resumeAll();
}
addRobot(robot) {
@ -51,8 +78,14 @@ class GamingBoard extends Phaser.Scene {
}
modifyNodes(lNodes) {
this.listRobot[0].cleanNodes();
lNodes.forEach(element => this.listRobot[0].addNode(element));
for (let i = 0; i < this.listRobot.length; i++) {
if (this.listRobot[i].name === MYSELF) {
this.listRobot[i].cleanNodes();
lNodes.forEach(element => this.listRobot[0].addNode(element));
return true;
}
}
return false;
}
chooseTarget(robot) {

@ -0,0 +1,12 @@
class Looser extends Finish {
constructor(father) {
super(father);
}
create() {
super.create();
super.addTitle(selectWord("GAME OVER", "PARTIE PERDUE"));
super.btnRetry(super.createButton(WIDTH_WINDOW / 3, 'retry'));
super.btnHome(super.createButton(WIDTH_WINDOW / 1.5, 'home'));
}
}

@ -122,10 +122,10 @@ class Robot {
}
attackTarget() {
attackTarget(percentBonus = 0) {
if (this.verifyTarget() && this.target.isAlive() && this.isTargetInRange()) {
if (this.canAttack)
this.attack(this.target);
this.attack(this.target, percentBonus);
return true;
}
return false;
@ -142,27 +142,31 @@ class Robot {
return false;
}
attack(target) {
attack(target, percentBonus) {
this.canAttack = false;
this.missile.setPosition(this.x, this.y).setVisible(true);
this.missile.setRotation(Math.atan2(this.y - this.target.y, this.x - this.target.x) - 3.14 / 2);
this.scene.sound.play('shot');
let duration = this.calcDistance(this.target) * WIDTH_MAP / 1000;
this.scene.tweens.add({
targets: this.missile,
x: target.x,
y: target.y,
ease: 'Linear',
duration: 200,
onComplete: () => this.finishAttack(target)
duration: duration,
onComplete: () => this.finishAttack(target, percentBonus)
});
this.scene.time.addEvent({delay: Phaser.Math.Between(1000, 3000), callback: this.reload, callbackScope: this});
}
finishAttack(target) {
if (target.beAttack(this.damage)) {
finishAttack(target, percentBonus) {
if (target.beAttack(this.damage * percentBonus)) {
this.setTarget(null);
}
this.missile.setVisible(false);
@ -173,7 +177,24 @@ class Robot {
}
beAttack(damage) {
let diff = this.shield.decrease(damage)
let diff = this.shield.decrease(damage);
let style = {font: '40px stencil', fill: "#ffff00"};
let text = this.scene.add.text(this.x, this.y, damage.toString(), style).setOrigin(0, 1);
this.scene.tweens.add({
targets: text,
x: this.x + 30,
y: this.y - 50,
alpha: 0,
duration: DURATION_DAMAGE,
ease: 'Sine.easeOut',
onComplete: () => text.destroy()
})
this.scene.sound.play('hit');
console.log('HIT');
if (diff > 0) {
console.log("Shield Broken");
this.life.decrease(diff);
@ -242,18 +263,19 @@ class Robot {
let color = 0x008000;
let thickness = 4;
let alpha = 1;
let alpha = 1 / 3;
this.circleRange.lineStyle(thickness, color, alpha);
let radius = this.range;
this.circleRange.strokeCircle(this.x, this.y, radius);
color = 0xff7f00;
alpha = 2 / 3;
this.circleRange.lineStyle(thickness, color, alpha);
radius = this.range * 2 / 3;
this.circleRange.strokeCircle(this.x, this.y, radius);
color = 0xff0000;
alpha = 1;
this.circleRange.lineStyle(thickness, color, alpha);
radius = this.range / 3;
this.circleRange.strokeCircle(this.x, this.y, radius);

@ -1,6 +1,7 @@
class Type extends Phaser.Scene {
constructor() {
constructor(father) {
super('Type');
this.father = father;
}
preload() {
@ -35,6 +36,7 @@ class Type extends Phaser.Scene {
}
clickPlay(btn) {
newGame(this.father);
this.scene.start('Game');
}
}

@ -0,0 +1,13 @@
class Winner extends Finish {
constructor(father) {
super(father);
}
create() {
super.create();
super.addTitle(selectWord("WINNER", "GAGNER"));
super.btnRetry(super.createButton(WIDTH_WINDOW / 4, 'retry'));
super.btnHome(super.createButton(WIDTH_WINDOW / 2, 'home'));
super.btnNext(super.createButton(WIDTH_WINDOW / 4 * 3, 'next'));
}
}

@ -0,0 +1,64 @@
class Finish extends Phaser.Scene {
constructor(father) {
super('Finish');
this.father = father;
}
create() {
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_WINDOW / 2, 0x35363A).setOrigin(0, 0.5);
}
addTitle(title) {
let sizeText = HEIGHT_WINDOW / 6;
let style = {font: sizeText.toString() + 'px stencil', fill: "#e2e2e2"};
this.add.text(WIDTH_WINDOW / 2, HEIGHT_WINDOW / 2, title, style).setOrigin(0.5, 0.5);
}
createButton(x, texture) {
let btn = this.add.image(x, HEIGHT_WINDOW / 8 * 7, texture).setOrigin(0.5, 0.5).setInteractive();
btn.on('pointerover', () => btn.setFrame(1));
btn.on('pointerout', () => btn.setFrame(0));
btn.displayHeight = HEIGHT_WINDOW / 9;
btn.scaleX = btn.scaleY;
return btn;
}
btnRetry(btn) {
btn.on('pointerdown', () => this.retry());
}
retry() {
console.log("RETRY");
this.close();
newGame(this.father);
this.father.scene.start('Game');
}
btnHome(btn) {
btn.on('pointerdown', () => this.home());
}
home() {
console.log("HOME");
this.close();
this.father.scene.start('Type');
}
btnNext(btn) {
btn.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');
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 46 KiB

Loading…
Cancel
Save