-
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.
1 parent
4aaa759
commit ac0092d
Showing
15 changed files
with
214 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Fruit Cutting Game</title> | ||
<link rel="stylesheet" href="styles.css"> | ||
</head> | ||
<body> | ||
<div class="game-container"> | ||
<div class="knife"></div> | ||
<div id="score" style="text-align: center; color: aquamarine;font-size: 30px;margin-top: 30px;">0</div> | ||
</div> | ||
|
||
<audio id="backgroundMusic" loop> | ||
<source src="background.mp3" type="audio/mpeg"> | ||
Your browser does not support the audio element. | ||
</audio> | ||
|
||
<audio id="cutSound"> | ||
<source src="cut.mp3" type="audio/mpeg"> | ||
Your browser does not support the audio element. | ||
</audio> | ||
|
||
<div class="start-button" onclick="startGame()">Start Game</div> | ||
<div class="play-again" onclick="startNewGame()">Play Again</div> | ||
|
||
<script src="script.js"></script> | ||
</body> | ||
</html> |
Binary file not shown.
Binary file not shown.
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,120 @@ | ||
|
||
const fruits = [ | ||
'apple.png', | ||
'orange.png', | ||
'banana.png', | ||
'graphes.png', | ||
'papaya.png', | ||
'watermelon.png', | ||
'mango.png' | ||
|
||
]; | ||
|
||
let score = 0; | ||
let gameTime = 0; | ||
let gameRunning = false; | ||
let gameInterval; | ||
|
||
function startGame() { | ||
gameRunning = true; | ||
document.querySelector('.start-button').style.display = 'none'; // Hide start button | ||
const gameContainer = document.querySelector('.game-container'); | ||
gameContainer.addEventListener('mousemove', moveKnife); | ||
|
||
function moveKnife(event) { | ||
const knife = document.querySelector('.knife'); | ||
knife.style.left = event.clientX - knife.offsetWidth / 2 + 'px'; | ||
knife.style.top = event.clientY - knife.offsetHeight / 2 + 'px'; | ||
} | ||
|
||
function createFruit() { | ||
if (!gameRunning) return; | ||
|
||
const fruit = document.createElement('div'); | ||
fruit.classList.add('fruit'); | ||
const randomFruit = fruits[Math.floor(Math.random() * fruits.length)]; | ||
fruit.style.backgroundImage = `url('${randomFruit}')`; | ||
fruit.style.left = Math.random() * (window.innerWidth - 100) + 'px'; | ||
fruit.style.top = '0px'; | ||
gameContainer.appendChild(fruit); | ||
|
||
moveFruit(fruit); | ||
} | ||
|
||
gameInterval = setInterval(createFruit, 1000); | ||
setTimeout(endGame, 30000); | ||
setInterval(updateGameTime, 1000); | ||
|
||
document.getElementById('backgroundMusic').play(); // Start background music | ||
} | ||
|
||
function moveFruit(fruitElement) { | ||
let position = 0; | ||
const interval = setInterval(() => { | ||
if (!gameRunning) { | ||
clearInterval(interval); | ||
return; | ||
} | ||
|
||
position += 20; | ||
fruitElement.style.top = position + 'px'; | ||
|
||
const knife = document.querySelector('.knife'); | ||
if (knife && checkCollision(fruitElement, knife)) { | ||
fruitElement.style.backgroundImage = 'none'; | ||
fruitElement.style.backgroundColor = 'red'; | ||
fruitElement.style.borderRadius = '50%'; // Make it a small circle | ||
|
||
score++; | ||
document.getElementById('score').textContent = score; | ||
playCutSound(); // Play sound effect | ||
|
||
setTimeout(() => { | ||
fruitElement.remove(); | ||
}, 100); | ||
} | ||
|
||
if (position >= window.innerHeight) { | ||
fruitElement.remove(); | ||
} | ||
}, 20); | ||
} | ||
|
||
function playCutSound() { | ||
const cutSound = document.getElementById('cutSound'); | ||
cutSound.currentTime = 0; // Reset sound to start | ||
cutSound.play(); | ||
} | ||
|
||
function checkCollision(fruit, knife) { | ||
const fruitRect = fruit.getBoundingClientRect(); | ||
const knifeRect = knife.getBoundingClientRect(); | ||
|
||
return !( | ||
fruitRect.right < knifeRect.left || | ||
fruitRect.left > knifeRect.right || | ||
fruitRect.bottom < knifeRect.top || | ||
fruitRect.top > knifeRect.bottom | ||
); | ||
} | ||
|
||
function updateGameTime() { | ||
gameTime++; | ||
} | ||
|
||
function endGame() { | ||
gameRunning = false; | ||
clearInterval(gameInterval); | ||
document.getElementById('backgroundMusic').pause(); | ||
document.querySelector('.play-again').style.display = 'block'; | ||
alert(`Game Over! Your score: ${score} in ${gameTime} seconds.`); | ||
} | ||
|
||
function startNewGame() { | ||
score = 0; | ||
gameTime = 0; | ||
gameRunning = true; | ||
document.getElementById('score').textContent = score; | ||
document.querySelector('.play-again').style.display = 'none'; | ||
startGame(); | ||
} |
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,64 @@ | ||
body { | ||
margin: 10; | ||
overflow: hidden; | ||
font-family: Arial, sans-serif; | ||
background: url('https://ideogram.ai/assets/progressive-image/balanced/response/gbfrHHRRSAeEt7Si6GCOuw'); | ||
background-size: cover; | ||
background-repeat: no-repeat; | ||
} | ||
|
||
.game-container { | ||
position: relative; | ||
width: 100vw; | ||
height: 100vh; | ||
|
||
|
||
} | ||
|
||
.knife { | ||
position: absolute; | ||
width: 150px; | ||
height: 150px; | ||
background: url('knife.png') no-repeat center center; | ||
background-size: contain; | ||
pointer-events: none; | ||
} | ||
|
||
#scoreboard { | ||
position: absolute; | ||
top: 10px; | ||
left: 10px; | ||
font-size: 24px; | ||
} | ||
.fruit { | ||
width: 100px; | ||
height: 100px; | ||
background-size: cover; | ||
position: absolute; | ||
transition: background-color 0.3s ease-out; | ||
border-radius: 50%; | ||
} | ||
.play-again { | ||
position: fixed; | ||
top: 50%; | ||
left: 50%; | ||
transform: translate(-50%, -50%); | ||
padding: 10px 20px; | ||
background-color: #551363; | ||
color: white; | ||
font-size: 18px; | ||
cursor: pointer; | ||
display: none; | ||
} | ||
.start-button { | ||
position: fixed; | ||
top: 50%; | ||
left: 50%; | ||
transform: translate(-50%, -50%); | ||
padding: 20px 40px; | ||
background-color: #0f296b; | ||
color: white; | ||
font-size: 24px; | ||
cursor: pointer; | ||
display: block; | ||
} |