-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
122 lines (99 loc) · 3.93 KB
/
Copy pathscript.js
File metadata and controls
122 lines (99 loc) · 3.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
"use strict";
// DOM Elements
const titleElement = document.querySelector(".title");
const buttonsContainer = document.querySelector(".buttons");
const yesButton = document.querySelector(".btn--yes");
const noButton = document.querySelector(".btn--no");
const catImg = document.querySelector(".cat-img");
// Audio Elements
const boomAudio = new Audio('boom.mp3'); // Sound when "No" is clicked
const valentineAudio = document.getElementById("valentine-music"); // Background music
const MAX_NO_CLICKS = 5; // Maximum "No" clicks before stopping interaction
let noClickCount = 0; // Tracks how many times "No" was clicked
let interactionsEnabled = true; // Controls whether further interactions are allowed
// Text and messages
const yesButtonTexts = ["Yes", "No", "Just kidding", "Okay", "Fine", "Alright fine."];
const noButtonMessages = [
"No",
"Are you sure?",
"Why not?",
"Don't do this to me >:(",
"Please...",
"I'll just cry in the corner."
];
// Functions
function updateYesButtonText() {
yesButton.textContent = yesButtonTexts[Math.min(noClickCount, yesButtonTexts.length - 1)];
}
function updateNoButtonText() {
noButton.textContent = noClickCount === 1 ? "Yes" : "No";
}
function updateTitleMessage() {
titleElement.textContent = noButtonMessages[Math.min(noClickCount, noButtonMessages.length - 1)];
}
function changeCatImage() {
const imageIndex = noClickCount <= MAX_NO_CLICKS ? noClickCount : MAX_NO_CLICKS;
catImg.src = `img/cat-${imageIndex}.jpg`;
}
function playBoomSound() {
boomAudio.currentTime = 0.2;
boomAudio.play(); // Play the boom sound when "No" is clicked
}
function resizeYesButton() {
const currentFontSize = parseFloat(window.getComputedStyle(yesButton).getPropertyValue("font-size"));
let newFontSize = currentFontSize * 1.4; // Default resize
// Special case: After the last "No" click, expand "Yes" button more
if (noClickCount === MAX_NO_CLICKS) {
newFontSize = currentFontSize * 0.8; // Increase size more when "Alright fine" is clicked
}
yesButton.style.fontSize = `${newFontSize}px`;
}
function playMusic(startTime, duration = null) {
if (valentineAudio) {
valentineAudio.currentTime = startTime;
valentineAudio.play().catch(err => console.error("Error playing music:", err));
// Optional duration to stop music only during specific actions
if (duration) {
setTimeout(() => valentineAudio.pause(), duration);
}
}
}
function randomizeNoButtonPosition() {
const randomX = Math.floor(Math.random() * (window.innerWidth - noButton.offsetWidth));
const randomY = Math.floor(Math.random() * (window.innerHeight - noButton.offsetHeight));
// Use transform to position the No button randomly
noButton.style.position = "absolute"; // Ensure the button is positioned absolutely
noButton.style.left = `${randomX}px`;
noButton.style.top = `${randomY}px`;
}
// Event Listeners
noButton.addEventListener("click", () => {
noClickCount++;
updateYesButtonText();
updateNoButtonText();
updateTitleMessage();
changeCatImage();
resizeYesButton();
playBoomSound(); // Always play the boom sound on every "No" click
// Play music for the first "No" click
if (noClickCount === 1) {
playMusic(0, 19780); // Play from 0 to 19.780 seconds
}
// After max "No" clicks, randomize "No" button position for subsequent clicks
if (noClickCount === MAX_NO_CLICKS) {
interactionsEnabled = false;
// No button doesn't randomize yet after the max "No"
}
// For subsequent clicks after max "No", randomize button position
if (noClickCount > MAX_NO_CLICKS) {
randomizeNoButtonPosition(); // Randomize position of the "No" button after the max "No"
}
});
yesButton.addEventListener("click", () => {
// Handles the "Yes" button click
titleElement.textContent = "Yayyy!! :3";
buttonsContainer.classList.add("hidden");
catImg.src = `img/cat-yes.jpg`; // Display the final "Yes" image
// Resume music from 19.75 seconds until the end
playMusic(19.75);
});