Skip to content

Commit 189bf40

Browse files
authored
Update script.js
1 parent ceb03e0 commit 189bf40

1 file changed

Lines changed: 125 additions & 2 deletions

File tree

‎script.js‎

Lines changed: 125 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const passwordError = document.getElementById('password-error');
1919
const nextWebsiteBtn = document.getElementById('next-website-btn');
2020

2121
let userName = ''; // No localStorage, reset on load
22-
let scores = JSON.parse(localStorage.getItem('scores')) || { tic: 0, rps: 0, memory: 0 }; // Keep scores in localStorage
22+
let scores = JSON.parse(localStorage.getItem('scores')) || { tic: 0, rps: 0, memory: 0, flappy: 0 }; // Added flappy score
2323

2424
const lovelyQuotes = [
2525
"Your smile lights up the world like a starry night.",
@@ -68,7 +68,7 @@ submitPasswordBtn.addEventListener('click', () => {
6868
});
6969

7070
nextWebsiteBtn.addEventListener('click', () => {
71-
window.location.href = 'https://www.youtube.com';
71+
window.location.href = 'https://devrutu143.github.io/https-devrutu243.github.io/';
7272
});
7373

7474
function showDashboard() {
@@ -97,15 +97,18 @@ const leaderboardBtn = document.getElementById('leaderboard-btn');
9797
const game1Btn = document.getElementById('game1-btn');
9898
const game2Btn = document.getElementById('game2-btn');
9999
const game3Btn = document.getElementById('game3-btn');
100+
const game4Btn = document.getElementById('game4-btn');
100101
const game1 = document.getElementById('game1');
101102
const game2 = document.getElementById('game2');
102103
const game3 = document.getElementById('game3');
104+
const game4 = document.getElementById('game4');
103105

104106
gamesBtn.addEventListener('click', () => showSection(gamesSection));
105107
leaderboardBtn.addEventListener('click', () => showSection(leaderboardSection));
106108
game1Btn.addEventListener('click', () => showSection(game1));
107109
game2Btn.addEventListener('click', () => showSection(game2));
108110
game3Btn.addEventListener('click', () => showSection(game3));
111+
game4Btn.addEventListener('click', () => showSection(game4));
109112

110113
const backBtns = document.querySelectorAll('.back-btn');
111114
backBtns.forEach(btn => {
@@ -119,6 +122,7 @@ function showSection(section) {
119122
game1.classList.add('hidden');
120123
game2.classList.add('hidden');
121124
game3.classList.add('hidden');
125+
game4.classList.add('hidden');
122126
passwordSection.classList.add('hidden');
123127
secretsSection.classList.add('hidden');
124128
section.classList.remove('hidden');
@@ -130,12 +134,15 @@ function loadLeaderboard() {
130134
<li>Tic-Tac-Toe Wins: ${scores.tic}</li>
131135
<li>Rock-Paper-Scissors Score: ${scores.rps}</li>
132136
<li>Memory Match Best Moves: ${scores.memory || 'N/A'}</li>
137+
<li>Flappy Rutu Best Score: ${scores.flappy || 'N/A'}</li>
133138
`;
134139
}
135140

136141
function updateScore(game, value) {
137142
if (game === 'memory') {
138143
if (!scores.memory || value < scores.memory) scores.memory = value;
144+
} else if (game === 'flappy') {
145+
if (!scores.flappy || value > scores.flappy) scores.flappy = value;
139146
} else {
140147
scores[game] += value;
141148
}
@@ -394,3 +401,119 @@ function handleCardClick(e) {
394401

395402
resetMemory.addEventListener('click', initMemory);
396403
initMemory();
404+
405+
// Game 4: Flappy Rutu
406+
const flappyCanvas = document.getElementById('flappy-canvas');
407+
const flappyScoreEl = document.getElementById('flappy-score');
408+
const flappyMessage = document.getElementById('flappy-message');
409+
const resetFlappy = document.getElementById('reset-flappy');
410+
const ctx = flappyCanvas ? flappyCanvas.getContext('2d') : null;
411+
412+
let bird = { x: 50, y: 150, vy: 0, gravity: 0.6, jump: -10, size: 20 };
413+
let pipes = [];
414+
let hearts = [];
415+
let flappyScore = 0;
416+
let flappyGameActive = false;
417+
let frameCount = 0;
418+
419+
function initFlappy() {
420+
flappyCanvas.width = 300;
421+
flappyCanvas.height = 400;
422+
bird = { x: 50, y: 150, vy: 0, gravity: 0.6, jump: -10, size: 20 };
423+
pipes = [];
424+
hearts = [];
425+
flappyScore = 0;
426+
flappyScoreEl.textContent = flappyScore;
427+
flappyMessage.classList.add('hidden');
428+
flappyGameActive = true;
429+
frameCount = 0;
430+
pipes.push({ x: flappyCanvas.width, gapY: Math.random() * 200 + 100 });
431+
if (!flappyCanvas.onclick) {
432+
flappyCanvas.onclick = () => {
433+
if (flappyGameActive) bird.vy = bird.jump;
434+
};
435+
}
436+
requestAnimationFrame(updateFlappy);
437+
}
438+
439+
function updateFlappy() {
440+
if (!flappyGameActive) return;
441+
442+
// Update bird
443+
bird.vy += bird.gravity;
444+
bird.y += bird.vy;
445+
if (bird.y + bird.size > flappyCanvas.height || bird.y < 0) {
446+
endFlappyGame();
447+
return;
448+
}
449+
450+
// Update pipes
451+
frameCount++;
452+
if (frameCount % 90 === 0) {
453+
pipes.push({ x: flappyCanvas.width, gapY: Math.random() * 200 + 100 });
454+
}
455+
pipes.forEach(pipe => {
456+
pipe.x -= 2;
457+
if (pipe.x + 50 < 0) pipes.shift();
458+
if (
459+
bird.x + bird.size > pipe.x && bird.x < pipe.x + 50 &&
460+
(bird.y < pipe.gapY - 70 || bird.y + bird.size > pipe.gapY + 70)
461+
) {
462+
endFlappyGame();
463+
return;
464+
}
465+
if (pipe.x + 50 < bird.x && !pipe.scored) {
466+
flappyScore++;
467+
flappyScoreEl.textContent = flappyScore;
468+
pipe.scored = true;
469+
}
470+
});
471+
472+
// Update hearts
473+
if (frameCount % 150 === 0) {
474+
hearts.push({ x: flappyCanvas.width, y: Math.random() * (flappyCanvas.height - 20) });
475+
}
476+
hearts.forEach(heart => {
477+
heart.x -= 2;
478+
if (
479+
bird.x + bird.size > heart.x && bird.x < heart.x + 15 &&
480+
bird.y + bird.size > heart.y && bird.y < heart.y + 15
481+
) {
482+
flappyScore += 5;
483+
flappyScoreEl.textContent = flappyScore;
484+
hearts.splice(hearts.indexOf(heart), 1);
485+
}
486+
});
487+
if (hearts.length > 0 && hearts[0].x < -15) hearts.shift();
488+
489+
// Draw
490+
ctx.clearRect(0, 0, flappyCanvas.width, flappyCanvas.height);
491+
// Draw bird
492+
ctx.fillStyle = '#ffca28';
493+
ctx.font = '20px Arial';
494+
ctx.fillText('😜', bird.x, bird.y);
495+
// Draw pipes
496+
ctx.fillStyle = '#7b1fa2';
497+
pipes.forEach(pipe => {
498+
ctx.fillRect(pipe.x, 0, 50, pipe.gapY - 70);
499+
ctx.fillRect(pipe.x, pipe.gapY + 70, 50, flappyCanvas.height - pipe.gapY - 70);
500+
});
501+
// Draw hearts
502+
ctx.fillStyle = '#e91e63';
503+
ctx.font = '15px Arial';
504+
hearts.forEach(heart => {
505+
ctx.fillText('💕', heart.x, heart.y);
506+
});
507+
508+
requestAnimationFrame(updateFlappy);
509+
}
510+
511+
function endFlappyGame() {
512+
flappyGameActive = false;
513+
flappyMessage.textContent = `Rutu crashed! Score: ${flappyScore} 🚀 Try again?`;
514+
flappyMessage.classList.remove('hidden');
515+
updateScore('flappy', flappyScore);
516+
}
517+
518+
resetFlappy.addEventListener('click', initFlappy);
519+
if (game4) initFlappy();

0 commit comments

Comments
 (0)