!DOCTYPE HTML
!DOCTYPE HTML
DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Simple Racing Game</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #e0e0e0;
margin: 0;
padding: 0;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
.game-container {
position: relative;
width: 300px;
height: 500px;
background-color: #2e2e2e;
border: 2px solid #333;
overflow: hidden;
}
.car {
position: absolute;
width: 40px;
height: 80px;
background-color: #ff5733;
bottom: 0;
left: 50%;
margin-left: -20px; /* Center the car */
}
.obstacle {
position: absolute;
width: 40px;
height: 40px;
background-color: #444;
top: -40px;
left: 50%;
margin-left: -20px; /* Center the obstacle */
}
#score {
position: absolute;
top: 10px;
left: 10px;
color: white;
font-size: 20px;
}
#gameOver {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
font-size: 30px;
color: red;
display: none;
}
</style>
</head>
<body>
<script>
const gameContainer = document.getElementById("gameContainer");
const car = document.getElementById("car");
const scoreElement = document.getElementById("score");
const gameOverElement = document.getElementById("gameOver");
// Game loop
function gameLoop() {
if (gameOver) return;
moveObstacles();
updateScore();
requestAnimationFrame(gameLoop);
}
</body>
</html>