|
<!DOCTYPE html> |
|
<html lang="en"> |
|
<head> |
|
<meta charset="UTF-8"> |
|
<meta name="viewport" content="width=device-width, initial-scale=1.0"> |
|
<title>Futuristic Ball Game</title> |
|
<link rel="stylesheet" href="style.css"> |
|
</head> |
|
<body> |
|
<div class="game-container"> |
|
<div id="score">Score: 0</div> |
|
<div id="level">Level: 1</div> |
|
<div id="lives">Lives: ❤️ ❤️ ❤️ ❤️</div> |
|
<div class="platform"></div> |
|
</div> |
|
|
|
<script> |
|
let score = 0; |
|
let level = 1; |
|
let lives = 4; |
|
|
|
const scoreElement = document.getElementById('score'); |
|
const levelElement = document.getElementById('level'); |
|
const livesElement = document.getElementById('lives'); |
|
|
|
|
|
function createBall() { |
|
const ball = document.createElement('div'); |
|
ball.classList.add('ball'); |
|
|
|
|
|
ball.style.left = `${Math.random() * (window.innerWidth - 30)}px`; |
|
document.body.appendChild(ball); |
|
|
|
let ballFallInterval = setInterval(() => { |
|
const ballRect = ball.getBoundingClientRect(); |
|
const platformRect = document.querySelector('.platform').getBoundingClientRect(); |
|
|
|
|
|
if ( |
|
ballRect.bottom >= platformRect.top && |
|
ballRect.left >= platformRect.left && |
|
ballRect.right <= platformRect.right |
|
) { |
|
score += 10; |
|
scoreElement.textContent = `Score: ${score}`; |
|
ball.remove(); |
|
clearInterval(ballFallInterval); |
|
createBall(); |
|
} else if (ballRect.top > window.innerHeight) { |
|
lives -= 1; |
|
livesElement.innerHTML = `Lives: ${'❤️ '.repeat(lives)}`; |
|
ball.remove(); |
|
clearInterval(ballFallInterval); |
|
createBall(); |
|
if (lives === 0) { |
|
alert('Game Over!'); |
|
} |
|
} |
|
}, 20); |
|
|
|
return ball; |
|
} |
|
|
|
|
|
createBall(); |
|
|
|
|
|
const platform = |