我正在尝试在JS中的图形之间添加碰撞,我已经对其进行了设置,以使图形与画布的边缘发生碰撞,但希望图形彼此碰撞。
这是与画布边缘碰撞的代码。
this.update = function()
{
if (this.x+this.radius > secondCanvas.width || this.x-this.radius < 0)
{
this.dx = -this.dx;
}
if (this.y+this.radius > secondCanvas.width || this.y-this.radius < 0)
{
this.dy = -this.dy;
}
this.x += this.dx;
this.y +=this.dy
this.draw();
}
这是图纸的代码
{
var radius = 30
var x = Math.random() * secondCanvas.width;
var y = Math.random() * secondCanvas.height;
var dx = Math.random() * 5;
var dy = Math.random() * 5;
circleArray.push(new Circle(x, y, dx, dy, radius))
}