-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMyScene.js
766 lines (583 loc) · 25.6 KB
/
MyScene.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
// Clases de la biblioteca
import * as THREE from './libs/three.module.js'
import Stats from './libs/Stats.js';
// Clases de mi proyecto
import {Link} from './Link.js'
import {NivelBosque} from './NivelBosque.js'
import {NivelBosque2} from './NivelBosque2.js'
import {NivelSecreto} from './NivelSecreto.js'
import {NivelMazmorra} from './NivelMazmorra.js'
import {NivelBoss} from './NivelBoss.js'
import {NivelMar} from './NivelMar.js'
import {NivelDesierto} from './NivelDesierto.js'
import {AttackSword} from './AttackSword.js'
import {Bomba} from './Bomba.js'
/// La clase fachada del modelo
/**
* Usaremos una clase derivada de la clase Scene de Three.js para llevar el control de la escena y de todo lo que ocurre en ella.
*/
class MyScene extends THREE.Scene {
constructor (myCanvas) {
super();
this.resolucion_altura = 1920
this.resolucion_anchura = 915
// Lo primero, crear el visualizador, pasándole el lienzo sobre el que realizar los renderizados.
this.renderer = this.createRenderer(myCanvas);
//creamos la informacion de fps
this.stats = new Stats();
this.stats.showPanel(0) ; // 0: fps, 1: ms, 2: mb, 3+: custom
document.body.appendChild( this.stats.dom );
//variable que cambia a false cuando el jugador pulsa cualquier tecla por primera vez
this.comienzo = true
this.fin=false
this.sonido_muerte=false
// Construimos los distinos elementos que tendremos en la escena
// Todo elemento que se desee sea tenido en cuenta en el renderizado de la escena debe pertenecer a esta. Bien como hijo de la escena (this en esta clase) o como hijo de un elemento que ya esté en la escena.
// Tras crear cada elemento se añadirá a la escena con this.add(variable)
this.createLights ();
// Tendremos una cámara con un control de movimiento con el ratón
this.createCamera ();
//el nivel en el que se comienza es en el de bosque 1
this.game_level = MyScene.MAR
//estado del juego
this.estado_juego = MyScene.START
this.texto
this.cuadro
this.crearNiveles();
this.crearPersonajes();
this.crearSonidos();
}
crearSonidos(){
const listener = new THREE.AudioListener();
// create a global audio source
const boss_sound = new THREE.Audio( listener );
// load a sound and set it as the Audio object's buffer
const audioLoader = new THREE.AudioLoader();
audioLoader.load( 'sounds/boss.mp3', function( buffer ) {
boss_sound.setBuffer( buffer );
boss_sound.setLoop( true );
boss_sound.setVolume( 0.5 );
});
this.boss_sound = boss_sound
const win_sound = new THREE.Audio( listener );
audioLoader.load( 'sounds/victoria.mp3', function( buffer ) {
win_sound.setBuffer( buffer );
win_sound.setLoop( false );
win_sound.setVolume( 0.5 );
});
this.win_sound = win_sound
const dead_sound = new THREE.Audio( listener );
audioLoader.load( 'sounds/morir.mp3', function( buffer ) {
dead_sound.setBuffer( buffer );
dead_sound.setLoop( false );
dead_sound.setVolume( 0.5 );
});
this.dead_sound = dead_sound
}
crearPersonajes(){
this.link = new Link(this);
this.add (this.link);
//link necesita tener iniciado el array de obstaculos segun el primer nivel
this.link.cargarObstaculos(this.bosque.devolverObstaculos())
this.link.cargarEnemigos(this.bosque.devolverEnemigos())
this.attack_sword = new AttackSword(this.link);
this.add(this.attack_sword);
this.attack_sword.cargarObstaculos(this.bosque.devolverObstaculos())
this.attack_sword.cargarEnemigos(this.bosque.devolverEnemigos())
}
createCamera () {
// Para crear una cámara le indicamos
// El ángulo del campo de visión en grados sexagesimales
// La razón de aspecto ancho/alto
// Los planos de recorte cercano y lejano
//this.camera.position.z = 24.75
var look = new THREE.Vector3 (101,20,29.75);
this.camera = new THREE.PerspectiveCamera(45, window.innerWidth / window.innerHeight, 0.1, 1000);
this.camera.position.set (0, 35,-5);
// Y hacia dónde mira
var look = new THREE.Vector3 (0,20,0);
// ,Y hacia dónde mira
//var look = new THREE.Vector3 (0,0,0);
this.camera.lookAt(look);
this.add (this.camera);
}
createLights () {
// Se crea una luz ambiental, evita que se vean complentamente negras las zonas donde no incide de manera directa una fuente de luz
// La luz ambiental solo tiene un color y una intensidad
// Se declara como var y va a ser una variable local a este método
// se hace así puesto que no va a ser accedida desde otros métodos
var ambientLight = new THREE.AmbientLight(0xccddee, 0.35);
// La añadimos a la escena
this.add (ambientLight);
// Se crea una luz focal que va a ser la luz principal de la escena
// La luz focal, además tiene una posición, y un punto de mira
// Si no se le da punto de mira, apuntará al (0,0,0) en coordenadas del mundo
// En este caso se declara como this.atributo para que sea un atributo accesible desde otros métodos.
this.spotLight = new THREE.SpotLight( 0xffffff, 1 );
this.spotLight.position.set( 60, 60, 40 );
this.add (this.spotLight);
}
createRenderer (myCanvas) {
// Se recibe el lienzo sobre el que se van a hacer los renderizados. Un div definido en el html.
// Se instancia un Renderer WebGL
var renderer = new THREE.WebGLRenderer();
// Se establece un color de fondo en las imágenes que genera el render
renderer.setClearColor(new THREE.Color(0xEEEEEE), 1.0);
// Se establece el tamaño, se aprovecha la totalidad de la ventana del navegador
renderer.setSize(window.innerWidth, window.innerHeight);
// La visualización se muestra en el lienzo recibido
$(myCanvas).append(renderer.domElement);
return renderer;
}
getCamera () {
// En principio se devuelve la única cámara que tenemos
// Si hubiera varias cámaras, este método decidiría qué cámara devuelve cada vez que es consultado
return this.camera;
}
setCameraAspect (ratio) {
// Cada vez que el usuario modifica el tamaño de la ventana desde el gestor de ventanas de
// su sistema operativo hay que actualizar el ratio de aspecto de la cámara
this.camera.aspect = ratio;
// Y si se cambia ese dato hay que actualizar la matriz de proyección de la cámara
this.camera.updateProjectionMatrix();
}
onWindowResize () {
// Este método es llamado cada vez que el usuario modifica el tamapo de la ventana de la aplicación
// Hay que actualizar el ratio de aspecto de la cámara
this.setCameraAspect (window.innerWidth / window.innerHeight);
// Y también el tamaño del renderizador
this.renderer.setSize (window.innerWidth, window.innerHeight);
}
quitarBomba() {
this.remove(this.bomba)
}
usarBomba(position) {
this.bomba = new Bomba()
this.bomba.position.x = position.x
this.bomba.position.y = position.y + 0.5
this.bomba.position.z = position.z
this.add(this.bomba)
this.link.bombas -= 1
this.bomba.explotando=true
switch(this.link.game_level) {
case MyScene.BOSQUE_1:
if((this.bomba.position.x <= 5.25) && (this.bomba.position.x >= -8.75) &&
((this.bomba.position.z == 19.25) || (this.bomba.position.z == 17.5))) {
for(var i = 0; i < this.link.array_obstaculos.length; i++) {
if(this.link.array_obstaculos[i]['name'] == "roca") {
this.link.array_obstaculos[i].visible = false
this.link.array_obstaculos[i+1].visible = false
this.link.array_obstaculos[i+2].visible = false
this.link.array_obstaculos[i+3].visible = false
this.link.array_obstaculos.splice(i,4)
}
}
}
break;
}
// create an AudioListener and add it to the camera
const listener = new THREE.AudioListener();
this.camera.add( listener );
// create a global audio source
const sound = new THREE.Audio( listener );
// load a sound and set it as the Audio object's buffer
const audioLoader = new THREE.AudioLoader();
audioLoader.load( 'sounds/explosion.ogg', function( buffer ) {
sound.setBuffer( buffer );
sound.setLoop( false );
sound.setVolume( 0.5 );
sound.play();
});
}
changeCamera(game_level){
//Metodo para cambiar la camara de posicion
//this.camera.
switch(game_level){
case MyScene.BOSQUE_1:
this.camera.position.set (0, this.camera.position.y,-5);
//this.camera.position.x = 0
var look = new THREE.Vector3 (0,20,0);
this.camera.lookAt(look);
this.estado_juego = MyScene.START
break;
case MyScene.BOSQUE_2:
this.camera.position.set (-56, this.camera.position.y,-5);
//this.camera.position.x = -56
var look = new THREE.Vector3 (-56,20,0);
this.camera.lookAt(look);
this.estado_juego = MyScene.START
break;
case MyScene.DESIERTO:
this.camera.position.set (-110.25, this.camera.position.y,-5);
//this.camera.position.x = -56
var look = new THREE.Vector3 (-110.25,20,0);
this.camera.lookAt(look);
this.estado_juego = MyScene.START
break;
case MyScene.MAZMORRA:
this.camera.position.set (-166.25, this.camera.position.y,-5);
//this.camera.position.x = -56
var look = new THREE.Vector3 (-166.25,20,0);
this.camera.lookAt(look);
this.estado_juego = MyScene.START
break;
case MyScene.BOSS:
this.camera.position.set (-224, this.camera.position.y,-5);
//this.camera.position.x = -56
var look = new THREE.Vector3 (-224,20,0);
this.camera.lookAt(look);
this.estado_juego = MyScene.START
break;
case MyScene.MAR:
this.camera.position.set (-56, this.camera.position.y,24.75);
//this.camera.position.z = 24.75
var look = new THREE.Vector3 (-56,20,29.75);
this.camera.lookAt(look);
this.estado_juego = MyScene.START
break;
case MyScene.SECRETA:
this.camera.position.set (this.camera.position.x, this.camera.position.y,24.75);
//this.camera.position.z = 24.75
var look = new THREE.Vector3 (0,20,29.75);
this.camera.lookAt(look);
this.estado_juego = MyScene.START
break;
}
}
onKeyPressed(event){
var key = event.which || event.keyCode
var key_int = event.which || event.keyCode
//se admite tanto w como W, por eso se hace lowerCase de la key
key = String.fromCharCode(key).toLowerCase()
if(this.comienzo){
// create an AudioListener and add it to the camera
const listener = new THREE.AudioListener();
this.add( listener );
// create a global audio source
const sound = new THREE.Audio( listener );
// load a sound and set it as the Audio object's buffer
const audioLoader = new THREE.AudioLoader();
audioLoader.load( 'sounds/zelda.mp3', function( buffer ) {
sound.setBuffer( buffer );
sound.setLoop( true );
sound.setVolume( 0.5 );
sound.play();
});
this.comienzo = false
this.sound = sound
}
if(this.estado_juego == MyScene.DEAD && key_int == 13){
window.location.reload()
}
if(this.estado_juego == MyScene.WIN && key_int == 13){
window.location.reload()
}
if(this.estado_juego == MyScene.TEXTO && key_int == 13) {
document.getElementById("message").style.display = "none";
this.estado_juego = MyScene.START
}
if(this.estado_juego != MyScene.CHANGE_CAMERA && this.estado_juego != MyScene.DEAD && this.estado_juego != MyScene.TEXTO && this.estado_juego != MyScene.WIN) {
if (key == 'w' ){
if(this.link.moverLink(MyScene.LOOK_AT_UP)){
this.link.actualizarInfoPosicion(MyScene.LOOK_AT_UP)
}
this.link.comprobarMovimientoColisionEnemigo()
}
if (key == 'a'){
if(this.link.moverLink(MyScene.LOOK_AT_LEFT)){
this.link.actualizarInfoPosicion(MyScene.LOOK_AT_LEFT)
}
this.link.comprobarMovimientoColisionEnemigo()
}
if (key == 'd'){
if(this.link.moverLink(MyScene.LOOK_AT_RIGHT)){
this.link.actualizarInfoPosicion(MyScene.LOOK_AT_RIGHT)
}
this.link.comprobarMovimientoColisionEnemigo()
}
if (key == 's'){
if(this.link.moverLink(MyScene.LOOK_AT_DOWN)){
this.link.actualizarInfoPosicion(MyScene.LOOK_AT_DOWN)
}
this.link.comprobarMovimientoColisionEnemigo()
}
if (key_int == 32){
this.attack_sword.lanzarEspada(this.link.orientacion)
}
if(this.link.bombas > 0) {
if (key == 'e'){
this.usarBomba(this.link.position)
}
}
if(this.link.espada_roja){
this.attack_sword.cambiarAEspadaRoja()
this.link.espada_roja = false
}
}
if(this.estado_juego != MyScene.DEAD){
this.comprobarCambioNivel()
}
}
comprobarCambioNivel(){
//comprobar si hay cambio de estado de nivel
//this.link.comprobar_cambio_nivel()
//cambia el nivel tambien en Myscene
//si cambia de nivel, hay que hacerle el cambio de la camara
switch (this.link.game_level){
case MyScene.BOSQUE_1:
if(this.link.posPj_x == -28 && this.link.posPj_y == 0 && (this.link.posPj_z == 0 ||
this.link.posPj_z == 1.75 || this.link.posPj_z == 3.5 || this.link.posPj_z == 5.25)){
this.estado_juego = MyScene.CHANGE_CAMERA
this.link.game_level = MyScene.BOSQUE_2
this.game_level = MyScene.BOSQUE_2
this.changeCamera(MyScene.BOSQUE_2)
//cargas los obstaculos del mundo que se cambia
this.link.cargarObstaculos(this.bosque2.devolverObstaculos())
this.link.cargarEnemigos(this.bosque2.devolverEnemigos())
this.attack_sword.cargarObstaculos(this.bosque2.devolverObstaculos())
this.attack_sword.cargarEnemigos(this.bosque2.devolverEnemigos())
}
if((this.link.posPj_x == 0 ||this.link.posPj_x == -1.75 || this.link.posPj_x == -3.5 || this.link.posPj_x == -5.25 || this.link.posPj_x == 1.75)
&& this.link.posPj_y == 0 && this.link.posPj_z == 22.75){
this.estado_juego = MyScene.CHANGE_CAMERA
this.link.game_level = MyScene.SECRETA
this.game_level = MyScene.SECRETA
this.changeCamera( MyScene.SECRETA)
this.link.cargarObstaculos(this.secreto.devolverObstaculos())
this.attack_sword.cargarObstaculos(this.secreto.devolverObstaculos())
}
break;
case MyScene.BOSQUE_2:
if(this.link.posPj_x == -28 && this.link.posPj_y == 0 && (this.link.posPj_z == 0 ||
this.link.posPj_z == 1.75 || this.link.posPj_z == 3.5 || this.link.posPj_z == 5.25)){
this.estado_juego = MyScene.CHANGE_CAMERA
this.link.game_level = MyScene.BOSQUE_1
this.game_level = MyScene.BOSQUE_1
this.changeCamera(MyScene.BOSQUE_1)
this.link.cargarObstaculos(this.bosque.devolverObstaculos())
this.link.cargarEnemigos(this.bosque.devolverEnemigos())
this.attack_sword.cargarObstaculos(this.bosque.devolverObstaculos())
this.attack_sword.cargarEnemigos(this.bosque.devolverEnemigos())
}
if(this.link.posPj_x == -82.25 && this.link.posPj_y == 0 && this.link.posPj_z == 0){
this.estado_juego = MyScene.CHANGE_CAMERA
this.link.game_level = MyScene.DESIERTO
this.game_level = MyScene.DESIERTO
this.changeCamera(MyScene.DESIERTO)
this.link.cargarObstaculos(this.desierto.devolverObstaculos())
this.link.cargarEnemigos(this.desierto.devolverEnemigos())
this.attack_sword.cargarObstaculos(this.desierto.devolverObstaculos())
this.attack_sword.cargarEnemigos(this.desierto.devolverEnemigos())
}
if(this.link.posPj_x == -64.75 && this.link.posPj_y == 0 && this.link.posPj_z == 22.75){
this.estado_juego = MyScene.CHANGE_CAMERA
this.link.game_level = MyScene.MAR
this.game_level = MyScene.MAR
this.changeCamera( MyScene.MAR)
this.link.cargarObstaculos(this.mar.devolverObstaculos())
this.link.cargarEnemigos(this.mar.devolverEnemigos())
this.attack_sword.cargarObstaculos(this.mar.devolverObstaculos())
this.attack_sword.cargarEnemigos(this.mar.devolverEnemigos())
}
break;
case MyScene.MAR:
if(this.link.posPj_x == -64.75 && this.link.posPj_y == 0 && this.link.posPj_z == 22.75){
this.estado_juego = MyScene.CHANGE_CAMERA
this.link.game_level = MyScene.BOSQUE_2
this.game_level = MyScene.BOSQUE_2
this.changeCamera( MyScene.BOSQUE_2)
this.link.cargarObstaculos(this.bosque2.devolverObstaculos())
this.link.cargarEnemigos(this.bosque2.devolverEnemigos())
this.attack_sword.cargarObstaculos(this.bosque2.devolverObstaculos())
this.attack_sword.cargarEnemigos(this.bosque2.devolverEnemigos())
}
break;
case MyScene.DESIERTO:
if(this.link.posPj_x == -82.25 && this.link.posPj_y == 0 && this.link.posPj_z == 0){
this.estado_juego = MyScene.CHANGE_CAMERA
this.link.game_level = MyScene.BOSQUE_2
this.game_level = MyScene.BOSQUE_2
this.changeCamera(MyScene.BOSQUE_2)
this.link.cargarObstaculos(this.bosque2.devolverObstaculos())
this.link.cargarEnemigos(this.bosque2.devolverEnemigos())
this.attack_sword.cargarObstaculos(this.bosque2.devolverObstaculos())
this.attack_sword.cargarEnemigos(this.bosque2.devolverEnemigos())
}
if(this.link.posPj_x == -138.25 && this.link.posPj_y == 0 && this.link.posPj_z == 0){
this.estado_juego = MyScene.CHANGE_CAMERA
this.link.game_level = MyScene.MAZMORRA
this.game_level = MyScene.MAZMORRA
this.changeCamera(MyScene.MAZMORRA)
this.link.cargarObstaculos(this.mazmorra.devolverObstaculos())
this.link.cargarEnemigos(this.mazmorra.devolverEnemigos())
this.attack_sword.cargarObstaculos(this.mazmorra.devolverObstaculos())
this.attack_sword.cargarEnemigos(this.mazmorra.devolverEnemigos())
}
break;
case MyScene.MAZMORRA:
if(this.link.posPj_x == -138.25 && this.link.posPj_y == 0 && this.link.posPj_z == 0){
this.estado_juego = MyScene.CHANGE_CAMERA
this.link.game_level = MyScene.DESIERTO
this.game_level = MyScene.DESIERTO
this.changeCamera(MyScene.DESIERTO)
this.link.cargarObstaculos(this.desierto.devolverObstaculos())
this.link.cargarEnemigos(this.desierto.devolverEnemigos())
this.attack_sword.cargarObstaculos(this.desierto.devolverObstaculos())
this.attack_sword.cargarEnemigos(this.desierto.devolverEnemigos())
}
if(this.link.posPj_x == -196 && this.link.posPj_y == 0 && this.link.posPj_z == 0){
this.sound.pause()
this.boss_sound.play()
this.estado_juego = MyScene.CHANGE_CAMERA
this.link.game_level = MyScene.BOSS
this.game_level = MyScene.BOSS
this.changeCamera(MyScene.BOSS)
this.link.cargarObstaculos(this.boss.devolverObstaculos())
this.link.cargarEnemigos(this.boss.devolverEnemigos())
this.attack_sword.cargarObstaculos(this.boss.devolverObstaculos())
this.attack_sword.cargarEnemigos(this.boss.devolverEnemigos())
}
break;
case MyScene.BOSS:
if(this.link.posPj_x == -196 && this.link.posPj_y == 0 && this.link.posPj_z == 0){
this.boss_sound.pause()
this.sound.play()
this.estado_juego = MyScene.CHANGE_CAMERA
this.link.game_level = MyScene.MAZMORRA
this.game_level = MyScene.MAZMORRA
this.changeCamera(MyScene.MAZMORRA)
this.link.cargarObstaculos(this.mazmorra.devolverObstaculos())
this.link.cargarEnemigos(this.mazmorra.devolverEnemigos())
this.attack_sword.cargarObstaculos(this.mazmorra.devolverObstaculos())
this.attack_sword.cargarEnemigos(this.mazmorra.devolverEnemigos())
}
break;
case MyScene.SECRETA:
//solo puedes acceder a esta posicion se rompes las rocas y te acercas despues
if((this.link.posPj_x == 0 ||this.link.posPj_x == -1.75 || this.link.posPj_x == -3.5 || this.link.posPj_x == -5.25 || this.link.posPj_x == 1.75)
&& this.link.posPj_y == 0 && this.link.posPj_z == 22.75){
this.estado_juego = MyScene.CHANGE_CAMERA
this.link.game_level = MyScene.BOSQUE_1
this.game_level = MyScene.BOSQUE_1
this.changeCamera(MyScene.BOSQUE_1)
this.link.cargarObstaculos(this.bosque.devolverObstaculos())
this.link.cargarEnemigos(this.bosque.devolverEnemigos())
this.attack_sword.cargarObstaculos(this.bosque.devolverObstaculos())
this.attack_sword.cargarEnemigos(this.bosque.devolverEnemigos())
}
break;
}
}
bombaCogida() {
this.estado_juego = MyScene.TEXTO
document.getElementById("message").style.display = "block";
this.texto = document.getElementById("message").innerHTML = "<p>Nuevo Objeto: Bomba </p><p><p><p><p>Pulsa la 'e' para usar la bomba y destruir un muro de rocas </p><p><p><p><p>Pulsa 'Enter' para continuar</p>"
}
espadaCogida() {
this.estado_juego = MyScene.TEXTO
this.cuadro = document.getElementById("message").style.display = "block";
this.texto = document.getElementById("message").innerHTML = "<p>Nuevo Objeto: Espada </p><p><p><p><p>El daño de tu espada a aumentado x2 </p><p><p><p><p>Pulsa 'Enter' para continuar</p>"
}
terminarJuego(){
this.estado_juego = MyScene.DEAD
document.getElementById("message").style.display = "block";
document.getElementById("message").innerHTML = "<p>Has muerto :(</p><p><p><p><p>Pulsa 'Enter' para reinicar</p>"
this.sound.pause()
this.boss_sound.pause()
if(!this.sonido_muerte) {
this.sonido_muerte=true
this.dead_sound.play()
}
}
terminarJuegoGanar(){
this.estado_juego = MyScene.WIN
document.getElementById("message").style.display = "block";
document.getElementById("message").innerHTML = "<p>Has GANADO :)</p><p><p><p><p>Pulsa 'Enter' para reinicar</p>"
this.sound.pause()
this.boss_sound.pause()
if(!this.fin) {
this.win_sound.play()
this.fin=true
}
}
update () {
this.stats.begin();
var fin_juego = this.link.comprobarFinJuego()
if(fin_juego){
this.terminarJuego();
}
if(this.boss.samu.samu.vida <= 0){
//this.boss.samu.change_attack_visibility()
this.terminarJuegoGanar();
}
if(this.estado_juego != MyScene.DEAD){
// Se actualiza el resto del modelo
this.link.update();
this.attack_sword.update();
this.bosque.update();
this.bosque2.update()
this.desierto.update();
this.mar.update();
this.boss.update();
}
// Le decimos al renderizador "visualiza la escena que te indico usando la cámara que te estoy pasando"
this.renderer.render (this, this.getCamera());
// Este método debe ser llamado cada vez que queramos visualizar la escena de nuevo.
// Literalmente le decimos al navegador: "La próxima vez que haya que refrescar la pantalla, llama al método que te indico".
// Si no existiera esta línea, update() se ejecutaría solo la primera vez.
requestAnimationFrame(() => this.update())
if(this.bomba) {
if(this.bomba.explotando) {
this.bomba.update()
}
}
this.stats.end();
}
crearNiveles(){
this.resolucion_altura
this.bosque = new NivelBosque(this.resolucion_altura, this.resolucion_anchura)
this.add(this.bosque)
this.bosque2 = new NivelBosque2(this.resolucion_altura, this.resolucion_anchura)
this.add(this.bosque2)
this.desierto = new NivelDesierto()
this.add(this.desierto)
this.secreto = new NivelSecreto(this.resolucion_altura, this.resolucion_anchura)
this.add(this.secreto)
this.mazmorra = new NivelMazmorra(this.resolucion_altura, this.resolucion_anchura)
this.add(this.mazmorra)
this.boss = new NivelBoss(this.resolucion_altura, this.resolucion_anchura)
this.add(this.boss)
this.mar = new NivelMar(this.resolucion_altura, this.resolucion_anchura)
this.add(this.mar)
}
}
/* ESTADOS DEL JUEGO */
MyScene.NO_START = 0;
MyScene.START = 1;
MyScene.DEAD = 2;
MyScene.CHANGE_CAMERA = 3;
MyScene.WIN = 4;
MyScene.TEXTO = 5;
/* ESTADOS ORIENTACION MUÑECO */
MyScene.LOOK_AT_UP = 5;
MyScene.LOOK_AT_DOWN = 6;
MyScene.LOOK_AT_RIGHT = 7;
MyScene.LOOK_AT_LEFT = 8;
/*ESTADOS NIVEL EN QUE SE ENCUENTRA EL PJ*/
MyScene.BOSQUE_1 = 15
MyScene.BOSQUE_2 = 16
MyScene.MAR = 17
MyScene.DESIERTO = 18
MyScene.MAZMORRA = 19
MyScene.BOSS = 20
MyScene.SECRETA = 21
/// La función main
$(function () {
// Se instancia la escena pasándole el div que se ha creado en el html para visualizar
var scene = new MyScene("#WebGL-output");
// Se añaden los listener de la aplicación. En este caso, el que va a comprobar cuándo se modifica el tamaño de la ventana de la aplicación.
window.addEventListener ("resize", () => scene.onWindowResize());
// Se añaden los listener de la aplicación. En este caso, el que va a comprobar cuándo se pulsa una tecla
window.addEventListener ("keypress", (event) => scene.onKeyPressed(event));
scene.update();
});