如何更改彈跳球的大小以使其每5次變小反彈,然後每5次反彈就恢復到正常尺寸。就我自己的項目而言,我剛開始學習關於HTML5的知識。如何更改彈跳球的大小,使其每5次反彈變小一次,然後每5次彈跳就恢復到正常大小
ball.x += xunits;
ball.y += yunits;
context.fillStyle = color;
context.beginPath();
context.arc(ball.x,ball.y,15,0,Math.PI*2,true);
context.closePath();
context.fill();
if (ball.x > theCanvas.width || ball.x < 0) {
angle = 180 - angle;
color = "red";
updateBall();
} else if (ball.y > theCanvas.height || ball.y < 0) {
angle = 360 - angle;
color = "blue";
updateBall();
}
}
function updateBall() {
radians = angle * Math.PI/ 180;
xunits = Math.cos(radians) * speed;
yunits = Math.sin(radians) * speed;
}
var speed = 5;
var p1 = {x:250,y:0};
var angle = 45;
var radians =0;
var xunits = 0;
var yunits = 0;
var color = "blue";
var ball = {x:p1.x, y:p1.y};
updateBall();
theCanvas = document.getElementById('canvasOne');
context = theCanvas.getContext('2d');
function gameLoop() {
window.setTimeout(gameLoop, 20);
drawScreen()
}
gameLoop();