-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
271 lines (259 loc) · 8.92 KB
/
index.html
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
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Centered P5.js Game</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.4.0/p5.js"></script>
<style>
body {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
padding: 0;
overflow: hidden;
position: relative;
}
#true-button, #false-button {
position: absolute;
top: 220px;
right: 60px;
width: 80px;
height: 40px;
background-color: #228B22;
color: white;
font-family: monospace;
font-size: 16px;
border: none;
border-radius: 5px;
cursor: pointer;
z-index: 10;
display: none;
}
#false-button {
right: 160px;
}
</style>
</head>
<body>
<button id="true-button">True</button>
<button id="false-button">False</button>
<script>
let bg;
let sash;
let campingBadge, cookingBadge, swimmingBadge, citizenshipBadge;
let message = "Welcome to the campsite! Please choose an activity.";
let completedActivities = {
swimming: false,
cooking: false,
camping: false,
citizenship: false
};
let questions = {
swimming: [
{ question: "True or False: The safest way to help a drowning victim is with an object, not by grabbing them.", answer: true },
{ question: "True or False: Floating on your back is an effective way to conserve energy in water.", answer: true },
{ question: "True or False: Treading water is the same as floating.", answer: false }
],
camping: [
{ question: "True or False: You should always set up a tent on a hill to avoid flooding.", answer: false },
{ question: "True or False: Waterproofing your tent is important before camping.", answer: true },
{ question: "True or False: Campfires should be set up close to tents.", answer: false }
],
citizenship: [
{ question: "True or False: The American flag should never touch the ground.", answer: true },
{ question: "True or False: Birthright citizenship means anyone born in the US is a citizen.", answer: true },
{ question: "True or False: Thomas Jefferson wrote the Declaration of Independence.", answer: true }
],
cooking: [
{ question: "True or False: The correct order from smallest to largest fire starter is tinder, kindling, fuel.", answer: true },
{ question: "True or False: Starting a fire with wet wood is a good idea.", answer: false },
{ question: "True or False: It is safe to leave a campfire unattended.", answer: false }
]
};
let currentQuestion = null;
let awaitingAnswer = false;
let currentActivity = "";
let interactionCount = 0;
function preload() {
bg = loadImage('campground.png');
sash = loadImage('sash.png');
campingBadge = loadImage('camping.png');
cookingBadge = loadImage('cooking.png');
swimmingBadge = loadImage('swimming.png');
citizenshipBadge = loadImage('Citizenship.png');
}
function setup() {
createCanvas(1000, 1000).parent(document.body);
let trueButton = select('#true-button');
let falseButton = select('#false-button');
trueButton.mousePressed(() => checkAnswer(true));
falseButton.mousePressed(() => checkAnswer(false));
}
function draw() {
image(bg, 0, 0, width, height);
highlightZones();
displayMessage();
displaySashAndBadges();
checkAllBadgesCollected();
}
function highlightZones() {
if (!awaitingAnswer) {
textFont('monospace');
// Swimming
if (mouseX > 400 && mouseX < 600 && mouseY > 300 && mouseY < 600) {
fill(0, 0, 255, 100);
rect(400, 300, 200, 300);
fill(255);
textSize(32);
textAlign(CENTER, CENTER);
text('Swimming', 500, 450);
}
// Food station (grills at the bottom of the image)
if (mouseX > 200 && mouseX < 775 && mouseY > 760 && mouseY < 995) {
fill(255, 0, 0, 100);
rect(200, 760, 575, 235);
fill(255);
textSize(32);
textAlign(CENTER, CENTER);
text('Cooking', 487.5, 877.5);
}
// Tents on the right side
if (mouseX > 760 && mouseX < 975 && mouseY > 405 && mouseY < 745) {
fill(0, 255, 0, 100);
rect(760, 405, 215, 340);
fill(255);
textSize(32);
textAlign(CENTER, CENTER);
text('Camping', 867.5, 575);
}
// Station wagon (left side of the canvas)
if (mouseX > 0 && mouseX < 140 && mouseY > 370 && mouseY < 480) {
fill(255, 255, 0, 100);
rect(0, 370, 140, 110);
fill(0);
textSize(32);
textAlign(CENTER, CENTER);
text('Departure', 70, 425);
}
// American flag (top center)
if (mouseX > 460 && mouseX < 550 && mouseY > 150 && mouseY < 345) {
fill(255, 255, 255, 100);
rect(460, 150, 90, 195);
fill(0);
textSize(32);
textAlign(CENTER, CENTER);
text('Citizenship', 505, 247.5);
}
}
}
function mousePressed() {
if (awaitingAnswer) {
return;
}
textFont('monospace');
// Swimming pool
if (mouseX > 400 && mouseX < 600 && mouseY > 300 && mouseY < 600) {
currentActivity = "swimming";
askQuestion(currentActivity);
}
// Food station (grills at the bottom of the image)
else if (mouseX > 200 && mouseX < 775 && mouseY > 760 && mouseY < 995) {
currentActivity = "cooking";
askQuestion(currentActivity);
}
// Tents on the right side
else if (mouseX > 760 && mouseX < 975 && mouseY > 405 && mouseY < 745) {
currentActivity = "camping";
askQuestion(currentActivity);
}
// American flag (top center)
else if (mouseX > 460 && mouseX < 550 && mouseY > 150 && mouseY < 345) {
currentActivity = "citizenship";
askQuestion(currentActivity);
}
// Station wagon (departure)
else if (mouseX > 0 && mouseX < 140 && mouseY > 370 && mouseY < 480) {
if (Object.values(completedActivities).every(Boolean)) {
let confirmDeparture = confirm("Time to go home?");
if (confirmDeparture) {
window.close();
}
}
}
}
function askQuestion(activity) {
let questionIndex = floor(random(questions[activity].length));
currentQuestion = questions[activity][questionIndex];
message = currentQuestion.question;
awaitingAnswer = true;
select('#true-button').style('display', 'block');
select('#false-button').style('display', 'block');
}
function checkAnswer(userAnswer) {
if (awaitingAnswer) {
if (userAnswer === currentQuestion.answer) {
message = "Correct! You have earned the " + capitalize(currentActivity) + " badge.";
if (!completedActivities[currentActivity]) {
interactionCount++;
}
completedActivities[currentActivity] = true;
} else {
message = "Incorrect! Try again next time.";
}
awaitingAnswer = false;
currentQuestion = null;
select('#true-button').style('display', 'none');
select('#false-button').style('display', 'none');
}
}
function displayMessage() {
fill(180, 255, 180);
stroke(34, 139, 34);
strokeWeight(4);
rect(50, 20, width - 100, 80, 10);
noStroke();
fill(0);
textSize(24);
textFont('monospace');
textAlign(LEFT, CENTER);
let maxWidth = width - 120;
let textY = 40;
text(message, 60, textY, maxWidth);
}
function displaySashAndBadges() {
// Display the sash at (50, 120)
image(sash, 50, 120, 450, 100);
let badgeX = 70;
let badgeY = 140;
let badgeSpacing = 100;
// Display badges as soon as activities are completed
if (completedActivities.swimming) {
image(swimmingBadge, badgeX, badgeY, 80, 80);
badgeX += badgeSpacing;
}
if (completedActivities.cooking) {
image(cookingBadge, badgeX, badgeY, 80, 80);
badgeX += badgeSpacing;
}
if (completedActivities.camping) {
image(campingBadge, badgeX, badgeY, 80, 80);
badgeX += badgeSpacing;
}
if (completedActivities.citizenship) {
image(citizenshipBadge, badgeX, badgeY, 80, 80);
}
}
function checkAllBadgesCollected() {
if (Object.values(completedActivities).every(Boolean) && interactionCount >= 4) {
message = "Congratulations! You've collected all the badges. Click on the Departure button to go home.";
}
}
function capitalize(str) {
return str.charAt(0).toUpperCase() + str.slice(1);
}
</script>
</body>
</html>