matter: bigger walls, respawn, bug fix
This commit is contained in:
parent
d69c194cd3
commit
037aa83a21
@ -1323,14 +1323,19 @@ export default {
|
|||||||
|
|
||||||
console.log(`bringToCenter dist:${dist}, x_force:${x_force}, friction air:${fa}`);
|
console.log(`bringToCenter dist:${dist}, x_force:${x_force}, friction air:${fa}`);
|
||||||
} else { // in the ceneter zone let items floats freely
|
} else { // in the ceneter zone let items floats freely
|
||||||
|
let fa = 0.01;
|
||||||
let velocity = Matter.Body.getVelocity(this.body);
|
let velocity = Matter.Body.getVelocity(this.body);
|
||||||
let velocityx = Math.abs(velocity.x);
|
if (velocity.x) {
|
||||||
// map a range of numbers to another range of numbers
|
let velocityx = Math.abs(velocity.x);
|
||||||
// INFO https://stackoverflow.com/a/46462321
|
// map a range of numbers to another range of numbers
|
||||||
let velocity_range = [50, 1000];
|
// INFO https://stackoverflow.com/a/46462321
|
||||||
let fa_range = [0,3];
|
let velocity_range = [50, 1000];
|
||||||
let fa = fa_range[0] + (velocityx - velocity_range[0]) * (fa_range[1] - fa_range[0]) / (velocity_range[1] - velocity_range[0]);
|
let fa_range = [0,3];
|
||||||
console.log(`bringToCenter velocity.x:${velocity.x}, fa:${fa}`);
|
fa = fa_range[0] + (velocityx - velocity_range[0]) * (fa_range[1] - fa_range[0]) / (velocity_range[1] - velocity_range[0]);
|
||||||
|
console.log(`bringToCenter velocityx:${velocityx}, fa:${fa}, velocity`, velocity);
|
||||||
|
} else {
|
||||||
|
console.warn(`bringToCenter no velocity`, velocity);
|
||||||
|
}
|
||||||
|
|
||||||
this.body.frictionAir = fa;
|
this.body.frictionAir = fa;
|
||||||
}
|
}
|
||||||
@ -1354,6 +1359,8 @@ export default {
|
|||||||
let dist = dir < 0
|
let dist = dir < 0
|
||||||
? this.pos.x - pseudo_center_x
|
? this.pos.x - pseudo_center_x
|
||||||
: pseudo_center_x - this.pos.x;
|
: pseudo_center_x - this.pos.x;
|
||||||
|
|
||||||
|
dist = dist > 1000 ? 1000 : dist;
|
||||||
|
|
||||||
if (dist > this.canvas.width/6) { // apply decreasing forces and increasing friction air only out of center to let the items float in the center zone
|
if (dist > this.canvas.width/6) { // apply decreasing forces and increasing friction air only out of center to let the items float in the center zone
|
||||||
// max & min item position
|
// max & min item position
|
||||||
@ -1495,16 +1502,20 @@ export default {
|
|||||||
}
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
onAfterEngineUpdate (event) {
|
respawn() {
|
||||||
// respawn element if outside screen
|
// respawn element if outside screen
|
||||||
// if(this.pos.x <= 0
|
if(this.pos.x <= 0
|
||||||
// || this.pos.x >= this.canvas.width
|
|| this.pos.x >= this.canvas.width
|
||||||
// || this.pos.y <= 0
|
|| this.pos.y <= 0
|
||||||
// || this.pos.y >= this.canvas.height){
|
|| this.pos.y >= this.canvas.height){
|
||||||
// this.pos = this.getRandomPos()
|
this.pos = this.getRandomPos()
|
||||||
// Matter.Body.setPosition(this.body, {x:this.pos.x, y:this.pos.y});
|
Matter.Body.setPosition(this.body, {x:this.pos.x, y:this.pos.y});
|
||||||
// this.setInitBodyVelocity();
|
this.setInitBodyVelocity();
|
||||||
// }
|
}
|
||||||
|
|
||||||
|
},
|
||||||
|
onAfterEngineUpdate (event) {
|
||||||
|
this.respawn();
|
||||||
|
|
||||||
this.paper_main_object.position = this.pos = this.body.position;
|
this.paper_main_object.position = this.pos = this.body.position;
|
||||||
|
|
||||||
|
@ -100,7 +100,7 @@ export default {
|
|||||||
}.bind(this);
|
}.bind(this);
|
||||||
|
|
||||||
// MATTER
|
// MATTER
|
||||||
let wall_w = 100;
|
let wall_w = 1000;
|
||||||
Matter.Composite.add(this.world, [
|
Matter.Composite.add(this.world, [
|
||||||
// walls
|
// walls
|
||||||
Matter.Bodies.rectangle(canvas_w/2, -wall_w/2, canvas_w, wall_w, { isStatic: true }), // top
|
Matter.Bodies.rectangle(canvas_w/2, -wall_w/2, canvas_w, wall_w, { isStatic: true }), // top
|
||||||
|
Loading…
x
Reference in New Issue
Block a user