如何在重力作用下弹跳球?

时间:2019-12-26 03:16:03

标签: javascript jquery

我一直在尝试用重力在帆布上弹跳一个球。每次球击中侧壁或底壁时,x和y的速度应降低。由于球只是从墙壁上掉下来,因此以下代码无法正常工作。

return (
      <div>
        <h3>Openning Hours</h3>
        {clinic.properties.ALL_OPENING_HOURS.map(({day_string,opening_hours}) => (
          <p key={Math.random()*10000}>
            <div>{day_string}</div>
            <div>{opening_hours.join(',  ')}</div>
          </p>
        ))}
      </div>
    );

}

{{1}}

如果您有解决方案,请告诉我。

1 个答案:

答案 0 :(得分:0)

经过反复试验,我终于找到了这部分代码的答案:

Ball.prototype.checkCollison =function () {
    if(this.x <= 0 ) {

        if(this.xSpeed <0)
            this.xSpeed++;
        this.xSpeed = -this.xSpeed;
        this.x=1;

    }
    else if( this.x >= 200) {
        if(this.xSpeed > 0)
            this.xSpeed--;
        this.xSpeed = -this.xSpeed;
        this.x--;

    }

    else if(  this.y >= 200) {
        if(this.ySpeed >0)
            this.ySpeed--;
        this.ySpeed = -this.ySpeed;
        this.y--;
    }
    else if(this.y<=0) {
        this.ySpeed=-this.ySpeed;



    }
};

尽管谢谢大家的帮助,但我也很感谢。