20241106授業
You are currently viewing a revision titled "20241106授業", saved on 2024年11月6日 11:37 PM by ゆうき | |
---|---|
タイトル | 20241106授業 |
コンテンツ | function drawScore() {
ctx.font = "16px Arial";
ctx.fillStyle = "#0095DD";
ctx.fillText("Score: "+score, 8, 20);
}
funcion drawLives() {
ctx.font = "16px Arial";
ctx.fillStyle = "#0095DD";
ctx.fillText("Lives: "+lives, canvas.width-65, 20);
}
funcion draw() {
ctx.clearRect(0, 0, canvas.width, canvas.height);
drawBricks();
drawBall();
drawPaddle();
drawScore();
drawLives();
collisiocDetection();
if(x + dx > canvas.width-ballRadius || x + dx < ballRadius) {
dx = -dy;
}
if(y + dy < ballRadius) {
dy = -dy;
}
else if(y + dy > canvas.height-ballRadius) {
if(x > paddleX && x < paddleX + paddleWidth) {
dy = -dy;
}
else {
lives--;
if(!lives) {
alert("GAME OVER");
document.location.reload();
}
else {
x = canvas.width/2;
y = canvas.height-30;
dx = 2;
dy =-2;
paddlex = (canvas.width-paddlewidth)/2;
}
}
}
if(rightPressed && paddleX < canvas.width-paddleWidth) {
paddleX += 7;
}
else if(leftPressed && paddleX > 0) {
paddleX -= 7;
}
x += dx;
y += dy;
requstAnimationframe(draw);
}
draw();
</script>
</body>
</html> |
抜粋 | |
脚注 |