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)
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)))}}
|
@ -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];
|
||||||
|
}
|
||||||
|
}
|
@ -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;
|
Loading…
Reference in new issue