|
@@ -104,8 +104,7 @@ export default {
|
|
|
this.ctx = this.canvasMap.ctx
|
|
|
|
|
|
// define init position of the item
|
|
|
- this.pos.x = this.ray/2 + Math.random()*(this.canvas.width - this.ray)
|
|
|
- this.pos.y = this.ray/2 + Math.random()*(this.canvas.height - this.ray)
|
|
|
+ this.pos = this.getRandomPos();
|
|
|
|
|
|
// MATTER
|
|
|
// create the matter body and add it to the engine
|
|
@@ -147,6 +146,12 @@ export default {
|
|
|
Matter.Events.on(this.matterEngine, "beforeUpdate", this.onBeforeEngineUpdate)
|
|
|
Matter.Events.on(this.matterEngine, "afterUpdate", this.onAfterEngineUpdate);
|
|
|
},
|
|
|
+ getRandomPos(){
|
|
|
+ return {
|
|
|
+ x: this.ray/2 + Math.random()*(this.canvas.width - this.ray),
|
|
|
+ y: this.ray/2 + Math.random()*(this.canvas.height - this.ray)
|
|
|
+ };
|
|
|
+ },
|
|
|
parsePoints (){
|
|
|
// converts data (menace/maintien, actuel/future, prise) into atcual position x,y
|
|
|
for (let i = 0; i < this.entites.length; i++) {
|
|
@@ -187,7 +192,7 @@ export default {
|
|
|
getSalientPoints () {
|
|
|
// debugger
|
|
|
// console.log(this.entites);
|
|
|
- let arc = 360/12;
|
|
|
+ let arc = 360/10;
|
|
|
// loop through arcs
|
|
|
for (let i = 0; i <= 360/arc; i++) {
|
|
|
// loop through entities to find the farest on the arc
|
|
@@ -197,8 +202,8 @@ export default {
|
|
|
let entite = this.entites[j];
|
|
|
if(arc*i <= entite.display.alpha && entite.display.alpha <= arc*i+arc) {
|
|
|
// if entity is in arc
|
|
|
- if (entite.display.ray > max_r) {
|
|
|
- // if entity is farest from precedent one
|
|
|
+ if (entite.display.ray > max_r) { // && entite.display.ray > this.ray/2 // and farest from minimu
|
|
|
+ // if entity is farest from precedent one
|
|
|
max_r = entite.display.ray;
|
|
|
farest = entite;
|
|
|
}
|
|
@@ -277,6 +282,14 @@ export default {
|
|
|
}
|
|
|
},
|
|
|
onAfterEngineUpdate (event) {
|
|
|
+ // respawn element if outside screen
|
|
|
+ if(this.pos.x < 0
|
|
|
+ || this.pos.x > this.canvas.width
|
|
|
+ || this.pos.y < 0
|
|
|
+ || this.pos.y > this.canvas.height){
|
|
|
+ this.pos = this.getRandomPos()
|
|
|
+ Matter.Body.setPosition(this.body, {x:this.pos.x, y:this.pos.y});
|
|
|
+ }
|
|
|
this.draw()
|
|
|
},
|
|
|
draw() {
|