forked from ohanoch/cgv_game
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.html
697 lines (566 loc) · 23.3 KB
/
Main.html
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
<!DOCTYPE html>
<head>
<link rel="stylesheet" type="text/css" href="stylesheet.css"> <!-- CSS -->
<meta charset="UTF-8">
<title>_alpha_</title>
<style> body { margin: 0px 0px 0px 0px; } canvas { width: 100%; height: 100% } </style>
<!-- <iframe src="starwars-gh-pages/index.html" class="frame" ></iframe> -->
</head>
<audio id="xyz" src="sounds/haha.wav" preload="auto"></audio>
<script src="libs\three.js"></script>
<script src="libs\OrbitControls.js"></script>
<script src="libs\stats.min.js"></script>
<script src="libs\OBJLoader.js"></script>
<script src="libs\MTLLoader.js"></script>
<script src="libs\threex.cubecamera.js"></script>
<script src="libs\threex.atmospherematerial.js"></script>
<script src="libs\threex.atmospherematerialdatgui.js"></script>
<script src="libs\threex.dilategeometry.js"></script>
<script src="libs\threex.geometricglowmesh.js"></script>
<script src="libs\GeometryUtils.js"></script>
<script src="libs\BendModifier.js"></script>
<script src="libs\dat.gui.min.js"></script>
<script src="libs\CSS3DRenderer.js"></script>
<script src="libs\THREEx.WindowResize.js"></script>
<script src="src\classes\level.js"></script>
<script src="src\classes\alpha.js"></script>
<script src="src\classes\map.js"></script>
<script src="src\classes\menu.js"></script>
<script src="src\classes\powerup.js"></script>
<script src="src\classes\collectible.js"></script>
<script src="src\render.js"></script>
<script src="src\createLevels.js"></script>
<script src="src\mouseKeyboard.js"></script>
<script src="src\createWorldFunctions.js"></script>
<script src="src\death.js"></script>
<script src="src\menuFunctions.js"></script>
<script src="src\collisions.js"></script>
<script src="src\fuckingText.js"></script>
<script src="src\customSubroutines.js"></script>
<script>
"use strict";
var STARTING_LIVES = 3;
var currLevel = 3; //level variable mostly for display purposes at the moment
var level;
//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< G L O B A L V A R I A B L E S >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
/* General mechanics variables */
var canvas, renderer, scene, mainCamera; // Standard three.js requirements.
var container, stats;
var minimapCamera; //minimap variables
var controls; // An OrbitControls object that is used to implement
// rotation of the scene using the mouse. (It actually rotates
// the camera around the scene.)
var listener, crashSound, playingSound, pauseSound; //sound variables
/* flags for different instances */
var fullscreen = false;
var animating = false; // Set to true when an animation is in progress.
var alpha_centered =true; // used to recenter alpha avater after doing a rotation animation
var keys = []; // records current keys being pressed
var resetCameraFlag = false // flag to reset the camera position to original position
var jumping = false; // whether player is jumping or not
var alphaDone = false;
var mapDone = false;
var score = 0;
var lives = STARTING_LIVES;
var collectibleCount = 0;
var activePowerups = [];
var crot = Math.PI; // iterator for doing object rotation animation
var mixer = null; // The object that animates the model, of type THREE.AnimationMixer
var mute = false;
var frameNumber = 0;
/* Global object variables */
var player = new THREE.Object3D();
var alpha; // player stats tracking + model object
var worldMap; // make global so it can be accessed by collision function
/* Global object arrays */
var menusArr = {};
var collideMeshArray = []; // array to store all collidable mesh's (buildings + items)
var powerups = []; // items providing certain powerups or "boosts" to the player for a short time when picked up
var collectibles = []; // the items that the player needs to collect in order to progress to the next level
/* text sculputure*/
var discoBall;
var sculpt;
var joshSucks; // he does
// for the text; there is no better way, sorry.
var textMesh1;
var font;
var text;
var text_height;
var text_size;
var curveSegments;
var text_object_container;
var cubeCamera; // for dynamic reflections
var reflection_on_off; //turn cubeCam on or off
//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< CUTSCENE >>>>>>>>>>>>>>>>>>>>>>>>>>>>>
var cutscenePlaying = true;
var cutscene = new THREE.Scene();
// var cutsceneCamera = new THREE.PerspectiveCamera(30, window.innerWidth/window.innerHeight, 0.1, 100);
var SCREEN_WIDTH = window.innerWidth, SCREEN_HEIGHT = window.innerHeight;
var VIEW_ANGLE = 45, ASPECT = SCREEN_WIDTH / SCREEN_HEIGHT, NEAR = 0.1, FAR = 20000;
var cutsceneCamera =new THREE.PerspectiveCamera( VIEW_ANGLE, ASPECT, NEAR, FAR);
// custom global variables
var video, videoImage, videoImageContext, videoTexture;
// // Plane for text
// var planeMaterial = new THREE.MeshBasicMaterial({color: 0x000000, opacity: 0.1, side: THREE.DoubleSide });
// var planeWidth = 360;
// var planeHeight = 120;
// var planeGeometry = new THREE.PlaneGeometry( planeWidth, planeHeight );
// var planeMesh= new THREE.Mesh( planeGeometry, planeMaterial );
// planeMesh.position.y += planeHeight/2;
// // add it to the standard (WebGL) scene
// cutscene.add(planeMesh);
///////////
// VIDEO //
///////////
// create the video element
video = document.createElement( 'video' );
// video.id = 'video';
// video.type = ' video/ogg; codecs="theora, vorbis" ';
video.src = "videos/sintel.ogv";
video.load(); // must call after setting/changing source
video.play();
// alternative method --
// create DIV in HTML:
// <video id="myVideo" autoplay style="display:none">
// <source src="videos/sintel.ogv" type='video/ogg; codecs="theora, vorbis"'>
// </video>
// and set JS variable:
// video = document.getElementById( 'myVideo' );
videoImage = document.createElement( 'canvas' );
videoImage.width = 480;
videoImage.height = 204;
videoImageContext = videoImage.getContext( '2d' );
// background color if no video present
videoImageContext.fillStyle = 'red';
videoImageContext.fillRect( 0, 0, videoImage.width, videoImage.height );
videoTexture = new THREE.Texture( videoImage );
videoTexture.minFilter = THREE.LinearFilter;
videoTexture.magFilter = THREE.LinearFilter;
var movieMaterial = new THREE.MeshBasicMaterial( { map: videoTexture, overdraw: true, side:THREE.DoubleSide } );
// the geometry on which the movie will be displayed;
// movie image will be scaled to fit these dimensions.
var movieGeometry = new THREE.PlaneGeometry( 240, 100, 4, 4 );
var movieScreen = new THREE.Mesh( movieGeometry, movieMaterial );
movieScreen.position.set(0,50,0);
// movieScreen.rotateX(-Math.PI/3);
cutscene.add(movieScreen);
cutsceneCamera.position.set(0,50,200);
cutsceneCamera.lookAt(movieScreen.position);
var cutsceneFrames = 0;
// var rendererCSS;
// // create a new scene to hold CSS
// var cssScene = new THREE.Scene();
// // create the iframe to contain webpage
// var element = document.createElement('iframe')
// // webpage to be loaded into iframe
// element.src = "starwars-gh-pages/index.html";
// // width of iframe in pixels
// var elementWidth = 1024;
// // force iframe to have same relative dimensions as planeGeometry
// var aspectRatio = planeHeight / planeWidth;
// var elementHeight = elementWidth * aspectRatio;
// element.style.width = elementWidth + "px";
// element.style.height = elementHeight + "px";
// // create a CSS3DObject to display element
// var cssObject = new THREE.CSS3DObject( element );
// // synchronize cssObject position/rotation with planeMesh position/rotation
// cssObject.position.set(planeMesh.position);
// cssObject.rotation.set(planeMesh.rotation);
// // resize cssObject to same size as planeMesh (plus a border)
// var percentBorder = 0.05;
// cssObject.scale.x /= (1 + percentBorder) * (elementWidth / planeWidth);
// cssObject.scale.y /= (1 + percentBorder) * (elementWidth / planeWidth);
// cssScene.add(cssObject);
// // create a renderer for CSS
// rendererCSS = new THREE.CSS3DRenderer();
// rendererCSS.setSize( window.innerWidth, window.innerHeight );
// rendererCSS.domElement.style.position = 'absolute';
// rendererCSS.domElement.style.top = 0;
// rendererCSS.domElement.style.margin = 0;
// rendererCSS.domElement.style.padding = 0;
// document.body.appendChild( rendererCSS.domElement );
// // when window resizes, also resize this renderer
// THREEx.WindowResize(rendererCSS, cutsceneCamera);
// renderer.domElement.style.position = 'absolute';
// renderer.domElement.style.top = 0;
// // make sure original renderer appears on top of CSS renderer
// renderer.domElement.style.zIndex = 1;
// rendererCSS.domElement.appendChild( renderer.domElement );
// var loadingScreen = {
// scene: new THREE.Scene(),
// camera: new THREE.PerspectiveCamera(30, window.innerWidth/window.innerHeight, 0.1, 100),
// box: new THREE.Mesh(
// new THREE.BoxGeometry(0.5,0.5,0.5),
// new THREE.MeshBasicMaterial({ color:0x4444ff })
// )
// };
// var RESOURCES_LOADED = false;
/////////////////////////////////////////////
/////////////////////////////////////////////
// for menu class
//var menu = new Menu(ALPHA_CAMERA_DISTANCE * 2, "textures/skyboxes/tantolunden5/", "sprites/buttons/");
//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< I N I T I A L I S A T I O N F U N C T I O N S >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
/* /////////////////////////////////////////////////////////////
Creates the world map, lights, cameras, player and collectibles and powerups.
Called by restartGame and init.
INPUT: none
OUTPUT: none
*//////////////////////////////////////////////////////////////
function createWorld() {
renderer.setClearColor("black"); // Background color for scene.
scene = new THREE.Scene();
var fogColour = new THREE.Color(level.fogColour);
scene.fog = new THREE.Fog(fogColour, level.alphaCameraDistance * 15, level.alphaCameraDistance * 20);
scene.add(player);
createMenus();
// -------------------------------------- MAKE MAIN CAMERA -------------------------------------
mainCamera = new THREE.PerspectiveCamera(
30,
window.innerWidth/window.innerHeight,
0.1,
level.alphaCameraDistance * 20
);
mainCamera.position.z = level.alphaCameraDistance;
player.add(mainCamera);
// -------------------------------------- MAKE SOUND -------------------------------------
// create an AudioListener and add it to the camera
listener = new THREE.AudioListener();
mainCamera.add( listener );
// create a global audio source
crashSound = new THREE.Audio( listener );
playingSound = new THREE.Audio( listener );
pauseSound = new THREE.Audio( listener );
addSounds();
//-------------------------------------------- LIGHTING ------------------------------------------------
createRandomLights();
var viewLight = new THREE.PointLight(level.alphaLightColour, 1);
player.add(viewLight);
viewLight.position.z = level.alphaCameraDistance;
//------------------------------------------ MINIMAP ----------------------------------------------
minimapCamera = new THREE.OrthographicCamera( // Orthographic camera does not change according to distance, which is what we want
window.innerHeight / -5, // Left
window.innerHeight / 5, // Right
window.innerHeight / 5, // Top
window.innerHeight / -5, // Bottom
-3 * level.atmosphereHeight, // Near
10000 ); // Far
minimapCamera.up = new THREE.Vector3(0,0,-1); // COMMENT
minimapCamera.lookAt( new THREE.Vector3(0,-1,0) ); // COMMENT
scene.add(minimapCamera); // Add minimap camera to scene
//---------------------------------- CREATE THE WORLD -------------------------------------------
worldMap = new Map(level.worldWidth, level.worldDepth, level.atmosphereHeight, level.floorTextureURL, level.backgroundURL, level.buildingModelURLs) //width, height, atmosphereHight, textureURL, skyboxDirectory
scene.add(worldMap.floor);
scene.background = worldMap.background;
scene.add(worldMap.atmosphere);
//add buildings to scene
worldMap.createBuildings(level.mapBuildingRatio);
for (var i = 0; i < worldMap.buildings.length; i++){
scene.add(worldMap.buildings[i]);
}
//---------------------------------- Dynamic Sculpture -------------------------------------------
// TODO: try cubecamera on lab computers
// resources: http://learningthreejs.com/blog/2014/05/12/live-cube-maps-reflections-in-your-three-dot-js-game-with-threex-dot-cubecamera/
sculpt = new THREE.Object3D(); // Sculpture container
joshSucks = new THREE.Object3D(); // Sphere Sculpture object
// Make a reflective sphere (only reflects skybox, at the moment)
var geometry = new THREE.SphereGeometry(5, 32, 16);
var material = new THREE.MeshPhongMaterial({
color : 0xffffff,
envMap : scene.background
});
discoBall = new THREE.Mesh(geometry, material);
discoBall.position.set(0,0,0); // centre obj coords of sphere
joshSucks.add(discoBall);
//diffuse stick
var length = 8, width = 8;
var shape = new THREE.Shape();
shape.moveTo( 0,0 );
shape.lineTo( 0, width );
shape.lineTo( length, width );
shape.lineTo( length, 0 );
shape.lineTo( 0, 0 );
var extrudeSettings = {
steps: 2,
amount: 100,
bevelEnabled: true,
bevelThickness: 1,
bevelSize: 1,
bevelSegments: 1
};
var geometry = new THREE.ExtrudeGeometry( shape, extrudeSettings );
var material = new THREE.MeshStandardMaterial({color: 0x517a, roughness: 0.6, })
var stick = new THREE.Mesh( geometry, material ) ;
stick.rotation.x=Math.PI/2;
stick.position.set(-1.5,10,0);
///////////
//////////////////////////////////////////////////////////////////////////////////
// add text //
/// ///////////////////////////////////////////////////////////////////////////////
text = "JOSH SUCKS";
text_height = 0.5;
text_size = 2;
curveSegments = 4;
font = undefined;
text_object_container = new THREE.Group();
text_object_container.position.set(-8,0,7); // -8,0,7 is the magic tuple to get the text to rotate around the sphere.
loadFont();
joshSucks.add(text_object_container);
joshSucks.children[1].rotateZ(0.2);
// joshSucks.add( stick );
// var temp_test = player.position.clone();
joshSucks.position.set(1,12,3.8); //center the sphere
///// cube cam for reflections
cubeCamera = new THREEx.CubeCamera(discoBall);
cubeCamera.update(renderer, scene);
material.envMap = cubeCamera.textureCube;
////////////////////////////////////////
sculpt.add(joshSucks);
sculpt.add(stick);
sculpt.scale.set(5,5,5);
sculpt.position.set(0,5,0);
scene.add(sculpt);
scene.add(cubeCamera.object3d); // good enough
//----------------------------------- CREATE THE PLAYER --------------------------------------------
// alpha is created by modelLoader function and added to player
var loader = new THREE.JSONLoader(); // create loader for .js models
loader.load(level.alphaModelURL, modelLoader); // load model and call model_loader
//------------------------------------- CREATE POWERUPS -----------------------------------------------
createPowerups();
//--------------------------------------- CREATE COLLECTIBLES ------------------------------------------------
createCollectibles(level.collectibleURL);
} // end function createWorld()
/*//////////////////////////////////////////////////////////////////////////
Model Loader function for alpha object. Creates alpha, places it in the scene and sets up animation
Callback function for JSON loader in createWorld()
INPUT: THREE geometry and material objects
OUTPUT: none
///////////////////////////////////////////////////////////////////////////*/
function modelLoader(geometry, materials) {
var material = new THREE.MeshLambertMaterial( {
vertexColors: THREE.FaceColors, // use colors from the geometry
morphTargets: true // for animation
});
alpha = new Alpha(geometry,material, 1); // create alpha object
// TRANSFORMS
alpha.geometry.computeBoundingSphere();
alpha.scale.set(
500/Math.pow(alpha.geometry.boundingSphere.radius,2),
500/Math.pow(alpha.geometry.boundingSphere.radius,2),
500/Math.pow(alpha.geometry.boundingSphere.radius,2),
);
alpha.position.set(0,0,0);
alpha.rotateY(Math.PI);
alpha.castShadow = true;
player.add(alpha); // add alpha to player
player.translateY(10); // move player so that alpha doesn't crash on game start
alpha.geometry.computeBoundingBox(); // Get bounding box for model, for doing collisions
alphaDone = true;
alpha.startup();
// ANIMATION STUFF
mixer = new THREE.AnimationMixer( alpha );
var clip = THREE.AnimationClip.CreateFromMorphTargetSequence( 'motion', geometry.morphTargets, 30 );
var animationAction = mixer.clipAction(clip);
animationAction.setDuration(1);
animationAction.play();
render();
}
// END OF INITIALISATION
/*/////////////////////////////////////////////////////////////////////////////////
Updates frame by moving player, moving minimap camera, crashing player if they move above atmosphere or below floor, update animations, increment score and check for collisions
Called by doFrame
INPUT: none
OUTPUT: none
//////////////////////////////////////////////////////////////////////////////////*/
function updateForFrame() {
frameNumber++;
// This block runs while resources are loading.
// if( loading === true ){
// // //console.log("bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb")
// renderer.setClearColor("black");
// box.position.x -= 0.05;
// if( box.position.x < -10 ){
// box.position.x = 10;
// }
// box.position.y = Math.sin(box.position.x);
// return; // Stop the function here.
// }
// make dynamic reflections
if(reflection_on_off == true){
cubeCamera.update(renderer, scene);
discoBall.material.envMap = cubeCamera.textureCube;
}
//animate josh sucks (text) WOOHOO I CAN ACCESS CHILD NODES!
// joshSucks.rotateY(0.1*Math.sin(Math.PI/6));
sculpt.children[0].rotateY(0.1*Math.sin(Math.PI/6));
//Move player backwards or forwards by their Z velocity
player.translateZ(alpha.getSpeedZ());
//Move player up or down by their Y velocity
player.translateY(alpha.getSpeedY());
// move minimap camera on x,z axis according to player
// minimap height stays constant right and captures from right bellow the atmosphere
minimapCamera.position.set(player.position.x, minimapCamera.position.y, player.position.z);
// t to stop gravity, for testing
if(keys[84]){
alpha.setMinSpeedY(0);
}
// Put player on floor if they aren't already on it.
if(!putOnFloor()){
return;
}
//check for death by atmosphere (lasers) (height) + some leeway
if(player.position.y > level.atmosphereHeight + 1){
Crash();
return;
}
// Slowly moving the camera back behind _alpha_
if (resetCameraFlag){
resetCameraPosition();
}
// Animate the avatar model to rotate back to center in it's z-axis, after banking
reCenterAlpha();
// Animate power-ups
for(var i = 0; i < powerups.length; i++){
powerups[i].animate();
}
//check if a power has been activated
if(activePowerups.length > 0) {
for (var k = 0; k < activePowerups.length; k++) {
if(activePowerups[k].getExpiration() < 0) {
activePowerups[k].deactivatePower();
activePowerups.splice(k, 1);
} else {
activePowerups[k].decrementExpiration();
}
}
}
// animate collectibles
for(var j = 0; j < collectibles.length; j++) {
collectibles[j].animate();
}
// update model animation
if(mixer) {
var updateSpeed = 0.02*(-1)*alpha.speedZ;
if(updateSpeed > 0.05) {
mixer.update(0.05);
} else if(updateSpeed < 0.005) {
mixer.update(0.005)
} else {
mixer.update(0.02*(-1)*alpha.speedZ);
}
}
// camera can't got below floor
if(new THREE.Vector3().setFromMatrixPosition(mainCamera.matrixWorld).y < worldMap.floorHeight + 0.1){
mainCamera.position.y = worldMap.floorHeight + 1.1;
}
// Summon keyboard control lookups in one line.
keyCheck();
//Collision
collisions();
if(alpha == null){
return;
}
// Score update: TODO: ut in function and tidy up
if(Math.abs(player.position.x) <= level.worldWidth / 2 && Math.abs(player.position.z) <= level.worldDepth){
score++;
} else {
score = score - 5;
}
document.getElementById("s0").innerHTML = "Level: " + level.levelNum;
document.getElementById("s1").innerHTML = "Score: " + score;
document.getElementById("s2").innerHTML = "Lives: " + lives; // this will need to go in Crash function maybe
}
/*/////////////////////////////////////////////////////////////////////////////////
Drives the animation, called by system through requestAnimationFrame()
Called by itself, exitMenu, init and keysPressed
INPUT: none
OUTPUT: none
//////////////////////////////////////////////////////////////////////////////////*/
function doFrame() {
if (cutscenePlaying) {
renderer.setClearColor("black");
// box.position.x -= 0.05;
// if( box.position.x < -10 ){
// box.position.x = 10;
// }
// box.position.y = Math.sin(box.position.x);
render();
stats.update();
cutsceneFrames++;
console.log(cutsceneFrames);
if(cutsceneFrames < 3000 ){
requestAnimationFrame(doFrame);
} else {
cutscenePlaying = false;
finishInit();
}
}
if (animating) {
updateForFrame();
render();
stats.update();
requestAnimationFrame(doFrame);
}
}
/*/////////////////////////////////////////////////////////////////////////////////////
Finishes initialisation of the world after cutscene is done.
Called by doFrame
INPUT: none
OUTPUT: none
//////////////////////////////////////////////////////////////////////////////////////*/
function finishInit() {
createWorld();
installOrbitControls();
document.addEventListener("mousedown", function(){resetCameraFlag = false}, false);
document.addEventListener("mouseup", function(){resetCameraFlag = true}, false);
render();
}
/*/////////////////////////////////////////////////////////////////////////////////////
Creates the renderer, container for stats, scene object, calls createWorld and installOrbitControls. Renders initial view of the scene
Called by onload event
INPUT: none
OUTPUT: none
//////////////////////////////////////////////////////////////////////////////////////*/
function init() {
createLevel(currLevel);
try {
document.getElementById( 'container' ).style.margin = "0px 0px 0px 0px";
container = document.getElementById( 'container' );
renderer = new THREE.WebGLRenderer( { antialias: true } );
renderer.setPixelRatio( window.devicePixelRatio );
renderer.setSize( window.innerWidth, window.innerHeight );
renderer.shadowMap.enabled = true;
renderer.setScissorTest( true ); //important for minimap not to take control of entire screen even though it only occupies a corner
//renderer.shadowMap.type = THREE.PCFSoftShadowMap; // default THREE.PCFShadowMap
container.appendChild( renderer.domElement );
stats = new Stats();
container.appendChild( stats.dom );
}
catch (e) {
document.getElementById("message").innerHTML="<b>Sorry, an error occurred:<br>" +
e + "</b>";
return;
}
// cutsceneCamera.lookAt(planeMesh.position);
cutscene.add(cutsceneCamera);
requestAnimationFrame(doFrame);
// cutscenePlaying=false;
// finishInit();
// createWorld();
// installOrbitControls();
// document.addEventListener("mousedown", function(){resetCameraFlag = false}, false);
// document.addEventListener("mouseup", function(){resetCameraFlag = true}, false);
// render();
}
</script>
<body onload="init()">
<div class="container">
<div id="container"></div>
<div class="text-block">
<h4>Stats</h4>
<p id="s0"></p>
<p id="s1">Score: NaN </p>
<p id="s2">Lives: - / - </p>
</div>
</div>
</body>
</html>