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 |
+
<!DOCTYPE html>
|
| 2 |
<html>
|
| 3 |
+
<head>
|
| 4 |
+
<title>Endless Runner</title>
|
| 5 |
+
<style>
|
| 6 |
+
body { margin: 0; overflow: hidden; }
|
| 7 |
+
canvas { display: block; }
|
| 8 |
+
#score {
|
| 9 |
+
position: absolute;
|
| 10 |
+
top: 10px;
|
| 11 |
+
left: 10px;
|
| 12 |
+
color: white;
|
| 13 |
+
font-family: Arial;
|
| 14 |
+
font-size: 20px;
|
| 15 |
+
}
|
| 16 |
+
</style>
|
| 17 |
+
</head>
|
| 18 |
+
<body>
|
| 19 |
+
<div id="score">Score: 0</div>
|
| 20 |
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r134/three.min.js"></script>
|
| 21 |
+
<script>
|
| 22 |
+
// Scene setup
|
| 23 |
+
const scene = new THREE.Scene();
|
| 24 |
+
const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
|
| 25 |
+
const renderer = new THREE.WebGLRenderer();
|
| 26 |
+
renderer.setSize(window.innerWidth, window.innerHeight);
|
| 27 |
+
document.body.appendChild(renderer.domElement);
|
| 28 |
+
|
| 29 |
+
// Player
|
| 30 |
+
const playerGeometry = new THREE.BoxGeometry(1, 1, 1);
|
| 31 |
+
const playerMaterial = new THREE.MeshBasicMaterial({ color: 0x00ff00 });
|
| 32 |
+
const player = new THREE.Mesh(playerGeometry, playerMaterial);
|
| 33 |
+
player.position.y = 0.5;
|
| 34 |
+
scene.add(player);
|
| 35 |
+
|
| 36 |
+
// Ground
|
| 37 |
+
const groundGeometry = new THREE.PlaneGeometry(10, 1000);
|
| 38 |
+
const groundMaterial = new THREE.MeshBasicMaterial({ color: 0x888888 });
|
| 39 |
+
const ground = new THREE.Mesh(groundGeometry, groundMaterial);
|
| 40 |
+
ground.rotation.x = -Math.PI / 2;
|
| 41 |
+
ground.position.y = 0;
|
| 42 |
+
scene.add(ground);
|
| 43 |
+
|
| 44 |
+
// Game variables
|
| 45 |
+
let obstacles = [];
|
| 46 |
+
let score = 0;
|
| 47 |
+
let isJumping = false;
|
| 48 |
+
let jumpVelocity = 0;
|
| 49 |
+
let gameSpeed = 0.1;
|
| 50 |
+
let lastObstacleTime = 0;
|
| 51 |
+
|
| 52 |
+
camera.position.z = 5;
|
| 53 |
+
camera.position.y = 5;
|
| 54 |
+
camera.lookAt(0, 0, 0);
|
| 55 |
+
|
| 56 |
+
// Obstacle creation
|
| 57 |
+
function createObstacle() {
|
| 58 |
+
const obstacleGeometry = new THREE.BoxGeometry(1, 1, 1);
|
| 59 |
+
const obstacleMaterial = new THREE.MeshBasicMaterial({ color: 0xff0000 });
|
| 60 |
+
const obstacle = new THREE.Mesh(obstacleGeometry, obstacleMaterial);
|
| 61 |
+
obstacle.position.y = 0.5;
|
| 62 |
+
obstacle.position.z = -50;
|
| 63 |
+
obstacle.position.x = Math.random() * 4 - 2;
|
| 64 |
+
scene.add(obstacle);
|
| 65 |
+
obstacles.push(obstacle);
|
| 66 |
+
}
|
| 67 |
+
|
| 68 |
+
// Jump mechanics
|
| 69 |
+
document.addEventListener('keydown', (event) => {
|
| 70 |
+
if (event.code === 'Space' && !isJumping) {
|
| 71 |
+
isJumping = true;
|
| 72 |
+
jumpVelocity = 0.3;
|
| 73 |
+
}
|
| 74 |
+
});
|
| 75 |
+
|
| 76 |
+
// Game loop
|
| 77 |
+
function animate() {
|
| 78 |
+
requestAnimationFrame(animate);
|
| 79 |
+
|
| 80 |
+
// Update ground movement
|
| 81 |
+
ground.position.z += gameSpeed;
|
| 82 |
+
if (ground.position.z > 100) {
|
| 83 |
+
ground.position.z = 0;
|
| 84 |
+
}
|
| 85 |
+
|
| 86 |
+
// Jump physics
|
| 87 |
+
if (isJumping) {
|
| 88 |
+
player.position.y += jumpVelocity;
|
| 89 |
+
jumpVelocity -= 0.015;
|
| 90 |
+
if (player.position.y <= 0.5) {
|
| 91 |
+
player.position.y = 0.5;
|
| 92 |
+
isJumping = false;
|
| 93 |
+
jumpVelocity = 0;
|
| 94 |
+
}
|
| 95 |
+
}
|
| 96 |
+
|
| 97 |
+
// Obstacle management
|
| 98 |
+
const currentTime = Date.now();
|
| 99 |
+
if (currentTime - lastObstacleTime > 2000) {
|
| 100 |
+
createObstacle();
|
| 101 |
+
lastObstacleTime = currentTime;
|
| 102 |
+
}
|
| 103 |
+
|
| 104 |
+
// Move and check obstacles
|
| 105 |
+
obstacles.forEach((obstacle, index) => {
|
| 106 |
+
obstacle.position.z += gameSpeed;
|
| 107 |
+
|
| 108 |
+
// Collision detection
|
| 109 |
+
if (Math.abs(obstacle.position.z - player.position.z) < 1 &&
|
| 110 |
+
Math.abs(obstacle.position.x - player.position.x) < 1 &&
|
| 111 |
+
player.position.y < 1.5) {
|
| 112 |
+
alert('Game Over! Score: ' + score);
|
| 113 |
+
obstacles.forEach(o => scene.remove(o));
|
| 114 |
+
obstacles = [];
|
| 115 |
+
score = 0;
|
| 116 |
+
}
|
| 117 |
+
|
| 118 |
+
// Remove obstacles that passed
|
| 119 |
+
if (obstacle.position.z > 10) {
|
| 120 |
+
scene.remove(obstacle);
|
| 121 |
+
obstacles.splice(index, 1);
|
| 122 |
+
score += 10;
|
| 123 |
+
}
|
| 124 |
+
});
|
| 125 |
+
|
| 126 |
+
// Update score
|
| 127 |
+
document.getElementById('score').textContent = 'Score: ' + score;
|
| 128 |
+
|
| 129 |
+
// Increase difficulty
|
| 130 |
+
gameSpeed += 0.0001;
|
| 131 |
+
|
| 132 |
+
renderer.render(scene, camera);
|
| 133 |
+
}
|
| 134 |
+
|
| 135 |
+
// Handle window resize
|
| 136 |
+
window.addEventListener('resize', () => {
|
| 137 |
+
camera.aspect = window.innerWidth / window.innerHeight;
|
| 138 |
+
camera.updateProjectionMatrix();
|
| 139 |
+
renderer.setSize(window.innerWidth, window.innerHeight);
|
| 140 |
+
});
|
| 141 |
+
|
| 142 |
+
animate();
|
| 143 |
+
</script>
|
| 144 |
+
</body>
|
| 145 |
+
</html>
|