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 new game: catch the falling stars #4653

Merged
merged 8 commits into from
Jul 5, 2024
Merged
Show file tree
Hide file tree
Changes from 6 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
Empty file.
15 changes: 15 additions & 0 deletions Games/Catch the falling Stars/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Catch the Falling Stars</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<div id="game-container">
<div id="basket"></div>
</div>
<script src="script.js"></script>
</body>
</html>
47 changes: 47 additions & 0 deletions Games/Catch the falling Stars/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
const gameContainer = document.getElementById('game-container');
const basket = document.getElementById('basket');
let score = 0;

document.addEventListener('mousemove', (event) => {
const basketX = event.clientX - (basket.offsetWidth / 2);
basket.style.left = `${basketX}px`;
});

function createStar() {
const star = document.createElement('div');
star.classList.add('star');
star.style.left = `${Math.random() * window.innerWidth}px`;
gameContainer.appendChild(star);
moveStar(star);
}

function moveStar(star) {
let starY = 0;
const fallInterval = setInterval(() => {
if (starY > window.innerHeight) {
clearInterval(fallInterval);
star.remove();
} else {
starY += 5;
star.style.top = `${starY}px`;
checkCollision(star);
}
}, 30);
}

function checkCollision(star) {
const basketRect = basket.getBoundingClientRect();
const starRect = star.getBoundingClientRect();
if (
starRect.bottom > basketRect.top &&
starRect.top < basketRect.bottom &&
starRect.right > basketRect.left &&
starRect.left < basketRect.right
) {
star.remove();
score += 10;
console.log(`Score: ${score}`);
}
}

setInterval(createStar, 1000);
33 changes: 33 additions & 0 deletions Games/Catch the falling Stars/styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
body {
margin: 0;
overflow: hidden;
background-color: #000;
}

#game-container {
position: relative;
width: 100vw;
height: 100vh;
background-color: #000;
overflow: hidden;
}

#basket {
position: absolute;
bottom: 20px;
left: 50%;
transform: translateX(-50%);
width: 100px;
height: 50px;
background-color: #fff;
border-radius: 10px;
}

.star {
position: absolute;
top: -20px;
width: 20px;
height: 20px;
background-color: yellow;
border-radius: 50%;
}
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,10 @@ This repository also provides one such platforms where contributers come over an
| [Modulo_Game](https://github.com/kunjgit/GameZone/tree/main/Games/Modulo_Game) |
| [Alien_Invasion](https://github.com/kunjgit/GameZone/tree/main/Games/Alien_Invasion) |
| [Drawing_App](https://github.com/kunjgit/GameZone/tree/main/Games/Drawing_app) |

| [Catch_the_falling_Stars](https://github.com/kunjgit/GameZone/tree/main/Games/Catch_the_falling_Stars) |


|[Town-Rise](https://github.com/kunjgit/GameZone/tree/main/Games/Town_Rise_Game)|
| [IKnowYou-Mind-Reading-Game](https://github.com/kunjgit/GameZone/tree/main/Games/IKnowYou-Mind-Reading-Game) |

Expand Down
Binary file added assets/Catch the Falling Stars.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.