Texto
Texto
DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="styles.css">
<title>Jogo da Bola</title>
</head>
<body>
<div class="game-container">
<div class="ball"></div>
<div class="obstacle"></div>
<div class="score">Pontuação: <span id="score">0</span></div>
</div>
<script src="script.js"></script>
</body>
</html>
.game-container {
position: relative;
width: 400px;
height: 400px;
background-color: #ddd;
}
.ball {
position: absolute;
width: 30px;
height: 30px;
background-color: #3498db;
border-radius: 50%;
bottom: 0;
left: 50%;
transform: translateX(-50%);
transition: 0.2s ease-in-out;
}
.obstacle {
position: absolute;
width: 20px;
height: 100px;
background-color: #e74c3c;
bottom: 0;
left: 70%;
transform: translateX(-50%);
animation: moveObstacle 5s linear infinite;
}
.score {
position: absolute;
top: 10px;
right: 10px;
font-size: 18px;
}
@keyframes moveObstacle {
0% {
left: 100%;
}
100% {
left: -20px;
}
}
let score = 0;
let speed = 1;
function updateScore() {
score += 100;
scoreElement.textContent = score;
function checkCollision() {
const ballRect = ball.getBoundingClientRect();
const obstacleRect = obstacle.getBoundingClientRect();
function gameLoop() {
updateScore();
checkCollision();
requestAnimationFrame(gameLoop);
}
gameLoop();