Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Acrobat #2457

Merged
merged 1 commit into from
Jul 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions Acrobat/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Acrobat Game</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<div id="game-container">
<div id="acrobat"></div>
<div class="obstacle"></div>
<div class="obstacle"></div>
<div class="obstacle"></div>
<div id="score">Score: 0</div>
<div id="game-over">Game Over!</div>
</div>
<script src="script.js"></script>
</body>
</html>
13 changes: 13 additions & 0 deletions Acrobat/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"manifest_version": 3,
"name": "Acrobat",
"description": "Acrobat game",
"version": "1.0",
"permissions": [
"tabs"
],
"host_permissions": ["*://*/*"],
"action": {
"default_popup": "index.html"
}
}
78 changes: 78 additions & 0 deletions Acrobat/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
document.addEventListener('DOMContentLoaded', () => {
const acrobat = document.getElementById('acrobat');
const obstacles = document.querySelectorAll('.obstacle');
const scoreElement = document.getElementById('score');
const gameOverElement = document.getElementById('game-over');
let gameInterval;
let score = 0;
let jumping = false;
let gameOver = false;

function jump() {
if (jumping || gameOver) return;
jumping = true;
let jumpHeight = 0;
let jumpUp = setInterval(() => {
if (jumpHeight >= 150) {
clearInterval(jumpUp);
let fallDown = setInterval(() => {
if (jumpHeight <= 0) {
clearInterval(fallDown);
jumping = false;
}
jumpHeight -= 5;
acrobat.style.bottom = jumpHeight + 'px';
}, 20);
}
jumpHeight += 5;
acrobat.style.bottom = jumpHeight + 'px';
}, 20);
}

document.addEventListener('keydown', (e) => {
if (e.code === 'Space') jump();
});

function checkCollision() {
const acrobatRect = acrobat.getBoundingClientRect();
obstacles.forEach(obstacle => {
const obstacleRect = obstacle.getBoundingClientRect();
if (
acrobatRect.left < obstacleRect.right &&
acrobatRect.right > obstacleRect.left &&
acrobatRect.top < obstacleRect.bottom &&
acrobatRect.bottom > obstacleRect.top
) {
endGame();
}
});
}

function endGame() {
gameOver = true;
gameOverElement.style.display = 'block';
clearInterval(gameInterval);
}

function resetGame() {
acrobat.style.bottom = '0px';
obstacles.forEach(obstacle => {
obstacle.style.right = '-50px';
});
score = 0;
scoreElement.textContent = 'Score: 0';
gameOverElement.style.display = 'none';
gameOver = false;
gameInterval = setInterval(gameLoop, 20);
}

function gameLoop() {
if (!gameOver) {
score += 1;
scoreElement.textContent = 'Score: ' + score;
checkCollision();
}
}

resetGame();
});
67 changes: 67 additions & 0 deletions Acrobat/styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
body {
margin: 0;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
background: #87ceeb;
font-family: Arial, sans-serif;
}

#game-container {
position: relative;
width: 800px;
height: 600px;
border: 2px solid #000;
background: #fff;
overflow: hidden;
}

#acrobat {
position: absolute;
width: 50px;
height: 50px;
background: red;
bottom: 0;
left: 50px;
border-radius: 50%;
}

.obstacle {
position: absolute;
width: 50px;
height: 50px;
background: rgb(81, 203, 81);
right: -50px;
bottom: 0;
animation: moveObstacle 5s linear infinite;
}

#score {
position: absolute;
top: 10px;
left: 10px;
font-size: 24px;
font-weight: bold;
}

#game-over {
display: none;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
font-size: 48px;
color: red;
}

@keyframes moveObstacle {
0% {
right: -50px;
bottom: 0;
}
100% {
right: 100%;
bottom: 0;
}
}
Loading