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

[New game]: Flying Fish #5013

Closed
wants to merge 3 commits into from
Closed
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
28 changes: 28 additions & 0 deletions Games/Flying_Fish/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# *Game_Name*
Flying Fish

---

<br>

## *Description 📃*
Flying Fish is an exhilarating game where players guide a fish through airborne obstacles using precise taps. Collect power-ups and avoid hazards to achieve the highest score.

## *Functionalities 🎮*

1. Click the "Start Game" button to begin.
2. Guide the fish through airborne obstacles.
3. Collect power-ups and avoid hazards.
4. Monitor the score and remaining lives.
5. When all lives are lost, the game ends, showing your final score and a button to restart the game.

1. Controls: Use the spacebar to make the fish jump.
2. Scoring: Each power-up collected increases your score by 10 points.
3. Difficulty: As the game progresses, obstacles become more frequent and move faster.
4. Timer: Players start with 3 lives. Hitting an obstacle deducts a life.
5. Game Over: When all lives are lost, the final score is displayed with an option to play again.

<br>

## *Screenshots 📸*
![Flying_Fish](https://github.com/user-attachments/assets/5c9b2456-8929-4448-8b52-a35a68ab4a2c)
19 changes: 19 additions & 0 deletions Games/Flying_Fish/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Flying Fish</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<div class="game-container">
<div id="game">
<div id="fish"></div>
<div id="score">Score: 0</div>
</div>
<button id="startButton">Start Game</button>
</div>
<script src="script.js"></script>
</body>
</html>
85 changes: 85 additions & 0 deletions Games/Flying_Fish/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
const fish = document.getElementById('fish');
const game = document.getElementById('game');
const scoreDisplay = document.getElementById('score');
const startButton = document.getElementById('startButton');

let fishTop = fish.offsetTop;
let fishLeft = fish.offsetLeft;
let gameHeight = game.clientHeight;
let gameWidth = game.clientWidth;
let score = 0;
let gameInterval;
let isGameRunning = false;

startButton.addEventListener('click', startGame);

function startGame() {
isGameRunning = true;
score = 0;
scoreDisplay.textContent = 'Score: ' + score;
fishTop = gameHeight / 2;
fishLeft = 50;
fish.style.top = fishTop + 'px';
fish.style.left = fishLeft + 'px';
startButton.style.display = 'none';
gameInterval = setInterval(gameLoop, 20);
document.addEventListener('keydown', controlFish);
}

function gameLoop() {
if (!isGameRunning) return;

// Gravity
fishTop += 2;
fish.style.top = fishTop + 'px';

// Check for collision with bottom of the game area
if (fishTop > gameHeight - fish.clientHeight) {
endGame();
}

// Increase score
score++;
scoreDisplay.textContent = 'Score: ' + score;
}

function controlFish(event) {
switch (event.code) {
case 'ArrowUp':
fishTop -= 20;
if (fishTop < 0) {
fishTop = 0;
}
fish.style.top = fishTop + 'px';
break;
case 'ArrowDown':
fishTop += 20;
if (fishTop > gameHeight - fish.clientHeight) {
fishTop = gameHeight - fish.clientHeight;
}
fish.style.top = fishTop + 'px';
break;
case 'ArrowLeft':
fishLeft -= 20;
if (fishLeft < 0) {
fishLeft = 0;
}
fish.style.left = fishLeft + 'px';
break;
case 'ArrowRight':
fishLeft += 20;
if (fishLeft > gameWidth - fish.clientWidth) {
fishLeft = gameWidth - fish.clientWidth;
}
fish.style.left = fishLeft + 'px';
break;
}
}

function endGame() {
isGameRunning = false;
clearInterval(gameInterval);
document.removeEventListener('keydown', controlFish);
startButton.textContent = 'Restart Game';
startButton.style.display = 'block';
}
56 changes: 56 additions & 0 deletions Games/Flying_Fish/styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
body {
margin: 0;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
background-color: #000;
color: #0ff;
font-family: 'Courier New', Courier, monospace;
}

.game-container {
text-align: center;
}

#game {
position: relative;
width: 300px;
height: 500px;
border: 2px solid #0ff;
overflow: hidden;
background-color: #111;
}

#fish {
position: absolute;
width: 30px;
height: 30px;
background-color: #0ff;
border-radius: 50%;
top: 50%;
left: 50px;
transform: translateY(-50%);
}

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

#startButton {
margin-top: 20px;
padding: 10px 20px;
background-color: #0ff;
border: none;
color: #000;
font-size: 16px;
cursor: pointer;
border-radius: 5px;
}

#startButton:hover {
background-color: #0aa;
}
Binary file added assets/images/Flying_Fish.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading