Turtle Adventure
About this app
Join the Turtle on an exciting adventure!
Turtle Adventure Score: 0
Related apps
Put this on your site
Source
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>Turtle Adventure</title>
<meta name="description" content="Join the Turtle on an exciting adventure!">
<meta name="keywords" content="turtle, adventure, game">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<link href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Roboto:400,700" rel="stylesheet">
<style>
body {
font-family: 'Roboto', sans-serif;
background-color: #1abc9c;
margin: 0;
padding: 0;
}
#main-container {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
#game-container {
width: 600px;
height: 400px;
background-color: #ffffff;
border-radius: 10px;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
.turtle {
width: 50px;
height: 50px;
background-color: #16a085;
border-radius: 50%;
position: absolute;
bottom: 0;
left: 0;
transition: 0.2s ease-in-out;
}
.obstacle {
width: 50px;
height: 50px;
background-color: #c0392b;
border-radius: 50%;
position: absolute;
top: 0;
right: 0;
transition: 0.2s ease-in-out;
}
.score {
color: #ffffff;
font-size: 24px;
margin-bottom: 20px;
}
</style>
</head>
<body>
<div id="main-container">
<div id="game-container">
<div class="turtle"></div>
<div class="obstacle"></div>
<div class="score">Score: 0</div>
</div>
</div>
<script type="text/javascript">
try {
document.addEventListener("DOMContentLoaded", function() {
const turtle = document.querySelector(".turtle");
const obstacle = document.querySelector(".obstacle");
const score = document.querySelector(".score");
let gameScore = 0;
let gameSpeed = 10;
let obstacleInterval;
function jump() {
if (!turtle.classList.contains("jump")) {
turtle.classList.add("jump");
setTimeout(function() {
turtle.classList.remove("jump");
}, 500);
}
}
function startGame() {
gameScore = 0;
turtle.style.bottom = "0px";
obstacle.style.top = "0px";
score.textContent = "Score: " + gameScore;
obstacleInterval = setInterval(function() {
const turtleBottom = parseInt(window.getComputedStyle(turtle).getPropertyValue("bottom"));
const obstacleTop = parseInt(window.getComputedStyle(obstacle).getPropertyValue("top"));
if (turtleBottom <= 50 && obstacleTop <= 100 && obstacleTop >= 0) {
clearInterval(obstacleInterval);
alert("Game Over! Your Score: " + gameScore);
startGame();
}
gameScore++;
score.textContent = "Score: " + gameScore;
gameSpeed += 0.05;
obstacle.style.transition = `top ${gameSpeed}s linear`;
turtle.style.transition = `bottom ${gameSpeed}s linear`;
const randomHeight = Math.floor(Math.random() * 150);
obstacle.style.top = randomHeight + "px";
}, 2000);
}
document.addEventListener("keydown", function(event) {
if (event.code === "Space") {
jump();
}
});
startGame();
});
} catch (error) {
throw error;
}
</script>
</body>
</html>
NEW APPS
These are apps made by the community!