Spaces:
Running
Running
Add 2 files
Browse files- README.md +7 -5
- index.html +611 -19
README.md
CHANGED
@@ -1,10 +1,12 @@
|
|
1 |
---
|
2 |
-
title:
|
3 |
-
emoji:
|
4 |
-
colorFrom:
|
5 |
-
colorTo:
|
6 |
sdk: static
|
7 |
pinned: false
|
|
|
|
|
8 |
---
|
9 |
|
10 |
-
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
1 |
---
|
2 |
+
title: friend-quest
|
3 |
+
emoji: 🐳
|
4 |
+
colorFrom: yellow
|
5 |
+
colorTo: red
|
6 |
sdk: static
|
7 |
pinned: false
|
8 |
+
tags:
|
9 |
+
- deepsite
|
10 |
---
|
11 |
|
12 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
index.html
CHANGED
@@ -1,19 +1,611 @@
|
|
1 |
-
<!
|
2 |
-
<html>
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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|
+
<title>Friend Quest</title>
|
7 |
+
<script src="https://cdn.tailwindcss.com"></script>
|
8 |
+
<style>
|
9 |
+
/* Custom CSS for pixel art and game elements */
|
10 |
+
.pixel-art {
|
11 |
+
image-rendering: pixelated;
|
12 |
+
image-rendering: -moz-crisp-edges;
|
13 |
+
image-rendering: crisp-edges;
|
14 |
+
}
|
15 |
+
|
16 |
+
#gameCanvas {
|
17 |
+
background-color: #6b8cff;
|
18 |
+
border: 4px solid #333;
|
19 |
+
box-shadow: 0 0 20px rgba(0,0,0,0.3);
|
20 |
+
}
|
21 |
+
|
22 |
+
.quiz-modal {
|
23 |
+
background-color: #f0e6d2;
|
24 |
+
border: 4px solid #8b4513;
|
25 |
+
box-shadow: 0 0 0 8px #d2b48c, 0 0 0 12px #8b4513;
|
26 |
+
}
|
27 |
+
|
28 |
+
.quiz-option {
|
29 |
+
background-color: #d2b48c;
|
30 |
+
border: 3px solid #8b4513;
|
31 |
+
transition: all 0.2s;
|
32 |
+
}
|
33 |
+
|
34 |
+
.quiz-option:hover {
|
35 |
+
background-color: #f0e6d2;
|
36 |
+
transform: scale(1.05);
|
37 |
+
}
|
38 |
+
|
39 |
+
.quiz-option.correct {
|
40 |
+
background-color: #8fbc8f;
|
41 |
+
border-color: #556b2f;
|
42 |
+
}
|
43 |
+
|
44 |
+
.quiz-option.wrong {
|
45 |
+
background-color: #cd5c5c;
|
46 |
+
border-color: #8b0000;
|
47 |
+
}
|
48 |
+
|
49 |
+
@keyframes jump {
|
50 |
+
0% { transform: translateY(0); }
|
51 |
+
50% { transform: translateY(-20px); }
|
52 |
+
100% { transform: translateY(0); }
|
53 |
+
}
|
54 |
+
|
55 |
+
.jump-animation {
|
56 |
+
animation: jump 0.5s ease;
|
57 |
+
}
|
58 |
+
|
59 |
+
.character {
|
60 |
+
transition: transform 0.1s;
|
61 |
+
}
|
62 |
+
|
63 |
+
.moving {
|
64 |
+
animation: walk 0.5s steps(4) infinite;
|
65 |
+
}
|
66 |
+
|
67 |
+
@keyframes walk {
|
68 |
+
from { background-position: 0 0; }
|
69 |
+
to { background-position: -64px 0; }
|
70 |
+
}
|
71 |
+
</style>
|
72 |
+
</head>
|
73 |
+
<body class="bg-gray-900 text-white min-h-screen flex flex-col items-center justify-center p-4">
|
74 |
+
<div class="text-center mb-4">
|
75 |
+
<h1 class="text-4xl font-bold mb-2 text-yellow-300 font-mono">FRIEND QUEST</h1>
|
76 |
+
<p class="text-lg text-gray-300">Find your lost friend by answering questions about them!</p>
|
77 |
+
</div>
|
78 |
+
|
79 |
+
<div class="relative">
|
80 |
+
<!-- Game Canvas -->
|
81 |
+
<canvas id="gameCanvas" width="800" height="400" class="pixel-art"></canvas>
|
82 |
+
|
83 |
+
<!-- Start Screen -->
|
84 |
+
<div id="startScreen" class="absolute inset-0 bg-black bg-opacity-70 flex flex-col items-center justify-center">
|
85 |
+
<div class="text-center p-8 bg-gray-800 rounded-lg border-4 border-yellow-400 max-w-md">
|
86 |
+
<h2 class="text-3xl font-bold mb-4 text-yellow-400">FRIEND QUEST</h2>
|
87 |
+
<p class="mb-6">Your friend is lost in this strange world! Jump over obstacles and answer questions about them to find your way.</p>
|
88 |
+
<button id="startButton" class="bg-yellow-500 hover:bg-yellow-400 text-black font-bold py-3 px-6 rounded-lg text-xl transition-all transform hover:scale-105">
|
89 |
+
START ADVENTURE
|
90 |
+
</button>
|
91 |
+
</div>
|
92 |
+
</div>
|
93 |
+
|
94 |
+
<!-- Quiz Modal -->
|
95 |
+
<div id="quizModal" class="absolute inset-0 hidden items-center justify-center">
|
96 |
+
<div class="quiz-modal p-6 rounded-lg w-full max-w-md">
|
97 |
+
<h3 class="text-2xl font-bold mb-4 text-center text-brown-800">What do you remember about your friend?</h3>
|
98 |
+
<p id="quizQuestion" class="text-lg mb-6 text-center text-brown-800">Loading question...</p>
|
99 |
+
<div class="grid grid-cols-1 gap-3">
|
100 |
+
<button class="quiz-option py-3 px-4 rounded-lg text-lg" data-answer="1">Option 1</button>
|
101 |
+
<button class="quiz-option py-3 px-4 rounded-lg text-lg" data-answer="2">Option 2</button>
|
102 |
+
<button class="quiz-option py-3 px-4 rounded-lg text-lg" data-answer="3">Option 3</button>
|
103 |
+
<button class="quiz-option py-3 px-4 rounded-lg text-lg" data-answer="4">Option 4</button>
|
104 |
+
</div>
|
105 |
+
<div id="quizFeedback" class="mt-4 text-center text-lg font-bold hidden"></div>
|
106 |
+
</div>
|
107 |
+
</div>
|
108 |
+
|
109 |
+
<!-- Game Over Screen -->
|
110 |
+
<div id="gameOverScreen" class="absolute inset-0 hidden bg-black bg-opacity-70 flex flex-col items-center justify-center">
|
111 |
+
<div class="text-center p-8 bg-gray-800 rounded-lg border-4 border-red-500 max-w-md">
|
112 |
+
<h2 class="text-3xl font-bold mb-4 text-red-500">GAME OVER</h2>
|
113 |
+
<p class="mb-6" id="gameOverMessage">You failed to find your friend!</p>
|
114 |
+
<button id="restartButton" class="bg-red-500 hover:bg-red-400 text-white font-bold py-3 px-6 rounded-lg text-xl transition-all transform hover:scale-105">
|
115 |
+
TRY AGAIN
|
116 |
+
</button>
|
117 |
+
</div>
|
118 |
+
</div>
|
119 |
+
|
120 |
+
<!-- Win Screen -->
|
121 |
+
<div id="winScreen" class="absolute inset-0 hidden bg-black bg-opacity-70 flex flex-col items-center justify-center">
|
122 |
+
<div class="text-center p-8 bg-gray-800 rounded-lg border-4 border-green-500 max-w-md">
|
123 |
+
<h2 class="text-3xl font-bold mb-4 text-green-500">VICTORY!</h2>
|
124 |
+
<p class="mb-6">You found your friend! Thanks to your great memory about them.</p>
|
125 |
+
<button id="playAgainButton" class="bg-green-500 hover:bg-green-400 text-white font-bold py-3 px-6 rounded-lg text-xl transition-all transform hover:scale-105">
|
126 |
+
PLAY AGAIN
|
127 |
+
</button>
|
128 |
+
</div>
|
129 |
+
</div>
|
130 |
+
</div>
|
131 |
+
|
132 |
+
<div class="mt-6 flex gap-8">
|
133 |
+
<div class="text-center">
|
134 |
+
<p class="text-lg">Controls:</p>
|
135 |
+
<p class="text-gray-400">Arrow keys to move, Space to jump</p>
|
136 |
+
</div>
|
137 |
+
<div class="text-center">
|
138 |
+
<p class="text-lg">Progress:</p>
|
139 |
+
<p id="scoreDisplay" class="text-yellow-400">Questions: 0/5</p>
|
140 |
+
</div>
|
141 |
+
</div>
|
142 |
+
|
143 |
+
<script>
|
144 |
+
// Game variables
|
145 |
+
const canvas = document.getElementById('gameCanvas');
|
146 |
+
const ctx = canvas.getContext('2d');
|
147 |
+
const startScreen = document.getElementById('startScreen');
|
148 |
+
const startButton = document.getElementById('startButton');
|
149 |
+
const quizModal = document.getElementById('quizModal');
|
150 |
+
const quizQuestion = document.getElementById('quizQuestion');
|
151 |
+
const quizOptions = document.querySelectorAll('.quiz-option');
|
152 |
+
const quizFeedback = document.getElementById('quizFeedback');
|
153 |
+
const gameOverScreen = document.getElementById('gameOverScreen');
|
154 |
+
const gameOverMessage = document.getElementById('gameOverMessage');
|
155 |
+
const restartButton = document.getElementById('restartButton');
|
156 |
+
const winScreen = document.getElementById('winScreen');
|
157 |
+
const playAgainButton = document.getElementById('playAgainButton');
|
158 |
+
const scoreDisplay = document.getElementById('scoreDisplay');
|
159 |
+
|
160 |
+
// Game state
|
161 |
+
let gameRunning = false;
|
162 |
+
let quizActive = false;
|
163 |
+
let currentQuestion = null;
|
164 |
+
let correctAnswers = 0;
|
165 |
+
const totalQuestions = 5;
|
166 |
+
|
167 |
+
// Character properties
|
168 |
+
const character = {
|
169 |
+
x: 50,
|
170 |
+
y: 300,
|
171 |
+
width: 32,
|
172 |
+
height: 48,
|
173 |
+
speed: 5,
|
174 |
+
velocityY: 0,
|
175 |
+
gravity: 0.5,
|
176 |
+
jumpForce: -12,
|
177 |
+
isJumping: false,
|
178 |
+
direction: 1, // 1 for right, -1 for left
|
179 |
+
moving: false
|
180 |
+
};
|
181 |
+
|
182 |
+
// Game world properties
|
183 |
+
const world = {
|
184 |
+
width: 2000,
|
185 |
+
scrollX: 0,
|
186 |
+
groundHeight: 350
|
187 |
+
};
|
188 |
+
|
189 |
+
// Platform and obstacle data
|
190 |
+
const platforms = [
|
191 |
+
{ x: 0, y: world.groundHeight, width: 500, height: 50 },
|
192 |
+
{ x: 600, y: world.groundHeight - 100, width: 200, height: 50 },
|
193 |
+
{ x: 900, y: world.groundHeight, width: 300, height: 50 },
|
194 |
+
{ x: 1300, y: world.groundHeight - 150, width: 200, height: 50 },
|
195 |
+
{ x: 1600, y: world.groundHeight, width: 400, height: 50 }
|
196 |
+
];
|
197 |
+
|
198 |
+
// Checkpoints that trigger quizzes
|
199 |
+
const checkpoints = [
|
200 |
+
{ x: 300, quizTaken: false },
|
201 |
+
{ x: 800, quizTaken: false },
|
202 |
+
{ x: 1100, quizTaken: false },
|
203 |
+
{ x: 1400, quizTaken: false },
|
204 |
+
{ x: 1800, quizTaken: false }
|
205 |
+
];
|
206 |
+
|
207 |
+
// Enemy data
|
208 |
+
const enemies = [
|
209 |
+
{ x: 400, y: world.groundHeight - 30, width: 32, height: 32, speed: 2, direction: 1 },
|
210 |
+
{ x: 700, y: world.groundHeight - 130, width: 32, height: 32, speed: 1, direction: -1 },
|
211 |
+
{ x: 1000, y: world.groundHeight - 30, width: 32, height: 32, speed: 3, direction: 1 },
|
212 |
+
{ x: 1500, y: world.groundHeight - 180, width: 32, height: 32, speed: 2, direction: -1 }
|
213 |
+
];
|
214 |
+
|
215 |
+
// Friend (goal) position
|
216 |
+
const friend = {
|
217 |
+
x: 1900,
|
218 |
+
y: world.groundHeight - 50,
|
219 |
+
width: 32,
|
220 |
+
height: 48
|
221 |
+
};
|
222 |
+
|
223 |
+
// Quiz questions
|
224 |
+
const questions = [
|
225 |
+
{
|
226 |
+
question: "What is your friend's favorite color?",
|
227 |
+
options: ["Blue", "Red", "Green", "Yellow"],
|
228 |
+
correct: 0
|
229 |
+
},
|
230 |
+
{
|
231 |
+
question: "What food does your friend dislike?",
|
232 |
+
options: ["Pizza", "Broccoli", "Ice cream", "Pasta"],
|
233 |
+
correct: 1
|
234 |
+
},
|
235 |
+
{
|
236 |
+
question: "Where did you first meet your friend?",
|
237 |
+
options: ["School", "Park", "Library", "Sports club"],
|
238 |
+
correct: 2
|
239 |
+
},
|
240 |
+
{
|
241 |
+
question: "What is your friend's favorite season?",
|
242 |
+
options: ["Winter", "Spring", "Summer", "Fall"],
|
243 |
+
correct: 3
|
244 |
+
},
|
245 |
+
{
|
246 |
+
question: "What is your friend's biggest fear?",
|
247 |
+
options: ["Spiders", "Heights", "Darkness", "Clowns"],
|
248 |
+
correct: 1
|
249 |
+
}
|
250 |
+
];
|
251 |
+
|
252 |
+
// Keyboard state
|
253 |
+
const keys = {
|
254 |
+
ArrowLeft: false,
|
255 |
+
ArrowRight: false,
|
256 |
+
ArrowUp: false,
|
257 |
+
Space: false
|
258 |
+
};
|
259 |
+
|
260 |
+
// Event listeners
|
261 |
+
startButton.addEventListener('click', startGame);
|
262 |
+
restartButton.addEventListener('click', resetGame);
|
263 |
+
playAgainButton.addEventListener('click', resetGame);
|
264 |
+
|
265 |
+
quizOptions.forEach(option => {
|
266 |
+
option.addEventListener('click', () => checkAnswer(option));
|
267 |
+
});
|
268 |
+
|
269 |
+
document.addEventListener('keydown', (e) => {
|
270 |
+
if (e.code in keys) {
|
271 |
+
keys[e.code] = true;
|
272 |
+
e.preventDefault();
|
273 |
+
}
|
274 |
+
});
|
275 |
+
|
276 |
+
document.addEventListener('keyup', (e) => {
|
277 |
+
if (e.code in keys) {
|
278 |
+
keys[e.code] = false;
|
279 |
+
e.preventDefault();
|
280 |
+
}
|
281 |
+
});
|
282 |
+
|
283 |
+
// Game functions
|
284 |
+
function startGame() {
|
285 |
+
gameRunning = true;
|
286 |
+
startScreen.classList.add('hidden');
|
287 |
+
correctAnswers = 0;
|
288 |
+
updateScoreDisplay();
|
289 |
+
resetGameState();
|
290 |
+
requestAnimationFrame(gameLoop);
|
291 |
+
}
|
292 |
+
|
293 |
+
function resetGame() {
|
294 |
+
gameOverScreen.classList.add('hidden');
|
295 |
+
winScreen.classList.add('hidden');
|
296 |
+
resetGameState();
|
297 |
+
requestAnimationFrame(gameLoop);
|
298 |
+
}
|
299 |
+
|
300 |
+
function resetGameState() {
|
301 |
+
character.x = 50;
|
302 |
+
character.y = 300;
|
303 |
+
character.velocityY = 0;
|
304 |
+
character.isJumping = false;
|
305 |
+
world.scrollX = 0;
|
306 |
+
|
307 |
+
// Reset checkpoints
|
308 |
+
checkpoints.forEach(cp => cp.quizTaken = false);
|
309 |
+
|
310 |
+
// Reset enemies positions
|
311 |
+
enemies[0].x = 400;
|
312 |
+
enemies[1].x = 700;
|
313 |
+
enemies[2].x = 1000;
|
314 |
+
enemies[3].x = 1500;
|
315 |
+
|
316 |
+
correctAnswers = 0;
|
317 |
+
updateScoreDisplay();
|
318 |
+
gameRunning = true;
|
319 |
+
quizActive = false;
|
320 |
+
}
|
321 |
+
|
322 |
+
function updateScoreDisplay() {
|
323 |
+
scoreDisplay.textContent = `Questions: ${correctAnswers}/${totalQuestions}`;
|
324 |
+
}
|
325 |
+
|
326 |
+
function gameLoop() {
|
327 |
+
if (!gameRunning) return;
|
328 |
+
|
329 |
+
update();
|
330 |
+
render();
|
331 |
+
|
332 |
+
requestAnimationFrame(gameLoop);
|
333 |
+
}
|
334 |
+
|
335 |
+
function update() {
|
336 |
+
if (quizActive) return;
|
337 |
+
|
338 |
+
// Handle movement
|
339 |
+
if (keys.ArrowLeft || keys['a']) {
|
340 |
+
character.x -= character.speed;
|
341 |
+
character.direction = -1;
|
342 |
+
character.moving = true;
|
343 |
+
} else if (keys.ArrowRight || keys['d']) {
|
344 |
+
character.x += character.speed;
|
345 |
+
character.direction = 1;
|
346 |
+
character.moving = true;
|
347 |
+
} else {
|
348 |
+
character.moving = false;
|
349 |
+
}
|
350 |
+
|
351 |
+
// Handle jumping
|
352 |
+
if ((keys.ArrowUp || keys.Space || keys['w']) && !character.isJumping) {
|
353 |
+
character.velocityY = character.jumpForce;
|
354 |
+
character.isJumping = true;
|
355 |
+
}
|
356 |
+
|
357 |
+
// Apply gravity
|
358 |
+
character.velocityY += character.gravity;
|
359 |
+
character.y += character.velocityY;
|
360 |
+
|
361 |
+
// Check for ground collision
|
362 |
+
let onGround = false;
|
363 |
+
for (const platform of platforms) {
|
364 |
+
if (character.y + character.height >= platform.y &&
|
365 |
+
character.y + character.height <= platform.y + platform.height &&
|
366 |
+
character.x + character.width > platform.x &&
|
367 |
+
character.x < platform.x + platform.width &&
|
368 |
+
character.velocityY > 0) {
|
369 |
+
|
370 |
+
character.y = platform.y - character.height;
|
371 |
+
character.velocityY = 0;
|
372 |
+
character.isJumping = false;
|
373 |
+
onGround = true;
|
374 |
+
}
|
375 |
+
}
|
376 |
+
|
377 |
+
// Check for enemy collisions
|
378 |
+
for (const enemy of enemies) {
|
379 |
+
if (checkCollision(character, enemy)) {
|
380 |
+
gameOver("You got hit by an enemy!");
|
381 |
+
return;
|
382 |
+
}
|
383 |
+
}
|
384 |
+
|
385 |
+
// Check for friend collision (win condition)
|
386 |
+
if (checkCollision(character, friend) && correctAnswers === totalQuestions) {
|
387 |
+
gameRunning = false;
|
388 |
+
winScreen.classList.remove('hidden');
|
389 |
+
return;
|
390 |
+
}
|
391 |
+
|
392 |
+
// Check for falling off the world
|
393 |
+
if (character.y > canvas.height) {
|
394 |
+
gameOver("You fell off the world!");
|
395 |
+
return;
|
396 |
+
}
|
397 |
+
|
398 |
+
// Update enemy positions
|
399 |
+
enemies.forEach(enemy => {
|
400 |
+
enemy.x += enemy.speed * enemy.direction;
|
401 |
+
|
402 |
+
// Simple enemy AI - turn around at edges
|
403 |
+
let enemyOnPlatform = false;
|
404 |
+
for (const platform of platforms) {
|
405 |
+
if (enemy.x >= platform.x && enemy.x + enemy.width <= platform.x + platform.width &&
|
406 |
+
enemy.y + enemy.height >= platform.y && enemy.y + enemy.height <= platform.y + platform.height) {
|
407 |
+
enemyOnPlatform = true;
|
408 |
+
|
409 |
+
// Check if enemy is at platform edge
|
410 |
+
if ((enemy.x <= platform.x && enemy.direction === -1) ||
|
411 |
+
(enemy.x + enemy.width >= platform.x + platform.width && enemy.direction === 1)) {
|
412 |
+
enemy.direction *= -1;
|
413 |
+
}
|
414 |
+
break;
|
415 |
+
}
|
416 |
+
}
|
417 |
+
|
418 |
+
if (!enemyOnPlatform) {
|
419 |
+
enemy.direction *= -1;
|
420 |
+
}
|
421 |
+
});
|
422 |
+
|
423 |
+
// Check for checkpoint collisions
|
424 |
+
checkpoints.forEach((checkpoint, index) => {
|
425 |
+
if (!checkpoint.quizTaken &&
|
426 |
+
character.x + character.width > checkpoint.x &&
|
427 |
+
character.x < checkpoint.x + 10) {
|
428 |
+
|
429 |
+
checkpoint.quizTaken = true;
|
430 |
+
showQuiz(index);
|
431 |
+
}
|
432 |
+
});
|
433 |
+
|
434 |
+
// Update camera (world scroll)
|
435 |
+
if (character.x > canvas.width / 2) {
|
436 |
+
world.scrollX = character.x - canvas.width / 2;
|
437 |
+
|
438 |
+
// Don't scroll past the end of the world
|
439 |
+
if (world.scrollX > world.width - canvas.width) {
|
440 |
+
world.scrollX = world.width - canvas.width;
|
441 |
+
}
|
442 |
+
} else {
|
443 |
+
world.scrollX = 0;
|
444 |
+
}
|
445 |
+
}
|
446 |
+
|
447 |
+
function render() {
|
448 |
+
// Clear canvas
|
449 |
+
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
450 |
+
|
451 |
+
// Draw sky background
|
452 |
+
ctx.fillStyle = '#6b8cff';
|
453 |
+
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
454 |
+
|
455 |
+
// Draw clouds (simple background elements)
|
456 |
+
ctx.fillStyle = '#ffffff';
|
457 |
+
ctx.fillRect(100 - world.scrollX / 3, 50, 60, 20);
|
458 |
+
ctx.fillRect(300 - world.scrollX / 3, 80, 80, 25);
|
459 |
+
ctx.fillRect(500 - world.scrollX / 3, 60, 70, 20);
|
460 |
+
ctx.fillRect(800 - world.scrollX / 3, 70, 90, 30);
|
461 |
+
|
462 |
+
// Draw platforms
|
463 |
+
ctx.fillStyle = '#8b4513'; // Brown
|
464 |
+
platforms.forEach(platform => {
|
465 |
+
ctx.fillRect(platform.x - world.scrollX, platform.y, platform.width, platform.height);
|
466 |
+
});
|
467 |
+
|
468 |
+
// Draw ground
|
469 |
+
ctx.fillStyle = '#556b2f'; // Dark green
|
470 |
+
ctx.fillRect(0, world.groundHeight, world.width, canvas.height - world.groundHeight);
|
471 |
+
|
472 |
+
// Draw checkpoints (flag markers)
|
473 |
+
ctx.fillStyle = '#ff0000';
|
474 |
+
checkpoints.forEach(checkpoint => {
|
475 |
+
if (!checkpoint.quizTaken) {
|
476 |
+
ctx.fillRect(checkpoint.x - world.scrollX, world.groundHeight - 60, 10, 60);
|
477 |
+
ctx.fillStyle = '#ffffff';
|
478 |
+
ctx.beginPath();
|
479 |
+
ctx.moveTo(checkpoint.x - world.scrollX + 10, world.groundHeight - 60);
|
480 |
+
ctx.lineTo(checkpoint.x - world.scrollX + 30, world.groundHeight - 40);
|
481 |
+
ctx.lineTo(checkpoint.x - world.scrollX + 10, world.groundHeight - 20);
|
482 |
+
ctx.fill();
|
483 |
+
ctx.fillStyle = '#ff0000';
|
484 |
+
}
|
485 |
+
});
|
486 |
+
|
487 |
+
// Draw enemies (simple pixel art)
|
488 |
+
ctx.fillStyle = '#ff0000';
|
489 |
+
enemies.forEach(enemy => {
|
490 |
+
// Simple enemy sprite - a red square with eyes
|
491 |
+
ctx.fillRect(enemy.x - world.scrollX, enemy.y, enemy.width, enemy.height);
|
492 |
+
|
493 |
+
// Eyes
|
494 |
+
ctx.fillStyle = '#ffffff';
|
495 |
+
ctx.fillRect(enemy.x - world.scrollX + 5, enemy.y + 5, 8, 8);
|
496 |
+
ctx.fillRect(enemy.x - world.scrollX + 19, enemy.y + 5, 8, 8);
|
497 |
+
ctx.fillStyle = '#000000';
|
498 |
+
ctx.fillRect(enemy.x - world.scrollX + 7, enemy.y + 7, 4, 4);
|
499 |
+
ctx.fillRect(enemy.x - world.scrollX + 21, enemy.y + 7, 4, 4);
|
500 |
+
|
501 |
+
ctx.fillStyle = '#ff0000';
|
502 |
+
});
|
503 |
+
|
504 |
+
// Draw friend (goal)
|
505 |
+
ctx.fillStyle = '#ffff00'; // Yellow
|
506 |
+
ctx.fillRect(friend.x - world.scrollX, friend.y, friend.width, friend.height);
|
507 |
+
|
508 |
+
// Face details
|
509 |
+
ctx.fillStyle = '#000000';
|
510 |
+
ctx.fillRect(friend.x - world.scrollX + 8, friend.y + 10, 4, 4); // Left eye
|
511 |
+
ctx.fillRect(friend.x - world.scrollX + 20, friend.y + 10, 4, 4); // Right eye
|
512 |
+
ctx.fillRect(friend.x - world.scrollX + 10, friend.y + 20, 12, 4); // Mouth
|
513 |
+
|
514 |
+
// Draw character (simple pixel art)
|
515 |
+
ctx.fillStyle = '#00ff00'; // Green
|
516 |
+
ctx.fillRect(character.x - world.scrollX, character.y, character.width, character.height);
|
517 |
+
|
518 |
+
// Face details (changes direction)
|
519 |
+
ctx.fillStyle = '#000000';
|
520 |
+
if (character.direction === 1) {
|
521 |
+
// Facing right
|
522 |
+
ctx.fillRect(character.x - world.scrollX + 8, character.y + 10, 4, 4); // Left eye
|
523 |
+
ctx.fillRect(character.x - world.scrollX + 20, character.y + 10, 4, 4); // Right eye
|
524 |
+
ctx.fillRect(character.x - world.scrollX + 10, character.y + 20, 12, 4); // Mouth
|
525 |
+
} else {
|
526 |
+
// Facing left
|
527 |
+
ctx.fillRect(character.x - world.scrollX + 8, character.y + 10, 4, 4); // Left eye
|
528 |
+
ctx.fillRect(character.x - world.scrollX + 20, character.y + 10, 4, 4); // Right eye
|
529 |
+
ctx.fillRect(character.x - world.scrollX + 10, character.y + 20, 12, 4); // Mouth
|
530 |
+
}
|
531 |
+
|
532 |
+
// Draw score
|
533 |
+
ctx.fillStyle = '#ffffff';
|
534 |
+
ctx.font = '20px Arial';
|
535 |
+
ctx.fillText(`Questions: ${correctAnswers}/${totalQuestions}`, 20, 30);
|
536 |
+
}
|
537 |
+
|
538 |
+
function checkCollision(obj1, obj2) {
|
539 |
+
return obj1.x < obj2.x + obj2.width &&
|
540 |
+
obj1.x + obj1.width > obj2.x &&
|
541 |
+
obj1.y < obj2.y + obj2.height &&
|
542 |
+
obj1.y + obj1.height > obj2.y;
|
543 |
+
}
|
544 |
+
|
545 |
+
function showQuiz(index) {
|
546 |
+
if (index >= questions.length) return;
|
547 |
+
|
548 |
+
gameRunning = false;
|
549 |
+
quizActive = true;
|
550 |
+
currentQuestion = questions[index];
|
551 |
+
|
552 |
+
quizQuestion.textContent = currentQuestion.question;
|
553 |
+
quizOptions.forEach((option, i) => {
|
554 |
+
option.textContent = currentQuestion.options[i];
|
555 |
+
option.classList.remove('correct', 'wrong');
|
556 |
+
});
|
557 |
+
|
558 |
+
quizFeedback.classList.add('hidden');
|
559 |
+
quizModal.classList.remove('hidden');
|
560 |
+
}
|
561 |
+
|
562 |
+
function checkAnswer(selectedOption) {
|
563 |
+
if (!currentQuestion) return;
|
564 |
+
|
565 |
+
const selectedAnswer = parseInt(selectedOption.dataset.answer) - 1;
|
566 |
+
const isCorrect = selectedAnswer === currentQuestion.correct;
|
567 |
+
|
568 |
+
if (isCorrect) {
|
569 |
+
selectedOption.classList.add('correct');
|
570 |
+
quizFeedback.textContent = "Correct! You remember your friend well.";
|
571 |
+
quizFeedback.classList.remove('hidden', 'text-red-500');
|
572 |
+
quizFeedback.classList.add('text-green-600');
|
573 |
+
|
574 |
+
correctAnswers++;
|
575 |
+
updateScoreDisplay();
|
576 |
+
|
577 |
+
// After a delay, hide the quiz and resume game
|
578 |
+
setTimeout(() => {
|
579 |
+
quizModal.classList.add('hidden');
|
580 |
+
quizActive = false;
|
581 |
+
gameRunning = true;
|
582 |
+
requestAnimationFrame(gameLoop);
|
583 |
+
}, 1500);
|
584 |
+
} else {
|
585 |
+
selectedOption.classList.add('wrong');
|
586 |
+
quizOptions[currentQuestion.correct].classList.add('correct');
|
587 |
+
quizFeedback.textContent = "Wrong! Try to remember better next time.";
|
588 |
+
quizFeedback.classList.remove('hidden', 'text-green-600');
|
589 |
+
quizFeedback.classList.add('text-red-500');
|
590 |
+
|
591 |
+
// After a delay, hide the quiz and resume game
|
592 |
+
setTimeout(() => {
|
593 |
+
quizModal.classList.add('hidden');
|
594 |
+
quizActive = false;
|
595 |
+
gameRunning = true;
|
596 |
+
requestAnimationFrame(gameLoop);
|
597 |
+
}, 1500);
|
598 |
+
}
|
599 |
+
}
|
600 |
+
|
601 |
+
function gameOver(message) {
|
602 |
+
gameRunning = false;
|
603 |
+
gameOverMessage.textContent = message;
|
604 |
+
gameOverScreen.classList.remove('hidden');
|
605 |
+
}
|
606 |
+
|
607 |
+
// Initialize with start screen visible
|
608 |
+
startScreen.classList.remove('hidden');
|
609 |
+
</script>
|
610 |
+
<p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - 🧬 <a href="https://enzostvs-deepsite.hf.space?remix=WebashalarForML/friend-quest" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
|
611 |
+
</html>
|