-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathlevel2.html
More file actions
247 lines (218 loc) · 9.75 KB
/
Copy pathlevel2.html
File metadata and controls
247 lines (218 loc) · 9.75 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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Waste Sorting Game - Level 2</title>
<style>
body {
font-family: 'Trebuchet MS', sans-serif;
background-image: url('Images/Level 2/background_image.jpg');
background-size: cover;
background-repeat: no-repeat;
margin: 0;
padding: 0;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
position: relative;
/* Needed for absolute positioning */
}
.waste-item {
width: 150px;
/* Adjust the size of the waste items */
height: 150px;
cursor: pointer;
position: absolute;
animation: pulse 1s infinite alternate;
/* Apply pulsing animation */
}
@keyframes pulse {
0% {
transform: scale(1);
}
100% {
transform: scale(1.1);
}
}
#recyclable-bin,
#non-recyclable-bin {
width: 200px;
/* Adjust the size of the bin images */
cursor: pointer;
position: fixed;
transform: translateY(-50%);
}
.logo {
width: 150px;
height: auto;
position: absolute;
top: 20px;
left: 20px;
}
#recyclable-bin {
top: 50%;
/* Adjust the position of the recyclable bin */
left: 55%;
/* Adjust the position of the recyclable bin */
}
#non-recyclable-bin {
top: 52%;
/* Adjust the position of the non-recyclable bin */
right: 17%;
/* Adjust the position of the non-recyclable bin */
}
.score-timer-container {
position: absolute;
top: 20px;
/* Adjust the position of the container */
right: 20px;
/* Adjust the position of the container */
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
font-size: 24px;
color: white;
background-color: rgba(0, 0, 0, 0.51);
padding: 10px 20px;
border-radius: 10px;
}
.score-timer-container span {
margin: 5px 0;
/* Adjust the spacing between score and timer */
}
</style>
</head>
<body onclick="playBackgroundMusic()">
<audio id="background-music">
<source src="Music.mp3" type="audio/mpeg">
Your browser does not support the audio element.
</audio>
<div class="score-timer-container">
<span id="score">Score: <span id="score-value">0</span></span>
<span id="timer">Time: <span id="countdown">40</span> seconds</span>
</div>
<img src="Images/LogoR.png" alt="Green Gamify Logo" class="logo">
<img id="waste1" src="Images/Level 2/plastic_bottle.png" class="waste-item" draggable="true"
ondragstart="drag(event)" data-type="recyclable" title="Plastic Bottle" style="top: 700px; left: 400px;">
<img id="waste2" src="Images/Level 2/brokken glass.png" class="waste-item" draggable="true"
ondragstart="drag(event)" data-type="non-recyclable" title="Broken Glass" style="top: 650px; left: 600px;">
<img id="waste3" src="Images/Level 2/papper.png" class="waste-item" draggable="true" ondragstart="drag(event)"
data-type="recyclable" title="Paper" style="top: 750px; left: 100px; height: 100px; width: 100px;">
<img id="waste4" src="Images/Level 2/package.png" class="waste-item" draggable="true" ondragstart="drag(event)"
data-type="non-recyclable" title="Package" style="top: 480px; left: 150px;height: 100px; width: 100px;">
<img id="waste5" src="Images/Level 2/plasticbag.png" class="waste-item" draggable="true" ondragstart="drag(event)"
data-type="recyclable" title="Plastic Bag" style="top: 440px; left: 400px; height: 70px; width: 70px;">
<img id="waste6" src="Images/Level 2/plasticpack.png" class="waste-item" draggable="true" ondragstart="drag(event)"
data-type="non-recyclable" title="Plastic Pack" style="top: 400px; left: 1420px; height: 60px; width: 60px;">
<img id="waste7" src="Images/Level 2/glass.png" class="waste-item" draggable="true" ondragstart="drag(event)"
data-type="recyclable" title="Glass" style="top: 430px; left: 750px;height: 80px; width: 80px;">
<img id="waste8" src="Images/Level 2/paper bag.png" class="waste-item" draggable="true" ondragstart="drag(event)"
data-type="recyclable" title="Paper Bag" style="top: 470px; left: 1300px; height: 60px; width: 60px;">
<!-- Bin images inside the background image -->
<img id="recyclable-bin" src="Images/Level 2/recyclable_bin.png" class="bin-image" ondrop="drop(event)"
ondragover="allowDrop(event)" data-type="recyclable" alt="Recyclable Bin">
<img id="non-recyclable-bin" src="Images/Level 2/non_recyclable_bin.png" class="bin-image" ondrop="drop(event)"
ondragover="allowDrop(event)" data-type="non-recyclable" alt="Non-Recyclable Bin">
<script>
function playBackgroundMusic() {
const backgroundMusic = document.getElementById('background-music');
backgroundMusic.play();
}
let countdown = 40; // Initial countdown time in seconds
let score = 0; // Initial score
// Function to update the countdown timer
function updateTimer() {
countdown--;
document.getElementById('countdown').textContent = countdown;
if (countdown <= 0) {
clearInterval(timerInterval); // Stop the timer when it reaches 0
if (score >= 80) {
//alert('Time is up! Congratulations! You completed Level 2. Your score is ' + score);
// Redirect to Complete1.html after a delay
setTimeout(() => {
window.location.href = '2congratulations.html?score=' + score;
}, 1000);
} else {
//alert('Time is up! Try again. Your score is ' + score);
window.location.href = '2try_again.html?score=' + score;
}
}
}
// Function to update the score
function updateScore() {
score += 10; // Increase score by 10 for each correct placement
document.getElementById('score-value').textContent = score;
if (score >= 80) {
clearInterval(timerInterval); // Stop the timer when the score reaches 80
// Redirect to the score page for successful completion
window.location.href = '2congratulations.html?score=' + score;
}
}
// Timer interval that calls updateTimer every second
const timerInterval = setInterval(updateTimer, 1000);
function allowDrop(event) {
event.preventDefault();
}
function drag(event) {
event.dataTransfer.setData("text", event.target.id);
event.dataTransfer.setData("type", event.target.dataset.type);
}
function drop(event) {
event.preventDefault();
const draggedElementId = event.dataTransfer.getData("text");
const draggedElementType = event.dataTransfer.getData("type");
const binType = event.target.dataset.type;
let message;
let imageSrc;
if (draggedElementType === binType) {
//message = Correct! You dropped the waste in the ${binType} bin 😎.;
imageSrc = 'Images/Level 2/10.png';
updateScore(); // Update the score
// Remove the dropped waste item from the DOM
const droppedElement = document.getElementById(draggedElementId);
droppedElement.parentNode.removeChild(droppedElement);
// Check if all waste items are sorted
if (document.querySelectorAll('.waste-item').length === 0) {
// Redirect to Completed.html after a delay
setTimeout(() => {
window.location.href = '2Complete.html';
}, 3000);
}
} else {
//message = Oops! The waste has been dropped in the ${binType} bin 😒.;
imageSrc = 'Images/Level 2/sad.png';
}
// Show message
/*const popup = document.createElement('div');
popup.textContent = message;
popup.style.position = 'fixed';
popup.style.top = '50%';
popup.style.left = '50%';
popup.style.transform = 'translate(-50%, -50%)';
popup.style.backgroundColor = 'rgba(255, 255, 255, 0.9)';
popup.style.padding = '20px';
popup.style.border = '1px solid #000';
popup.style.borderRadius = '10px';
document.body.appendChild(popup);*/
// Show image
const image = document.createElement('img');
image.src = imageSrc;
image.style.position = 'fixed';
image.style.top = '60%';
image.style.left = '50%';
image.style.transform = 'translate(-50%, -50%)';
image.style.width = '100px';
image.style.height = '100px';
document.body.appendChild(image);
// Remove popup and image after 2 seconds
setTimeout(() => {
//popup.remove();
image.remove();
}, 2000);
}
</script>
</body>
</html>