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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<!DOCTYPE html>
|
2 |
<html>
|
3 |
+
<head>
|
4 |
+
<title>Neon Runner</title>
|
5 |
+
<style>
|
6 |
+
body { margin: 0; overflow: hidden; touch-action: none; }
|
7 |
+
#ui {
|
8 |
+
position: fixed;
|
9 |
+
top: 20px;
|
10 |
+
left: 50%;
|
11 |
+
transform: translateX(-50%);
|
12 |
+
color: #0ff;
|
13 |
+
font-family: Arial;
|
14 |
+
text-align: center;
|
15 |
+
pointer-events: none;
|
16 |
+
text-shadow: 0 0 10px #0ff;
|
17 |
+
}
|
18 |
+
#restart {
|
19 |
+
position: fixed;
|
20 |
+
top: 50%;
|
21 |
+
left: 50%;
|
22 |
+
transform: translate(-50%, -50%);
|
23 |
+
padding: 15px 30px;
|
24 |
+
font-size: 24px;
|
25 |
+
background: #00ffff;
|
26 |
+
border: none;
|
27 |
+
border-radius: 10px;
|
28 |
+
cursor: pointer;
|
29 |
+
display: none;
|
30 |
+
box-shadow: 0 0 20px #0ff;
|
31 |
+
}
|
32 |
+
</style>
|
33 |
+
</head>
|
34 |
+
<body>
|
35 |
+
<div id="ui">
|
36 |
+
<div>SCORE: <span id="score">0</span></div>
|
37 |
+
<div>COMBO: <span id="combo">x1</span></div>
|
38 |
+
</div>
|
39 |
+
<button id="restart">RESTART</button>
|
40 |
+
|
41 |
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js"></script>
|
42 |
+
<script>
|
43 |
+
let scene, camera, renderer, player, particles;
|
44 |
+
let obstacles = [];
|
45 |
+
let powerUps = [];
|
46 |
+
let velocity = 0;
|
47 |
+
let score = 0;
|
48 |
+
let combo = 1;
|
49 |
+
const config = {
|
50 |
+
GRAVITY: 0.02,
|
51 |
+
JUMP_FORCE: 0.6,
|
52 |
+
SPEED: 0.4,
|
53 |
+
PARTICLE_COUNT: 30
|
54 |
+
};
|
55 |
+
|
56 |
+
function init() {
|
57 |
+
scene = new THREE.Scene();
|
58 |
+
camera = new THREE.PerspectiveCamera(75, window.innerWidth/window.innerHeight, 0.1, 1000);
|
59 |
+
renderer = new THREE.WebGLRenderer({ antialias: true });
|
60 |
+
renderer.setSize(window.innerWidth, window.innerHeight);
|
61 |
+
renderer.setClearColor(0x000000);
|
62 |
+
document.body.appendChild(renderer.domElement);
|
63 |
+
|
64 |
+
// Lighting
|
65 |
+
const ambientLight = new THREE.AmbientLight(0xffffff, 0.5);
|
66 |
+
scene.add(ambientLight);
|
67 |
+
const directionalLight = new THREE.DirectionalLight(0x00ffff, 1);
|
68 |
+
directionalLight.position.set(0, 5, 5);
|
69 |
+
scene.add(directionalLight);
|
70 |
+
|
71 |
+
// Player
|
72 |
+
const playerGeometry = new THREE.CapsuleGeometry(0.3, 0.6, 8, 16);
|
73 |
+
const playerMaterial = new THREE.MeshPhongMaterial({
|
74 |
+
color: 0x00ffff,
|
75 |
+
emissive: 0x00ffff,
|
76 |
+
emissiveIntensity: 0.5
|
77 |
+
});
|
78 |
+
player = new THREE.Mesh(playerGeometry, playerMaterial);
|
79 |
+
player.position.set(0, 2, 0);
|
80 |
+
scene.add(player);
|
81 |
+
|
82 |
+
// Track
|
83 |
+
createTrack();
|
84 |
+
createParticleSystem();
|
85 |
+
|
86 |
+
camera.position.set(0, 4, 7);
|
87 |
+
camera.lookAt(0, 2, 0);
|
88 |
+
}
|
89 |
+
|
90 |
+
function createTrack() {
|
91 |
+
const trackGeometry = new THREE.PlaneGeometry(40, 40);
|
92 |
+
const trackTexture = new THREE.TextureLoader().load('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAAJUlEQVQoU2NkYGD4z8DAwMgABXCJYARQic4H4gIiBC4hAAACCRAH6YGjSQAAAABJRU5ErkJggg==');
|
93 |
+
const trackMaterial = new THREE.MeshPhongMaterial({
|
94 |
+
color: 0x222222,
|
95 |
+
emissive: 0x00ffff,
|
96 |
+
emissiveIntensity: 0.1,
|
97 |
+
map: trackTexture
|
98 |
+
});
|
99 |
+
const track = new THREE.Mesh(trackGeometry, trackMaterial);
|
100 |
+
track.rotation.x = -Math.PI / 2;
|
101 |
+
scene.add(track);
|
102 |
+
}
|
103 |
+
|
104 |
+
function createParticleSystem() {
|
105 |
+
const particleGeometry = new THREE.BufferGeometry();
|
106 |
+
const positions = [];
|
107 |
+
for(let i = 0; i < config.PARTICLE_COUNT; i++) {
|
108 |
+
positions.push(
|
109 |
+
Math.random() * 20 - 10,
|
110 |
+
0.2,
|
111 |
+
Math.random() * 20 - 10
|
112 |
+
);
|
113 |
+
}
|
114 |
+
particleGeometry.setAttribute('position', new THREE.Float32BufferAttribute(positions, 3));
|
115 |
+
const particleMaterial = new THREE.PointsMaterial({
|
116 |
+
size: 0.1,
|
117 |
+
color: 0x00ffff,
|
118 |
+
transparent: true,
|
119 |
+
opacity: 0.6
|
120 |
+
});
|
121 |
+
particles = new THREE.Points(particleGeometry, particleMaterial);
|
122 |
+
scene.add(particles);
|
123 |
+
}
|
124 |
+
|
125 |
+
function createObstacle() {
|
126 |
+
const types = ['box', 'sphere', 'cylinder'];
|
127 |
+
const type = types[Math.floor(Math.random() * types.length)];
|
128 |
+
let geometry;
|
129 |
+
|
130 |
+
switch(type) {
|
131 |
+
case 'sphere':
|
132 |
+
geometry = new THREE.SphereGeometry(0.5);
|
133 |
+
break;
|
134 |
+
case 'cylinder':
|
135 |
+
geometry = new THREE.CylinderGeometry(0.4, 0.4, 1);
|
136 |
+
break;
|
137 |
+
default:
|
138 |
+
geometry = new THREE.BoxGeometry(0.8, 0.8, 0.8);
|
139 |
+
}
|
140 |
+
|
141 |
+
const material = new THREE.MeshPhongMaterial({
|
142 |
+
color: 0xff0066,
|
143 |
+
emissive: 0xff0066,
|
144 |
+
emissiveIntensity: 0.3
|
145 |
+
});
|
146 |
+
const obstacle = new THREE.Mesh(geometry, material);
|
147 |
+
obstacle.position.set(15, type === 'cylinder' ? 0.5 : 0.4, 0);
|
148 |
+
obstacle.rotation.y = Math.random() * Math.PI;
|
149 |
+
scene.add(obstacle);
|
150 |
+
obstacles.push(obstacle);
|
151 |
+
}
|
152 |
+
|
153 |
+
function createPowerUp() {
|
154 |
+
if(Math.random() > 0.3) return;
|
155 |
+
|
156 |
+
const geometry = new THREE.TetrahedronGeometry(0.4);
|
157 |
+
const material = new THREE.MeshPhongMaterial({
|
158 |
+
color: 0xffff00,
|
159 |
+
emissive: 0xffff00,
|
160 |
+
emissiveIntensity: 0.5
|
161 |
+
});
|
162 |
+
const powerUp = new THREE.Mesh(geometry, material);
|
163 |
+
powerUp.position.set(15, 1.5, Math.random() * 4 - 2);
|
164 |
+
scene.add(powerUp);
|
165 |
+
powerUps.push(powerUp);
|
166 |
+
}
|
167 |
+
|
168 |
+
function checkCollision(obj) {
|
169 |
+
const playerBox = new THREE.Box3().expandByObject(player);
|
170 |
+
const objBox = new THREE.Box3().expandByObject(obj);
|
171 |
+
return playerBox.intersectsBox(objBox);
|
172 |
+
}
|
173 |
+
|
174 |
+
function gameOver() {
|
175 |
+
document.getElementById('restart').style.display = 'block';
|
176 |
+
config.SPEED = 0;
|
177 |
+
}
|
178 |
+
|
179 |
+
function resetGame() {
|
180 |
+
obstacles.forEach(o => scene.remove(o));
|
181 |
+
powerUps.forEach(p => scene.remove(p));
|
182 |
+
obstacles = [];
|
183 |
+
powerUps = [];
|
184 |
+
score = 0;
|
185 |
+
combo = 1;
|
186 |
+
config.SPEED = 0.4;
|
187 |
+
player.position.set(0, 2, 0);
|
188 |
+
document.getElementById('restart').style.display = 'none';
|
189 |
+
updateUI();
|
190 |
+
}
|
191 |
+
|
192 |
+
function updateUI() {
|
193 |
+
document.getElementById('score').textContent = score;
|
194 |
+
document.getElementById('combo').textContent = `x${combo}`;
|
195 |
+
}
|
196 |
+
|
197 |
+
document.addEventListener('keydown', e => {
|
198 |
+
if(e.code === 'Space' && player.position.y <= 2.1 && config.SPEED > 0) {
|
199 |
+
velocity = config.JUMP_FORCE;
|
200 |
+
combo++;
|
201 |
+
}
|
202 |
+
});
|
203 |
+
|
204 |
+
document.addEventListener('pointerdown', () => {
|
205 |
+
if(player.position.y <= 2.1 && config.SPEED > 0) {
|
206 |
+
velocity = config.JUMP_FORCE;
|
207 |
+
combo++;
|
208 |
+
}
|
209 |
+
});
|
210 |
+
|
211 |
+
document.getElementById('restart').addEventListener('click', resetGame);
|
212 |
+
|
213 |
+
function animate() {
|
214 |
+
requestAnimationFrame(animate);
|
215 |
+
|
216 |
+
// Player physics
|
217 |
+
velocity -= config.GRAVITY;
|
218 |
+
player.position.y += velocity;
|
219 |
+
if(player.position.y < 2) {
|
220 |
+
player.position.y = 2;
|
221 |
+
velocity = 0;
|
222 |
+
combo = 1;
|
223 |
+
}
|
224 |
+
|
225 |
+
// Movement system
|
226 |
+
obstacles.forEach((obstacle, i) => {
|
227 |
+
obstacle.position.x -= config.SPEED;
|
228 |
+
obstacle.rotation.y += 0.05;
|
229 |
+
|
230 |
+
if(obstacle.position.x < -15) {
|
231 |
+
scene.remove(obstacle);
|
232 |
+
obstacles.splice(i, 1);
|
233 |
+
}
|
234 |
+
|
235 |
+
if(checkCollision(obstacle)) gameOver();
|
236 |
+
});
|
237 |
+
|
238 |
+
powerUps.forEach((powerUp, i) => {
|
239 |
+
powerUp.position.x -= config.SPEED;
|
240 |
+
powerUp.rotation.x += 0.1;
|
241 |
+
powerUp.rotation.y += 0.1;
|
242 |
+
|
243 |
+
if(checkCollision(powerUp)) {
|
244 |
+
score += 50 * combo;
|
245 |
+
scene.remove(powerUp);
|
246 |
+
powerUps.splice(i, 1);
|
247 |
+
updateUI();
|
248 |
+
}
|
249 |
+
});
|
250 |
+
|
251 |
+
// Particle animation
|
252 |
+
particles.rotation.y += 0.002;
|
253 |
+
|
254 |
+
// Camera follow
|
255 |
+
camera.position.x += (player.position.x - camera.position.x) * 0.05;
|
256 |
+
camera.position.z = 7 + (score * 0.0002);
|
257 |
+
|
258 |
+
renderer.render(scene, camera);
|
259 |
+
}
|
260 |
+
|
261 |
+
// Game loop
|
262 |
+
setInterval(() => {
|
263 |
+
if(config.SPEED > 0) {
|
264 |
+
score += combo;
|
265 |
+
config.SPEED *= 1.0002;
|
266 |
+
updateUI();
|
267 |
+
}
|
268 |
+
}, 100);
|
269 |
+
|
270 |
+
setInterval(() => config.SPEED > 0 && createObstacle(), 1500);
|
271 |
+
setInterval(() => config.SPEED > 0 && createPowerUp(), 3000);
|
272 |
+
|
273 |
+
// Init
|
274 |
+
window.addEventListener('resize', () => {
|
275 |
+
camera.aspect = window.innerWidth / window.innerHeight;
|
276 |
+
camera.updateProjectionMatrix();
|
277 |
+
renderer.setSize(window.innerWidth, window.innerHeight);
|
278 |
+
});
|
279 |
+
|
280 |
+
init();
|
281 |
+
animate();
|
282 |
+
</script>
|
283 |
+
</body>
|
284 |
+
</html>
|