-
Notifications
You must be signed in to change notification settings - Fork 839
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5126 from Ishitamukherjee2004/main
Drop Dash Game is added
- Loading branch information
Showing
7 changed files
with
257 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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,18 @@ | ||
# **Drop_Dash_Game** | ||
|
||
--- | ||
|
||
**Tech Stack** | ||
1. HTML | ||
2. CSS | ||
3. Javascript | ||
|
||
|
||
<br> | ||
|
||
## **Screenshots 📸** | ||
|
||
<br> | ||
![images](https://github.com/user-attachments/assets/d9ca8651-1661-4860-bc04-7bc1a67a7ac9) | ||
|
||
<br> |
This file contains 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,22 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Water Drop Catcher</title> | ||
<link rel="stylesheet" href="style.css"> | ||
</head> | ||
<body> | ||
<div class="game-container"> | ||
<canvas id="gameCanvas"></canvas> | ||
<div id="score">Score: 0</div> | ||
<div id="lives">Lives: 5</div> | ||
<div id="gameOver" class="hidden"> | ||
<h2>Game Over</h2> | ||
<p>Your Score: <span id="finalScore"></span></p> | ||
<button id="continueBtn">Continue</button> | ||
</div> | ||
</div> | ||
<script src="script.js"></script> | ||
</body> | ||
</html> |
This file contains 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,137 @@ | ||
const canvas = document.getElementById('gameCanvas'); | ||
const ctx = canvas.getContext('2d'); | ||
const scoreElement = document.getElementById('score'); | ||
const livesElement = document.getElementById('lives'); | ||
const gameOverElement = document.getElementById('gameOver'); | ||
const finalScoreElement = document.getElementById('finalScore'); | ||
const continueBtn = document.getElementById('continueBtn'); | ||
|
||
canvas.width = 400; | ||
canvas.height = 600; | ||
|
||
let cloud = { | ||
x: canvas.width / 2, | ||
y: canvas.height - 50, | ||
width: 80, | ||
height: 50, | ||
speed: 10 | ||
}; | ||
|
||
let drops = []; | ||
let score = 0; | ||
let lives = 6; | ||
let gameLoop; | ||
|
||
function drawCloud() { | ||
ctx.fillStyle = '#fff'; | ||
ctx.beginPath(); | ||
ctx.arc(cloud.x, cloud.y, 25, 0, Math.PI * 2); | ||
ctx.arc(cloud.x - 25, cloud.y, 20, 0, Math.PI * 2); | ||
ctx.arc(cloud.x + 25, cloud.y, 20, 0, Math.PI * 2); | ||
ctx.fill(); | ||
} | ||
|
||
function drawDrop(drop) { | ||
ctx.fillStyle = '#00f'; | ||
ctx.beginPath(); | ||
ctx.arc(drop.x, drop.y, 5, 0, Math.PI * 2); | ||
ctx.fill(); | ||
} | ||
|
||
function createDrop() { | ||
return { | ||
x: Math.random() * canvas.width, | ||
y: 0, | ||
speed: Math.random() * 1 + .5 | ||
}; | ||
} | ||
|
||
function update() { | ||
ctx.clearRect(0, 0, canvas.width, canvas.height); | ||
|
||
drawCloud(); | ||
|
||
if (Math.random() < 0.01) { | ||
drops.push(createDrop()); | ||
} | ||
|
||
drops.forEach((drop, index) => { | ||
drop.y += drop.speed; | ||
drawDrop(drop); | ||
|
||
if (drop.y > canvas.height) { | ||
drops.splice(index, 1); | ||
lives--; | ||
updateLives(); | ||
if (lives === 0) { | ||
gameOver(); | ||
} | ||
} | ||
|
||
if ( | ||
drop.x > cloud.x - cloud.width / 2 && | ||
drop.x < cloud.x + cloud.width / 2 && | ||
drop.y > cloud.y - cloud.height / 2 && | ||
drop.y < cloud.y + cloud.height / 2 | ||
) { | ||
drops.splice(index, 1); | ||
score++; | ||
updateScore(); | ||
} | ||
}); | ||
|
||
if (score >= 10) { | ||
gameOver(); | ||
} | ||
|
||
gameLoop = requestAnimationFrame(update); | ||
} | ||
|
||
function updateScore() { | ||
scoreElement.textContent = `Score: ${score}`; | ||
} | ||
|
||
function updateLives() { | ||
livesElement.textContent = `Lives: ${lives}`; | ||
} | ||
|
||
function gameOver() { | ||
cancelAnimationFrame(gameLoop); | ||
gameOverElement.classList.remove('hidden'); | ||
finalScoreElement.textContent = score; | ||
} | ||
|
||
function resetGame() { | ||
score = 0; | ||
lives = 5; | ||
drops = []; | ||
updateScore(); | ||
updateLives(); | ||
gameOverElement.classList.add('hidden'); | ||
update(); | ||
} | ||
|
||
document.addEventListener('keydown', (e) => { | ||
if (e.key === 'ArrowLeft' && cloud.x > cloud.width / 2) { | ||
cloud.x -= cloud.speed; | ||
} else if (e.key === 'ArrowRight' && cloud.x < canvas.width - cloud.width / 2) { | ||
cloud.x += cloud.speed; | ||
} | ||
}); | ||
|
||
canvas.addEventListener('touchstart', (e) => { | ||
e.preventDefault(); | ||
const touch = e.touches[0]; | ||
const rect = canvas.getBoundingClientRect(); | ||
const touchX = touch.clientX - rect.left; | ||
|
||
if (touchX < canvas.width / 2) { | ||
cloud.x -= cloud.speed; | ||
} else { | ||
cloud.x += cloud.speed; | ||
} | ||
}); | ||
|
||
continueBtn.addEventListener('click', resetGame); | ||
|
||
resetGame(); |
This file contains 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,74 @@ | ||
body { | ||
margin: 0; | ||
padding: 0; | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
height: 100vh; | ||
background-color: #1a1a2e; | ||
font-family: 'Arial', sans-serif; | ||
color: #ffffff; | ||
} | ||
|
||
.game-container { | ||
position: relative; | ||
width: 400px; | ||
height: 600px; | ||
} | ||
|
||
canvas { | ||
border: 2px solid #16213e; | ||
border-radius: 10px; | ||
box-shadow: 0 0 20px rgba(0, 0, 0, 0.5); | ||
} | ||
|
||
#score, #lives { | ||
position: absolute; | ||
top: 10px; | ||
font-size: 20px; | ||
text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5); | ||
} | ||
|
||
#score { | ||
left: 10px; | ||
} | ||
|
||
#lives { | ||
right: 10px; | ||
} | ||
|
||
#gameOver { | ||
position: absolute; | ||
top: 50%; | ||
left: 50%; | ||
transform: translate(-50%, -50%); | ||
background-color: rgba(22, 33, 62, 0.9); | ||
padding: 20px; | ||
border-radius: 10px; | ||
text-align: center; | ||
box-shadow: 0 0 20px rgba(0, 0, 0, 0.5); | ||
} | ||
|
||
#gameOver h2 { | ||
margin-top: 0; | ||
color: #e94560; | ||
} | ||
|
||
#continueBtn { | ||
background-color: #e94560; | ||
color: #fff; | ||
border: none; | ||
padding: 10px 20px; | ||
font-size: 16px; | ||
cursor: pointer; | ||
border-radius: 5px; | ||
transition: background-color 0.3s; | ||
} | ||
|
||
#continueBtn:hover { | ||
background-color: #c13e54; | ||
} | ||
|
||
.hidden { | ||
display: none; | ||
} |
This file contains 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains 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