-
Notifications
You must be signed in to change notification settings - Fork 679
Add: 127 - Flower Garden Game #1940
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
Merged
+394
−1
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
f2f39f3
Create index.html
ktungl b50d9ad
Create README.md
ktungl 8beffef
Add files via upload
ktungl 7821a16
Delete 127 - Flower Garden Game directory
ktungl 2f3f604
Create index.html
ktungl 4415f87
Create README.md
ktungl f5b12a0
Add: Project screenshot for Flower Garden Game
ktungl 9a5ea8e
Create .gitkeep
ktungl a9b9fb8
Add files via upload
ktungl 5d85c7f
Update: Add Flower Garden Game to data.json
ktungl f238556
Delete projects/flower-garden-game/Screenshot/.gitkeep
ktungl 426dc0b
Delete projects/flower-garden-game/Screenshot directory
ktungl b0a8044
Add: Separate CSS file
ktungl 16debd4
Refactor: Separate HTML, CSS and JS files
ktungl ddddb05
Create Add: Separate JavaScript file
ktungl 4ccead6
Rename Add: Separate JavaScript file to script.js
ktungl d69dd49
Rename 127.png.png to 127.png
ktungl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
## 🌸 Flower Garden Game | ||
|
||
### Description | ||
An interactive flower planting game where players race against time to plant as many flowers as possible while avoiding mushrooms. Built with vanilla JavaScript and HTML5 Canvas. | ||
|
||
### Features | ||
- ⏱️ 60-second countdown timer | ||
- ❤️ Lives system (3 hearts) | ||
- 🍄 Randomly spawning mushrooms as obstacles | ||
- 🌼 Multiple colorful flower varieties | ||
- 🎮 Real-time score tracking | ||
- 🔄 Restart functionality | ||
- 📱 Responsive design | ||
|
||
### How to Play | ||
- Click anywhere on the canvas to plant a flower (+1 point) | ||
- Avoid clicking on mushrooms (-1 life) | ||
- Try to get the highest score within 60 seconds! | ||
|
||
### Technologies | ||
- HTML5 | ||
- CSS3 | ||
- Vanilla JavaScript | ||
- Canvas API | ||
|
||
### Screenshots | ||
 | ||
|
||
--- | ||
|
||
**Note:** This is a JavaScript adaptation of my original Python game, showcasing canvas manipulation, event handling, and game logic implementation. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Flower Garden Game</title> | ||
<link rel="stylesheet" href="style.css"> | ||
</head> | ||
<body> | ||
<div class="game-container"> | ||
<h1>🌸 Flower Garden Game 🌸</h1> | ||
<p class="instructions"> | ||
Plant as many flowers as you can within 60 seconds!<br> | ||
<strong>Avoid the mushrooms</strong> - clicking them costs a life! ❤️ | ||
</p> | ||
|
||
<div class="game-info"> | ||
<div class="info-item"> | ||
🌼 Score: <span id="score">0</span> | ||
</div> | ||
<div class="info-item hearts"> | ||
❤️ Lives: <span id="lives">3</span> | ||
</div> | ||
<div class="info-item"> | ||
⏱️ Time: <span id="time">60</span>s | ||
</div> | ||
</div> | ||
|
||
<canvas id="gameCanvas" width="400" height="400"></canvas> | ||
|
||
<div id="gameOverScreen" class="game-over"> | ||
<div id="finalMessage">Time's Up!</div> | ||
<div style="font-size: 18px; margin-top: 10px;"> | ||
Final Score: <span id="finalScore">0</span> | ||
</div> | ||
<button class="restart-btn" onclick="restartGame()">Play Again</button> | ||
</div> | ||
</div> | ||
|
||
<script src="script.js"></script> | ||
</body> | ||
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,219 @@ | ||
const canvas = document.getElementById('gameCanvas'); | ||
const ctx = canvas.getContext('2d'); | ||
|
||
// Game state | ||
let score = 0; | ||
let lives = 3; | ||
let timeRemaining = 60; | ||
let gameOver = false; | ||
let mushrooms = []; | ||
let flowers = []; | ||
let character = { x: 200, y: 200, size: 10 }; | ||
|
||
// Colors | ||
const flowerColors = ['#FF6B6B', '#4ECDC4', '#45B7D1', '#FFA07A', '#98D8C8', '#F7DC6F', '#BB8FCE']; | ||
const mushroomColors = { cap: '#E74C3C', stem: '#F5DEB3' }; | ||
|
||
// Initialize mushrooms | ||
function initMushrooms() { | ||
mushrooms = []; | ||
for (let i = 0; i < 5; i++) { | ||
mushrooms.push({ | ||
x: Math.random() * (canvas.width - 60) + 30, | ||
y: Math.random() * (canvas.height - 60) + 30 | ||
}); | ||
} | ||
} | ||
|
||
// Draw mushroom | ||
function drawMushroom(x, y) { | ||
// Cap | ||
ctx.fillStyle = mushroomColors.cap; | ||
ctx.beginPath(); | ||
ctx.ellipse(x, y - 10, 15, 15, 0, 0, Math.PI * 2); | ||
ctx.fill(); | ||
|
||
// White spots | ||
ctx.fillStyle = 'white'; | ||
ctx.beginPath(); | ||
ctx.arc(x - 5, y - 12, 3, 0, Math.PI * 2); | ||
ctx.arc(x + 5, y - 8, 2, 0, Math.PI * 2); | ||
ctx.fill(); | ||
|
||
// Stem | ||
ctx.fillStyle = mushroomColors.stem; | ||
ctx.fillRect(x - 5, y, 10, 20); | ||
} | ||
|
||
// Draw flower | ||
function drawFlower(x, y) { | ||
const color = flowerColors[Math.floor(Math.random() * flowerColors.length)]; | ||
|
||
// Petals | ||
ctx.fillStyle = color; | ||
for (let i = 0; i < 8; i++) { | ||
const angle = (Math.PI * 2 * i) / 8; | ||
const petalX = x + Math.cos(angle) * 8; | ||
const petalY = y + Math.sin(angle) * 8; | ||
ctx.beginPath(); | ||
ctx.arc(petalX, petalY, 5, 0, Math.PI * 2); | ||
ctx.fill(); | ||
} | ||
|
||
// Center | ||
ctx.fillStyle = '#FFD700'; | ||
ctx.beginPath(); | ||
ctx.arc(x, y, 4, 0, Math.PI * 2); | ||
ctx.fill(); | ||
|
||
// Stem | ||
ctx.strokeStyle = '#2E7D32'; | ||
ctx.lineWidth = 2; | ||
ctx.beginPath(); | ||
ctx.moveTo(x, y); | ||
ctx.lineTo(x, y + 15); | ||
ctx.stroke(); | ||
} | ||
|
||
// Draw character | ||
function drawCharacter() { | ||
ctx.fillStyle = '#3498db'; | ||
ctx.beginPath(); | ||
ctx.arc(character.x, character.y, character.size / 2, 0, Math.PI * 2); | ||
ctx.fill(); | ||
|
||
// Outline | ||
ctx.strokeStyle = '#2980b9'; | ||
ctx.lineWidth = 2; | ||
ctx.stroke(); | ||
} | ||
|
||
// Check collision between character and mushroom | ||
function checkCollision(mouseX, mouseY, mushroom) { | ||
const distance = Math.sqrt( | ||
Math.pow(mouseX - mushroom.x, 2) + | ||
Math.pow(mouseY - mushroom.y, 2) | ||
); | ||
return distance < 20; // Collision radius | ||
} | ||
|
||
// Draw everything | ||
function draw() { | ||
// Clear canvas | ||
ctx.clearRect(0, 0, canvas.width, canvas.height); | ||
|
||
// Draw flowers | ||
flowers.forEach(flower => { | ||
drawFlower(flower.x, flower.y); | ||
}); | ||
|
||
// Draw mushrooms | ||
mushrooms.forEach(mushroom => { | ||
drawMushroom(mushroom.x, mushroom.y); | ||
}); | ||
|
||
// Draw character | ||
drawCharacter(); | ||
} | ||
|
||
// Update UI | ||
function updateUI() { | ||
document.getElementById('score').textContent = score; | ||
document.getElementById('lives').textContent = lives; | ||
document.getElementById('time').textContent = timeRemaining; | ||
} | ||
|
||
// Handle click | ||
canvas.addEventListener('click', (e) => { | ||
if (gameOver) return; | ||
|
||
const rect = canvas.getBoundingClientRect(); | ||
const x = e.clientX - rect.left; | ||
const y = e.clientY - rect.top; | ||
|
||
// Move character | ||
character.x = x; | ||
character.y = y; | ||
|
||
// Check mushroom collision | ||
let hitMushroom = false; | ||
mushrooms = mushrooms.filter(mushroom => { | ||
if (checkCollision(x, y, mushroom)) { | ||
lives--; | ||
updateUI(); | ||
hitMushroom = true; | ||
|
||
if (lives <= 0) { | ||
endGame('Game Over! 💀'); | ||
} | ||
return false; | ||
} | ||
return true; | ||
}); | ||
|
||
// If didn't hit mushroom, plant flower | ||
if (!hitMushroom) { | ||
flowers.push({ x, y }); | ||
score++; | ||
updateUI(); | ||
} | ||
|
||
// Respawn mushrooms | ||
if (mushrooms.length < 5) { | ||
mushrooms.push({ | ||
x: Math.random() * (canvas.width - 60) + 30, | ||
y: Math.random() * (canvas.height - 60) + 30 | ||
}); | ||
} | ||
|
||
draw(); | ||
}); | ||
|
||
// Timer | ||
function startTimer() { | ||
const timer = setInterval(() => { | ||
if (gameOver) { | ||
clearInterval(timer); | ||
return; | ||
} | ||
|
||
timeRemaining--; | ||
updateUI(); | ||
|
||
if (timeRemaining <= 0) { | ||
clearInterval(timer); | ||
endGame("Time's Up! ⏰"); | ||
} | ||
}, 1000); | ||
} | ||
|
||
// End game | ||
function endGame(message) { | ||
gameOver = true; | ||
document.getElementById('finalMessage').textContent = message; | ||
document.getElementById('finalScore').textContent = score; | ||
document.getElementById('gameOverScreen').style.display = 'block'; | ||
} | ||
|
||
// Restart game | ||
function restartGame() { | ||
score = 0; | ||
lives = 3; | ||
timeRemaining = 60; | ||
gameOver = false; | ||
flowers = []; | ||
character = { x: 200, y: 200, size: 10 }; | ||
|
||
document.getElementById('gameOverScreen').style.display = 'none'; | ||
|
||
initMushrooms(); | ||
updateUI(); | ||
draw(); | ||
startTimer(); | ||
} | ||
|
||
// Initialize game | ||
initMushrooms(); | ||
draw(); | ||
updateUI(); | ||
startTimer(); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.