Я начинаю разработку игр с MelonJS и не понимаю, как создать Pushable / Pullable Entity.
Я почти уверен, что подход, который я выбрал, неправильный, так как он не может обнаружить столкновение с элементами столкновения для остановки элемента.
// this function is called by the engine, when
// an object is touched by something (here collected)
onCollision: function (response, other) {
// // do something when collected
console.log(response, me.collision.types);
switch (response.a.body.collisionType) {
case me.collision.types.PLAYER_OBJECT:
if (response.overlapV.x > -0) {
console.log("pushed right");
this.body.force = {
x: this.body.maxVel.x,
y: 0
};
} else if (response.overlapV.x < -0) {
console.log("pushed left");
this.body.force = {
x: -this.body.maxVel.x,
y: 0
};
} else if (response.overlapV.y > -0) {
console.log("pushed down");
this.body.force = {
x: 0,
y: this.body.maxVel.y
};
} else if (response.overlapV.y < -0) {
this.body.force = {
x: 0,
y: -this.body.maxVel.y
};
console.log("pushed up");
// response.b.body.force.y = 0;
// response.b.body.force.x = -this.body.maxVel.y;
} else {
this.body.force = {
x: 0,
y: 0
};
}
this.body.update();
return false;
default:
return false;
}
}