これが私のjavascriptゲームのテーマです-
ボールが X、Y パドルのオフセットに触れると、動きが止まるはずです。現在の軸はそのために知られているべきだと思いますが、どういうわけか私は方法を見つけることができません. より現実的なものにするのを手伝ってください。
これは私の描画機能です-
function draw() {
ctx.clearRect(0,0,300,300);
ctx.rect(mouseX-40,mouseY-20,40,20,true);
ctx.fillStyle = 'black';
ctx.fill();
ctx.beginPath();
ctx.arc(x,y,10,0,2*Math.PI,true);
ctx.closePath();
ctx.fill();
x+=dx;
y+=dy;
bounce();
}
私がここに置く条件-
function bounce(){
if(x+dx>300||x+dx<0)
dx=-dx;
if(y+dy>300||y+dy<0)
dy=-dy;
}