You know Dino Jump Game?
Here is the code: <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>Dino Jump Game</title>
<style>
body {
margin: 0;
background: #f7f7f7;
font-family: sans-serif;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
#game {
width: 600px;
height: 200px;
background-color: #eee;
overflow: hidden;
position: relative;
border: 2px solid #444;
}
#dino {
width: 40px;
height: 40px;
background: #444;
position: absolute;
bottom: 0;
left: 50px;
}
#obstacle {
width: 30px;
height: 30px;
background: red;
position: absolute;
bottom: 0;
left: 600px;
animation: moveObstacle 2s linear infinite;
}
@keyframes moveObstacle {
0% { left: 600px; }
100% { left: -30px; }
}
.jump {
animation: jump 0.5s ease-out;
}
@keyframes jump {
0% { bottom: 0; }
50% { bottom: 80px; }
100% { bottom: 0; }
}
#message {
position: absolute;
top: 10px;
left: 10px;
font-size: 18px;
color: #333;
}
</style>
</head>
<body>
<div id="game">
<div id="dino"></div>
<div id="obstacle"></div>
<div id="message">Press Space to Jump!</div>
</div>
<script>
const dino = document.getElementById("dino");
const obstacle = document.getElementById("obstacle");
const message = document.getElementById("message");
document.addEventListener("keydown", function(event) {
if (event.code === "Space" && !dino.classList.contains("jump")) {
dino.classList.add("jump");
setTimeout(() => dino.classList.remove("jump"), 500);
}
});
setInterval(function() {
const dinoTop = parseInt(window.getComputedStyle(dino).getPropertyValue("top"));
const obstacleLeft = parseInt(window.getComputedStyle(obstacle).getPropertyValue("left"));
if (obstacleLeft < 90 && obstacleLeft > 50 && dinoTop >= 140) {
message.textContent = "💥 Game Over!";
obstacle.style.animation = "none";
obstacle.style.left = obstacleLeft + "px";
}
}, 10);
</script>
</body>
</html>


