Blob.prototype.borderCheck = function() {
var xStart = 0;
var xEnd = this.server.config.width;
var yStart = 0;
var yEnd = this.server.config.width;
if (this.isBoosting() && this.x <= xStart) {
this.setBoost(-this.getBoostAngle());
}
if (this.isBoosting() && this.x >= xEnd) {
this.setBoost(-this.getBoostAngle());
}
if (this.isBoosting() && this.y <= yStart) {
this.setBoost(-this.getBoostAngle());
}
if (this.isBoosting() && this.y >= yEnd) {
this.setBoost(-this.getBoostAngle());
}
this.x = Math.min(xEnd, Math.max(this.x, xStart));
this.y = Math.min(yEnd, Math.max(this.y, yStart));
};
答案 0 :(得分:0)
当我在过去编写类似程序时,我将速度向量存储为x和y分量。然后与垂直或水平壁碰撞就像否定正确的组件一样简单。