Spaces:
Running
Running
Add 2 files
Browse files- README.md +7 -5
- index.html +514 -19
README.md
CHANGED
@@ -1,10 +1,12 @@
|
|
1 |
---
|
2 |
-
title: 3d
|
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: 3d-mario-bug
|
3 |
+
emoji: 🐳
|
4 |
+
colorFrom: green
|
5 |
+
colorTo: purple
|
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,514 @@
|
|
1 |
-
<!
|
2 |
-
<html>
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<!DOCTYPE html>
|
2 |
+
<html lang="en">
|
3 |
+
<head>
|
4 |
+
<meta charset="UTF-8">
|
5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6 |
+
<title>Pixel Quest 3D: Find Your Friend</title>
|
7 |
+
<script src="https://cdn.tailwindcss.com"></script>
|
8 |
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js"></script>
|
9 |
+
<style>
|
10 |
+
body {
|
11 |
+
margin: 0;
|
12 |
+
overflow: hidden;
|
13 |
+
font-family: 'Press Start 2P', cursive;
|
14 |
+
image-rendering: pixelated;
|
15 |
+
}
|
16 |
+
|
17 |
+
canvas {
|
18 |
+
display: block;
|
19 |
+
image-rendering: pixelated;
|
20 |
+
}
|
21 |
+
|
22 |
+
@font-face {
|
23 |
+
font-family: 'Press Start 2P';
|
24 |
+
src: url('https://fonts.googleapis.com/css2?family=Press+Start+2P&display=swap');
|
25 |
+
}
|
26 |
+
|
27 |
+
.pixel-border {
|
28 |
+
border: 4px solid #fff;
|
29 |
+
box-shadow: 0 0 0 4px #000, inset 0 0 0 4px #000;
|
30 |
+
}
|
31 |
+
|
32 |
+
.quiz-option {
|
33 |
+
transition: all 0.1s;
|
34 |
+
border: 3px solid #fff;
|
35 |
+
box-shadow: 0 0 0 3px #000;
|
36 |
+
}
|
37 |
+
|
38 |
+
.quiz-option:hover {
|
39 |
+
background-color: #4a5568;
|
40 |
+
transform: translateY(-2px);
|
41 |
+
}
|
42 |
+
|
43 |
+
.quiz-option.correct {
|
44 |
+
background-color: #48bb78;
|
45 |
+
}
|
46 |
+
|
47 |
+
.quiz-option.wrong {
|
48 |
+
background-color: #f56565;
|
49 |
+
}
|
50 |
+
|
51 |
+
.pixel-text {
|
52 |
+
text-shadow: 3px 3px 0 #000, -1px -1px 0 #000, 1px -1px 0 #000, -1px 1px 0 #000, 1px 1px 0 #000;
|
53 |
+
}
|
54 |
+
</style>
|
55 |
+
</head>
|
56 |
+
<body class="bg-gray-900">
|
57 |
+
<div id="game-container" class="relative w-full h-screen">
|
58 |
+
<!-- Start Screen -->
|
59 |
+
<div id="start-screen" class="absolute inset-0 flex flex-col items-center justify-center bg-gray-900 z-10">
|
60 |
+
<h1 class="text-4xl md:text-6xl text-green-400 mb-8 pixel-text">PIXEL QUEST 3D</h1>
|
61 |
+
<p class="text-xl text-white mb-12 pixel-text">Find Your Lost Friend!</p>
|
62 |
+
<div class="w-32 h-32 mb-8 bg-red-500 pixel-border animate-bounce"></div>
|
63 |
+
<button id="start-btn" class="px-8 py-4 bg-green-500 hover:bg-green-600 text-white font-bold pixel-border transition-all transform hover:scale-105">
|
64 |
+
START ADVENTURE
|
65 |
+
</button>
|
66 |
+
</div>
|
67 |
+
|
68 |
+
<!-- Quiz Modal -->
|
69 |
+
<div id="quiz-modal" class="hidden absolute inset-0 flex items-center justify-center z-20 bg-black bg-opacity-70">
|
70 |
+
<div class="bg-gray-800 p-6 rounded-lg w-11/12 max-w-md pixel-border">
|
71 |
+
<h2 id="quiz-question" class="text-xl text-white mb-6 pixel-text"></h2>
|
72 |
+
<div id="quiz-options" class="space-y-3"></div>
|
73 |
+
<div id="quiz-feedback" class="mt-4 text-yellow-300 hidden pixel-text"></div>
|
74 |
+
</div>
|
75 |
+
</div>
|
76 |
+
|
77 |
+
<!-- End Screen -->
|
78 |
+
<div id="end-screen" class="hidden absolute inset-0 flex flex-col items-center justify-center bg-gray-900 z-10">
|
79 |
+
<h1 class="text-4xl md:text-6xl text-green-400 mb-8 pixel-text">FRIEND FOUND!</h1>
|
80 |
+
<div class="flex items-center mb-8">
|
81 |
+
<div class="w-32 h-32 bg-red-500 pixel-border mr-4"></div>
|
82 |
+
<div class="w-32 h-32 bg-blue-500 pixel-border"></div>
|
83 |
+
</div>
|
84 |
+
<p id="final-score" class="text-xl text-white mb-12 pixel-text"></p>
|
85 |
+
<button id="restart-btn" class="px-8 py-4 bg-green-500 hover:bg-green-600 text-white font-bold pixel-border transition-all transform hover:scale-105">
|
86 |
+
PLAY AGAIN
|
87 |
+
</button>
|
88 |
+
</div>
|
89 |
+
|
90 |
+
<!-- UI Elements -->
|
91 |
+
<div id="ui-container" class="absolute top-4 left-4 z-10 hidden">
|
92 |
+
<div class="bg-gray-800 bg-opacity-70 p-3 rounded pixel-border">
|
93 |
+
<p class="text-white pixel-text">Score: <span id="score-display">0</span></p>
|
94 |
+
<p class="text-white pixel-text">Quizzes: <span id="quiz-count">0</span>/4</p>
|
95 |
+
</div>
|
96 |
+
</div>
|
97 |
+
</div>
|
98 |
+
|
99 |
+
<script>
|
100 |
+
// Game variables
|
101 |
+
let scene, camera, renderer;
|
102 |
+
let player, platforms = [], checkpoints = [], coins = [];
|
103 |
+
let playerVelocity = { x: 0, y: 0, z: 0 };
|
104 |
+
let playerSpeed = 0.2;
|
105 |
+
let jumpForce = 0.4;
|
106 |
+
let gravity = 0.02;
|
107 |
+
let isJumping = false;
|
108 |
+
let gamePaused = false;
|
109 |
+
let score = 0;
|
110 |
+
let quizzesCompleted = 0;
|
111 |
+
let currentCheckpoint = null;
|
112 |
+
let friendFound = false;
|
113 |
+
let keys = {};
|
114 |
+
let worldWidth = 100;
|
115 |
+
let worldDepth = 20;
|
116 |
+
let friend;
|
117 |
+
|
118 |
+
// Quiz questions
|
119 |
+
const quizQuestions = [
|
120 |
+
{
|
121 |
+
question: "What is your friend's favorite color?",
|
122 |
+
options: ["Blue", "Green", "Red", "Yellow"],
|
123 |
+
correct: 0
|
124 |
+
},
|
125 |
+
{
|
126 |
+
question: "Where did you first meet your friend?",
|
127 |
+
options: ["At school", "At the park", "At a party", "Online"],
|
128 |
+
correct: 1
|
129 |
+
},
|
130 |
+
{
|
131 |
+
question: "What's your friend's favorite food?",
|
132 |
+
options: ["Pizza", "Sushi", "Burgers", "Tacos"],
|
133 |
+
correct: 2
|
134 |
+
},
|
135 |
+
{
|
136 |
+
question: "What was your last adventure together?",
|
137 |
+
options: ["Hiking", "Movie marathon", "Road trip", "Camping"],
|
138 |
+
correct: 3
|
139 |
+
}
|
140 |
+
];
|
141 |
+
|
142 |
+
// Initialize game
|
143 |
+
function init() {
|
144 |
+
// Scene setup
|
145 |
+
scene = new THREE.Scene();
|
146 |
+
scene.background = new THREE.Color(0x87CEEB); // Sky blue
|
147 |
+
|
148 |
+
// Camera (orthographic for 2.5D effect)
|
149 |
+
const aspect = window.innerWidth / window.innerHeight;
|
150 |
+
camera = new THREE.OrthographicCamera(
|
151 |
+
-10 * aspect, 10 * aspect, // left, right
|
152 |
+
10, -10, // top, bottom
|
153 |
+
0.1, 1000
|
154 |
+
);
|
155 |
+
camera.position.set(0, 5, 20);
|
156 |
+
camera.lookAt(0, 0, 0);
|
157 |
+
|
158 |
+
// Renderer
|
159 |
+
renderer = new THREE.WebGLRenderer({ antialias: false });
|
160 |
+
renderer.setPixelRatio(window.devicePixelRatio > 1 ? 2 : 1);
|
161 |
+
renderer.setSize(window.innerWidth, window.innerHeight);
|
162 |
+
renderer.shadowMap.enabled = true;
|
163 |
+
document.getElementById('game-container').appendChild(renderer.domElement);
|
164 |
+
|
165 |
+
// Lighting
|
166 |
+
const ambientLight = new THREE.AmbientLight(0xffffff, 0.5);
|
167 |
+
scene.add(ambientLight);
|
168 |
+
|
169 |
+
const directionalLight = new THREE.DirectionalLight(0xffffff, 0.8);
|
170 |
+
directionalLight.position.set(10, 20, 10);
|
171 |
+
directionalLight.castShadow = true;
|
172 |
+
directionalLight.shadow.mapSize.width = 1024;
|
173 |
+
directionalLight.shadow.mapSize.height = 1024;
|
174 |
+
scene.add(directionalLight);
|
175 |
+
|
176 |
+
// Create world
|
177 |
+
createWorld();
|
178 |
+
|
179 |
+
// Create player
|
180 |
+
createPlayer();
|
181 |
+
|
182 |
+
// Create checkpoints
|
183 |
+
createCheckpoints();
|
184 |
+
|
185 |
+
// Create friend
|
186 |
+
createFriend();
|
187 |
+
|
188 |
+
// Event listeners
|
189 |
+
window.addEventListener('resize', onWindowResize);
|
190 |
+
document.addEventListener('keydown', onKeyDown);
|
191 |
+
document.addEventListener('keyup', onKeyUp);
|
192 |
+
|
193 |
+
// Start button
|
194 |
+
document.getElementById('start-btn').addEventListener('click', startGame);
|
195 |
+
document.getElementById('restart-btn').addEventListener('click', restartGame);
|
196 |
+
|
197 |
+
// Hide start screen after assets load
|
198 |
+
setTimeout(() => {
|
199 |
+
document.getElementById('ui-container').classList.remove('hidden');
|
200 |
+
}, 100);
|
201 |
+
}
|
202 |
+
|
203 |
+
function createWorld() {
|
204 |
+
// Ground
|
205 |
+
const groundGeometry = new THREE.BoxGeometry(worldWidth, 1, worldDepth);
|
206 |
+
const groundMaterial = new THREE.MeshStandardMaterial({
|
207 |
+
color: 0x2e8b57,
|
208 |
+
roughness: 1.0
|
209 |
+
});
|
210 |
+
const ground = new THREE.Mesh(groundGeometry, groundMaterial);
|
211 |
+
ground.position.y = -0.5;
|
212 |
+
ground.receiveShadow = true;
|
213 |
+
scene.add(ground);
|
214 |
+
|
215 |
+
// Platforms
|
216 |
+
const platformPositions = [
|
217 |
+
{ x: 10, y: 2, z: 0, width: 8, depth: 8 },
|
218 |
+
{ x: 25, y: 3, z: 5, width: 6, depth: 6 },
|
219 |
+
{ x: 40, y: 4, z: -3, width: 10, depth: 10 },
|
220 |
+
{ x: 60, y: 2, z: 2, width: 12, depth: 8 },
|
221 |
+
{ x: 80, y: 5, z: 0, width: 8, depth: 8 }
|
222 |
+
];
|
223 |
+
|
224 |
+
platformPositions.forEach(pos => {
|
225 |
+
const platformGeometry = new THREE.BoxGeometry(pos.width, 1, pos.depth);
|
226 |
+
const platformMaterial = new THREE.MeshStandardMaterial({
|
227 |
+
color: 0x8b4513,
|
228 |
+
roughness: 1.0
|
229 |
+
});
|
230 |
+
const platform = new THREE.Mesh(platformGeometry, platformMaterial);
|
231 |
+
platform.position.set(pos.x, pos.y, pos.z);
|
232 |
+
platform.receiveShadow = true;
|
233 |
+
scene.add(platform);
|
234 |
+
platforms.push(platform);
|
235 |
+
});
|
236 |
+
|
237 |
+
// Coins
|
238 |
+
for (let i = 0; i < 20; i++) {
|
239 |
+
const coinGeometry = new THREE.CylinderGeometry(0.5, 0.5, 0.2, 16);
|
240 |
+
const coinMaterial = new THREE.MeshStandardMaterial({ color: 0xffd700 });
|
241 |
+
const coin = new THREE.Mesh(coinGeometry, coinMaterial);
|
242 |
+
|
243 |
+
// Position coins randomly above platforms or ground
|
244 |
+
let x, y, z;
|
245 |
+
if (Math.random() > 0.5) {
|
246 |
+
// On platforms
|
247 |
+
const platform = platforms[Math.floor(Math.random() * platforms.length)];
|
248 |
+
x = platform.position.x + (Math.random() - 0.5) * (platform.geometry.parameters.width - 2);
|
249 |
+
y = platform.position.y + 1;
|
250 |
+
z = platform.position.z + (Math.random() - 0.5) * (platform.geometry.parameters.depth - 2);
|
251 |
+
} else {
|
252 |
+
// On ground
|
253 |
+
x = Math.random() * worldWidth;
|
254 |
+
y = 0.5;
|
255 |
+
z = (Math.random() - 0.5) * (worldDepth - 4);
|
256 |
+
}
|
257 |
+
|
258 |
+
coin.position.set(x, y, z);
|
259 |
+
coin.rotation.x = Math.PI / 2;
|
260 |
+
coin.userData.isCoin = true;
|
261 |
+
scene.add(coin);
|
262 |
+
coins.push(coin);
|
263 |
+
}
|
264 |
+
}
|
265 |
+
|
266 |
+
function createPlayer() {
|
267 |
+
// Simple pixel-style character
|
268 |
+
const playerGeometry = new THREE.BoxGeometry(1, 2, 1);
|
269 |
+
const playerMaterial = new THREE.MeshStandardMaterial({ color: 0xff0000 });
|
270 |
+
player = new THREE.Mesh(playerGeometry, playerMaterial);
|
271 |
+
player.position.set(0, 1, 0);
|
272 |
+
player.castShadow = true;
|
273 |
+
scene.add(player);
|
274 |
+
}
|
275 |
+
|
276 |
+
function createCheckpoints() {
|
277 |
+
// Create 4 checkpoints along the path
|
278 |
+
const checkpointPositions = [
|
279 |
+
{ x: 15, y: 0, z: 0 },
|
280 |
+
{ x: 30, y: 0, z: 0 },
|
281 |
+
{ x: 50, y: 0, z: 0 },
|
282 |
+
{ x: 70, y: 0, z: 0 }
|
283 |
+
];
|
284 |
+
|
285 |
+
checkpointPositions.forEach((pos, index) => {
|
286 |
+
const checkpointGeometry = new THREE.BoxGeometry(2, 2, 2);
|
287 |
+
const checkpointMaterial = new THREE.MeshStandardMaterial({
|
288 |
+
color: 0xffff00,
|
289 |
+
transparent: true,
|
290 |
+
opacity: 0.7
|
291 |
+
});
|
292 |
+
const checkpoint = new THREE.Mesh(checkpointGeometry, checkpointMaterial);
|
293 |
+
checkpoint.position.set(pos.x, pos.y + 1, pos.z);
|
294 |
+
checkpoint.userData.isCheckpoint = true;
|
295 |
+
checkpoint.userData.quizIndex = index;
|
296 |
+
scene.add(checkpoint);
|
297 |
+
checkpoints.push(checkpoint);
|
298 |
+
});
|
299 |
+
}
|
300 |
+
|
301 |
+
function createFriend() {
|
302 |
+
// Create the friend character at the end
|
303 |
+
const friendGeometry = new THREE.BoxGeometry(1, 2, 1);
|
304 |
+
const friendMaterial = new THREE.MeshStandardMaterial({ color: 0x0000ff });
|
305 |
+
friend = new THREE.Mesh(friendGeometry, friendMaterial);
|
306 |
+
friend.position.set(worldWidth - 5, 1, 0);
|
307 |
+
friend.castShadow = true;
|
308 |
+
friend.userData.isFriend = true;
|
309 |
+
scene.add(friend);
|
310 |
+
}
|
311 |
+
|
312 |
+
function startGame() {
|
313 |
+
document.getElementById('start-screen').classList.add('hidden');
|
314 |
+
document.getElementById('ui-container').classList.remove('hidden');
|
315 |
+
animate();
|
316 |
+
}
|
317 |
+
|
318 |
+
function restartGame() {
|
319 |
+
// Reset game state
|
320 |
+
score = 0;
|
321 |
+
quizzesCompleted = 0;
|
322 |
+
friendFound = false;
|
323 |
+
gamePaused = false;
|
324 |
+
|
325 |
+
// Reset player position
|
326 |
+
player.position.set(0, 1, 0);
|
327 |
+
playerVelocity = { x: 0, y: 0, z: 0 };
|
328 |
+
|
329 |
+
// Reset UI
|
330 |
+
document.getElementById('score-display').textContent = '0';
|
331 |
+
document.getElementById('quiz-count').textContent = '0/4';
|
332 |
+
document.getElementById('end-screen').classList.add('hidden');
|
333 |
+
document.getElementById('ui-container').classList.remove('hidden');
|
334 |
+
|
335 |
+
// Restart animation
|
336 |
+
animate();
|
337 |
+
}
|
338 |
+
|
339 |
+
function showQuiz(quizIndex) {
|
340 |
+
gamePaused = true;
|
341 |
+
currentCheckpoint = quizIndex;
|
342 |
+
|
343 |
+
const quiz = quizQuestions[quizIndex];
|
344 |
+
document.getElementById('quiz-question').textContent = quiz.question;
|
345 |
+
|
346 |
+
const optionsContainer = document.getElementById('quiz-options');
|
347 |
+
optionsContainer.innerHTML = '';
|
348 |
+
|
349 |
+
quiz.options.forEach((option, i) => {
|
350 |
+
const optionBtn = document.createElement('button');
|
351 |
+
optionBtn.className = 'w-full p-3 bg-gray-700 text-white quiz-option pixel-text';
|
352 |
+
optionBtn.textContent = option;
|
353 |
+
optionBtn.addEventListener('click', () => checkAnswer(i));
|
354 |
+
optionsContainer.appendChild(optionBtn);
|
355 |
+
});
|
356 |
+
|
357 |
+
document.getElementById('quiz-feedback').classList.add('hidden');
|
358 |
+
document.getElementById('quiz-modal').classList.remove('hidden');
|
359 |
+
}
|
360 |
+
|
361 |
+
function checkAnswer(answerIndex) {
|
362 |
+
const quiz = quizQuestions[currentCheckpoint];
|
363 |
+
const options = document.querySelectorAll('.quiz-option');
|
364 |
+
|
365 |
+
if (answerIndex === quiz.correct) {
|
366 |
+
// Correct answer
|
367 |
+
options[answerIndex].classList.add('correct');
|
368 |
+
document.getElementById('quiz-feedback').textContent = 'Correct!';
|
369 |
+
document.getElementById('quiz-feedback').classList.remove('hidden');
|
370 |
+
|
371 |
+
setTimeout(() => {
|
372 |
+
quizzesCompleted++;
|
373 |
+
document.getElementById('quiz-count').textContent = `${quizzesCompleted}/4`;
|
374 |
+
document.getElementById('quiz-modal').classList.add('hidden');
|
375 |
+
gamePaused = false;
|
376 |
+
|
377 |
+
// Remove the checkpoint
|
378 |
+
const checkpoint = checkpoints[currentCheckpoint];
|
379 |
+
scene.remove(checkpoint);
|
380 |
+
checkpoints[currentCheckpoint] = null;
|
381 |
+
|
382 |
+
// Add score
|
383 |
+
score += 100;
|
384 |
+
document.getElementById('score-display').textContent = score;
|
385 |
+
}, 1000);
|
386 |
+
} else {
|
387 |
+
// Wrong answer
|
388 |
+
options[answerIndex].classList.add('wrong');
|
389 |
+
options[quiz.correct].classList.add('correct');
|
390 |
+
document.getElementById('quiz-feedback').textContent = 'Try again!';
|
391 |
+
document.getElementById('quiz-feedback').classList.remove('hidden');
|
392 |
+
}
|
393 |
+
}
|
394 |
+
|
395 |
+
function onWindowResize() {
|
396 |
+
const aspect = window.innerWidth / window.innerHeight;
|
397 |
+
camera.left = -10 * aspect;
|
398 |
+
camera.right = 10 * aspect;
|
399 |
+
camera.top = 10;
|
400 |
+
camera.bottom = -10;
|
401 |
+
camera.updateProjectionMatrix();
|
402 |
+
renderer.setSize(window.innerWidth, window.innerHeight);
|
403 |
+
}
|
404 |
+
|
405 |
+
function onKeyDown(event) {
|
406 |
+
keys[event.code] = true;
|
407 |
+
|
408 |
+
// Jump
|
409 |
+
if (event.code === 'Space' && !isJumping && !gamePaused) {
|
410 |
+
playerVelocity.y = jumpForce;
|
411 |
+
isJumping = true;
|
412 |
+
}
|
413 |
+
}
|
414 |
+
|
415 |
+
function onKeyUp(event) {
|
416 |
+
keys[event.code] = false;
|
417 |
+
}
|
418 |
+
|
419 |
+
function checkCollisions() {
|
420 |
+
// Check platform collisions
|
421 |
+
let onGround = false;
|
422 |
+
const playerBox = new THREE.Box3().setFromObject(player);
|
423 |
+
|
424 |
+
platforms.forEach(platform => {
|
425 |
+
const platformBox = new THREE.Box3().setFromObject(platform);
|
426 |
+
if (playerBox.intersectsBox(platformBox)) {
|
427 |
+
// Check if player is on top of platform
|
428 |
+
if (player.position.y > platform.position.y + 0.9) {
|
429 |
+
player.position.y = platform.position.y + 1 + player.geometry.parameters.height / 2;
|
430 |
+
playerVelocity.y = 0;
|
431 |
+
isJumping = false;
|
432 |
+
onGround = true;
|
433 |
+
}
|
434 |
+
}
|
435 |
+
});
|
436 |
+
|
437 |
+
// Ground collision
|
438 |
+
if (player.position.y <= 0) {
|
439 |
+
player.position.y = 0;
|
440 |
+
playerVelocity.y = 0;
|
441 |
+
isJumping = false;
|
442 |
+
onGround = true;
|
443 |
+
}
|
444 |
+
|
445 |
+
// Check coin collisions
|
446 |
+
coins.forEach((coin, index) => {
|
447 |
+
if (coin && new THREE.Box3().setFromObject(player).intersectsBox(new THREE.Box3().setFromObject(coin))) {
|
448 |
+
scene.remove(coin);
|
449 |
+
coins[index] = null;
|
450 |
+
score += 10;
|
451 |
+
document.getElementById('score-display').textContent = score;
|
452 |
+
}
|
453 |
+
});
|
454 |
+
|
455 |
+
// Check checkpoint collisions
|
456 |
+
checkpoints.forEach((checkpoint, index) => {
|
457 |
+
if (checkpoint && new THREE.Box3().setFromObject(player).intersectsBox(new THREE.Box3().setFromObject(checkpoint))) {
|
458 |
+
showQuiz(index);
|
459 |
+
}
|
460 |
+
});
|
461 |
+
|
462 |
+
// Check friend collision
|
463 |
+
if (!friendFound && new THREE.Box3().setFromObject(player).intersectsBox(new THREE.Box3().setFromObject(friend)) && quizzesCompleted === 4) {
|
464 |
+
friendFound = true;
|
465 |
+
gamePaused = true;
|
466 |
+
|
467 |
+
// Show end screen
|
468 |
+
document.getElementById('final-score').textContent = `Final Score: ${score}`;
|
469 |
+
document.getElementById('end-screen').classList.remove('hidden');
|
470 |
+
document.getElementById('ui-container').classList.add('hidden');
|
471 |
+
}
|
472 |
+
|
473 |
+
return onGround;
|
474 |
+
}
|
475 |
+
|
476 |
+
function animate() {
|
477 |
+
if (gamePaused) return;
|
478 |
+
|
479 |
+
requestAnimationFrame(animate);
|
480 |
+
|
481 |
+
// Player movement
|
482 |
+
if (keys['KeyA'] || keys['ArrowLeft']) {
|
483 |
+
playerVelocity.x = -playerSpeed;
|
484 |
+
player.rotation.y = Math.PI;
|
485 |
+
} else if (keys['KeyD'] || keys['ArrowRight']) {
|
486 |
+
playerVelocity.x = playerSpeed;
|
487 |
+
player.rotation.y = 0;
|
488 |
+
} else {
|
489 |
+
playerVelocity.x = 0;
|
490 |
+
}
|
491 |
+
|
492 |
+
// Apply gravity
|
493 |
+
playerVelocity.y -= gravity;
|
494 |
+
|
495 |
+
// Update player position
|
496 |
+
player.position.x += playerVelocity.x;
|
497 |
+
player.position.y += playerVelocity.y;
|
498 |
+
|
499 |
+
// Check collisions
|
500 |
+
checkCollisions();
|
501 |
+
|
502 |
+
// Update camera to follow player (side-scrolling)
|
503 |
+
camera.position.x = player.position.x;
|
504 |
+
camera.position.z = 20;
|
505 |
+
camera.lookAt(player.position.x, player.position.y, 0);
|
506 |
+
|
507 |
+
renderer.render(scene, camera);
|
508 |
+
}
|
509 |
+
|
510 |
+
// Start the game
|
511 |
+
init();
|
512 |
+
</script>
|
513 |
+
<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/3d-mario-bug" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
|
514 |
+
</html>
|