Andro0s commited on
Commit
93b8415
verified
1 Parent(s): 94b5eb5

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +234 -16
index.html CHANGED
@@ -1,23 +1,241 @@
1
  <!DOCTYPE html>
2
  <html lang="es">
3
  <head>
4
- <meta charset="UTF-8">
5
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
- <title>Worms 3D Clone</title>
7
- <link rel="stylesheet" href="style.css">
8
-
9
- <script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js"></script>
10
- <script src="https://unpkg.com/[email protected]/examples/js/controls/OrbitControls.js"></script>
11
- <script src="https://unpkg.com/[email protected]/examples/js/loaders/OBJLoader.js"></script>
12
- <script src="https://unpkg.com/[email protected]/examples/js/loaders/MTLLoader.js"></script>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
  </head>
14
  <body>
15
- <div id="game-container"></div>
16
-
17
- <div id="controls">
18
- <p><strong>3D READY:</strong> Usa el rat贸n (o toca la pantalla) para rotar y hacer zoom en el terreno 3D.</p>
19
- </div>
20
 
21
- <script src="game.js"></script>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22
  </body>
23
- </html>
 
1
  <!DOCTYPE html>
2
  <html lang="es">
3
  <head>
4
+ <meta charset="UTF-8">
5
+ <title>Worms 3D</title>
6
+ <style>
7
+ body {
8
+ margin: 0;
9
+ overflow: hidden;
10
+ background: #222;
11
+ display: flex;
12
+ flex-direction: column;
13
+ align-items: center;
14
+ justify-content: flex-start;
15
+ }
16
+
17
+ /* CONTENEDOR GENERAL */
18
+ #game-container {
19
+ width: 90vw;
20
+ height: 70vh;
21
+ background: #000;
22
+ border: 3px solid #00ff88;
23
+ margin-top: 10px;
24
+ position: relative;
25
+ }
26
+
27
+ /* BOTONES */
28
+ #ui-bar {
29
+ margin-top: 12px;
30
+ display: flex;
31
+ gap: 12px;
32
+ }
33
+
34
+ button {
35
+ padding: 14px 26px;
36
+ font-size: 18px;
37
+ font-weight: bold;
38
+ border-radius: 8px;
39
+ border: none;
40
+ background: #00ff99;
41
+ color: #000;
42
+ cursor: pointer;
43
+ }
44
+
45
+ button:hover {
46
+ background: #00d97e;
47
+ }
48
+ </style>
49
+
50
+ <!-- THREE.JS + LIBRER脥AS -->
51
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js"></script>
52
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/examples/js/controls/OrbitControls.js"></script>
53
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/examples/js/loaders/OBJLoader.js"></script>
54
+
55
  </head>
56
  <body>
 
 
 
 
 
57
 
58
+ <!-- BOTONES VISIBLES -->
59
+ <div id="ui-bar">
60
+ <button onclick="cameraFollow = true">Seguir Gusano</button>
61
+ <button onclick="cameraFollow = false">Control Libre</button>
62
+ </div>
63
+
64
+ <!-- CONTENEDOR DEL JUEGO (AGRANDADO) -->
65
+ <div id="game-container"></div>
66
+
67
+ <script>
68
+ // =======================================================
69
+ // === Three.js 3D Initialization ===
70
+ // =======================================================
71
+
72
+ let scene, camera, renderer, terrain, controls;
73
+ let wormMesh;
74
+ const keys = {};
75
+ let cameraFollow = true; // Activar o desactivar seguimiento autom谩tico
76
+
77
+ const container = document.getElementById("game-container");
78
+ const textureLoader = new THREE.TextureLoader();
79
+ const movementSpeed = 0.5;
80
+
81
+ function init() {
82
+
83
+ scene = new THREE.Scene();
84
+ scene.background = new THREE.Color(0x87ceeb);
85
+
86
+ camera = new THREE.PerspectiveCamera(
87
+ 75,
88
+ container.clientWidth / container.clientHeight,
89
+ 0.1,
90
+ 1000
91
+ );
92
+
93
+ camera.position.set(0, 50, 70);
94
+
95
+ renderer = new THREE.WebGLRenderer({ antialias: true });
96
+ renderer.setSize(container.clientWidth, container.clientHeight);
97
+
98
+ container.appendChild(renderer.domElement);
99
+
100
+ const ambientLight = new THREE.AmbientLight(0x404040, 3);
101
+ scene.add(ambientLight);
102
+
103
+ const directionalLight = new THREE.DirectionalLight(0xffffff, 2);
104
+ directionalLight.position.set(100, 100, 50);
105
+ scene.add(directionalLight);
106
+
107
+ createTerrain();
108
+
109
+ controls = new THREE.OrbitControls(camera, renderer.domElement);
110
+ controls.enableDamping = true;
111
+ controls.dampingFactor = 0.05;
112
+ controls.minDistance = 20;
113
+ controls.maxDistance = 150;
114
+
115
+ loadWormModel();
116
+
117
+ window.addEventListener("keydown", (e) => keys[e.key.toLowerCase()] = true);
118
+ window.addEventListener("keyup", (e) => keys[e.key.toLowerCase()] = false);
119
+
120
+ window.addEventListener("resize", onWindowResize);
121
+ }
122
+
123
+ // =======================================================
124
+ // === Terreno Procedural ===
125
+ // =======================================================
126
+
127
+ function createTerrain() {
128
+ const texture = textureLoader.load("grass_texture.jpg");
129
+
130
+ const size = 150, segments = 64;
131
+ const geometry = new THREE.PlaneGeometry(size, size, segments, segments);
132
+ geometry.rotateX(-Math.PI / 2);
133
+
134
+ const material = new THREE.MeshPhongMaterial({
135
+ map: texture,
136
+ side: THREE.DoubleSide
137
+ });
138
+
139
+ terrain = new THREE.Mesh(geometry, material);
140
+
141
+ const verts = geometry.attributes.position.array;
142
+ const maxH = 15;
143
+
144
+ for (let i = 0; i < verts.length; i += 3) {
145
+ const x = verts[i] / size;
146
+ const y = verts[i + 2] / size;
147
+
148
+ const height =
149
+ Math.sin(x * 10) * 0.5 +
150
+ Math.cos(y * 7) * 0.8 +
151
+ Math.sin((x + y) * 5) * 0.3;
152
+
153
+ verts[i + 1] = height * maxH;
154
+ }
155
+
156
+ geometry.computeVertexNormals();
157
+ scene.add(terrain);
158
+ }
159
+
160
+ // =======================================================
161
+ // === Modelo OBJ del gusano ===
162
+ // =======================================================
163
+
164
+ function loadWormModel() {
165
+ const objLoader = new THREE.OBJLoader();
166
+
167
+ objLoader.load("cascabel123.obj", (object) => {
168
+
169
+ const material = new THREE.MeshPhongMaterial({
170
+ color: 0x68e079,
171
+ shininess: 30
172
+ });
173
+
174
+ object.traverse((child) => {
175
+ if (child.isMesh) child.material = material;
176
+ });
177
+
178
+ wormMesh = object;
179
+ wormMesh.scale.set(10, 10, 10);
180
+ wormMesh.position.set(0, 5, 0);
181
+
182
+ scene.add(wormMesh);
183
+ });
184
+ }
185
+
186
+ // =======================================================
187
+ // === Movimiento ===
188
+ // =======================================================
189
+
190
+ function moveWorm() {
191
+ if (!wormMesh) return;
192
+
193
+ let moved = false;
194
+ const prev = wormMesh.position.clone();
195
+
196
+ if (keys["w"]) { wormMesh.position.z -= movementSpeed; wormMesh.rotation.y = 0; moved = true; }
197
+ if (keys["s"]) { wormMesh.position.z += movementSpeed; wormMesh.rotation.y = Math.PI; moved = true; }
198
+ if (keys["a"]) { wormMesh.position.x -= movementSpeed; wormMesh.rotation.y = Math.PI/2; moved = true; }
199
+ if (keys["d"]) { wormMesh.position.x += movementSpeed; wormMesh.rotation.y = -Math.PI/2; moved = true; }
200
+
201
+ if (cameraFollow && moved) {
202
+ const delta = wormMesh.position.clone().sub(prev);
203
+ camera.position.add(delta);
204
+ }
205
+ }
206
+
207
+ // =======================================================
208
+ // === Render Loop ===
209
+ // =======================================================
210
+
211
+ function animate() {
212
+ requestAnimationFrame(animate);
213
+
214
+ moveWorm();
215
+
216
+ if (controls) {
217
+ if (cameraFollow && wormMesh) {
218
+ controls.target.copy(wormMesh.position);
219
+ }
220
+ controls.update();
221
+ }
222
+
223
+ renderer.render(scene, camera);
224
+ }
225
+
226
+ // =======================================================
227
+ // === Resize ===
228
+ // =======================================================
229
+
230
+ function onWindowResize() {
231
+ camera.aspect = container.clientWidth / container.clientHeight;
232
+ camera.updateProjectionMatrix();
233
+ renderer.setSize(container.clientWidth, container.clientHeight);
234
+ }
235
+
236
+ init();
237
+ animate();
238
+ </script>
239
+
240
  </body>
241
+ </html>