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 Game #4240

Merged
merged 6 commits into from
Jul 5, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
25 changes: 25 additions & 0 deletions Games/FruitCatcher/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# **FruitCatcher**

#### Description

"Fruit Catcher" is a simple and engaging game where players control a basket to catch falling fruits. The goal is to catch as many fruits as possible within a limited time, with the game getting progressively harder.

#### Functionality

- The game starts immediately upon loading.
- Players use the left and right arrow keys to move the basket.
- Fruits fall from the top of the screen at increasing speeds.
- Each fruit caught increases the player's score.
- The game ends when a fruit is missed.

#### How to Play

1. **Start the Game:** Open the `index.html` file in a web browser.
2. **Move the Basket:** Use the left (`←`) and right (`β†’`) arrow keys to move the basket.
3. **Catch Fruits:** Position the basket under the falling fruits to catch them.
4. **Score Points:** Each fruit caught increases your score by 1.
5. **End Game:** The game ends when the player decides to stop or refreshes the page. Your final score will be displayed.

Enjoy catching fruits and try to beat your high score!


18 changes: 18 additions & 0 deletions Games/FruitCatcher/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<!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="style.css">
</head>
<body>
<div id="game">
<div id="basket"></div>
<div id="stars-container"></div>
<div id="score">Score: 0</div>
<div id="game-over">Game Over</div>
</div>
<script src="script.js"></script>
</body>
</html>
70 changes: 70 additions & 0 deletions Games/FruitCatcher/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
const game = document.getElementById('game');
const basket = document.getElementById('basket');
const starsContainer = document.getElementById('stars-container');
const scoreDisplay = document.getElementById('score');
const gameOverDisplay = document.getElementById('game-over');

let score = 0;
let gameInterval;
let starFallInterval;
let starSpeed = 2;

document.addEventListener('keydown', moveBasket);

function moveBasket(event) {
const basketRect = basket.getBoundingClientRect();
if (event.key === 'ArrowLeft' && basketRect.left > 0) {
basket.style.left = basketRect.left - 20 + 'px';
}
if (event.key === 'ArrowRight' && basketRect.right < game.clientWidth) {
basket.style.left = basketRect.left + 20 + 'px';
}
}

function createStar() {
const star = document.createElement('div');
star.classList.add('star');
star.style.left = Math.random() * (game.clientWidth - 20) + 'px';
starsContainer.appendChild(star);
}

function fallStars() {
const stars = document.querySelectorAll('.star');
stars.forEach(star => {
const starRect = star.getBoundingClientRect();
if (starRect.top + starSpeed >= game.clientHeight) {
endGame();
} else if (checkCollision(basket, star)) {
star.remove();
score++;
scoreDisplay.textContent = 'Score: ' + score;
} else {
star.style.top = starRect.top + starSpeed + 'px';
}
});
if (Math.random() < 0.1) createStar();
}

function checkCollision(basket, star) {
const basketRect = basket.getBoundingClientRect();
const starRect = star.getBoundingClientRect();
return !(
basketRect.top > starRect.bottom ||
basketRect.right < starRect.left ||
basketRect.bottom < starRect.top ||
basketRect.left > starRect.right
);
}

function startGame() {
gameInterval = setInterval(fallStars, 20);
starFallInterval = setInterval(() => { starSpeed += 0.1; }, 1000);
}

function endGame() {
clearInterval(gameInterval);
clearInterval(starFallInterval);
gameOverDisplay.style.display = 'block';
}

startGame();
63 changes: 63 additions & 0 deletions Games/FruitCatcher/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
body {
margin: 0;
padding: 0;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
background-color: #282c34;
color: white;
font-family: Arial, sans-serif;
}

#game {
position: relative;
width: 80%;
height: 90vh;
border: 2px solid #fff;
overflow: hidden;
}

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

#stars-container {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}

.star {
position: absolute;
width: 20px;
height: 20px;
background-color: #fff;
border-radius: 50%;
}

#score {
position: absolute;
top: 10px;
left: 10px;
font-size: 20px;
}

#game-over {
display: none;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
font-size: 40px;
color: red;
}
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,8 @@ This repository also provides one such platforms where contributers come over an
|[AquaSort_Game](https://github.com/kunjgit/GameZone/tree/main/Games/AquaSort_Game) |
|[Turn_on_the_light](https://github.com/kunjgit/GameZone/tree/main/Games/Turn_on_the_light) |
| [Tic-Tac-Toe Game](https://github.com/kunjgit/GameZone/tree/main/Games/Tic-Tac-Toe) |
| [Rapid_click_frenzy](https://github.com/kunjgit/GameZone/tree/main/Games/Rapid_click_frenzy)
| [Rapid_click_frenzy](https://github.com/kunjgit/GameZone/tree/main/Games/Rapid_click_frenzy) |
VijaySamant4368 marked this conversation as resolved.
Show resolved Hide resolved
| [FruitCatcher](https://github.com/kunjgit/GameZone/tree/main/Games/FruitCatcher)



Expand Down
Binary file added assets/images/Screenshot 2024-06-03 195029.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading