displaying fields labels
This commit is contained in:
@@ -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() {
|
||||
|
@@ -86,10 +86,13 @@ export default {
|
||||
let wall_w = 100;
|
||||
Matter.Composite.add(this.world, [
|
||||
// walls
|
||||
Matter.Bodies.rectangle(canvas_w/2, -wall_w/2, canvas_w, wall_w, { isStatic: true }), // top
|
||||
Matter.Bodies.rectangle(canvas_w/2, canvas_h+wall_w/2, canvas_w, wall_w, { isStatic: true }), // bottom
|
||||
Matter.Bodies.rectangle(-wall_w/2, canvas_h/2, wall_w, canvas_h, { isStatic: true }), // left
|
||||
Matter.Bodies.rectangle(canvas_w+wall_w/2, canvas_h/2, wall_w, canvas_h, { isStatic: true }) // right
|
||||
Matter.Bodies.rectangle(canvas_w/2, -wall_w/2, canvas_w, wall_w, { isStatic: true }), // top
|
||||
Matter.Bodies.rectangle(canvas_w/2, canvas_h+wall_w/2, canvas_w, wall_w, { isStatic: true }), // bottom
|
||||
Matter.Bodies.rectangle(-wall_w/2, canvas_h/2, wall_w, canvas_h, { isStatic: true }), // left
|
||||
Matter.Bodies.rectangle(canvas_w+wall_w/2, canvas_h/2, wall_w, canvas_h, { isStatic: true }), // right
|
||||
// make the items never goes under menus
|
||||
Matter.Bodies.rectangle(550, canvas_h-15, 900, 30, { isStatic: true }), // menu bottom
|
||||
Matter.Bodies.rectangle(550, 15, 900, 30, { isStatic: true }) // menu top
|
||||
]);
|
||||
|
||||
// add mouse control
|
||||
|
Reference in New Issue
Block a user