@@ -54,6 +54,10 @@ function World() {
5454
5555 // Scoped variables in this world.
5656 var element ,
57+ audio ,
58+ audio2 ,
59+ source ,
60+ source2 ,
5761 scene ,
5862 camera ,
5963 character ,
@@ -92,6 +96,18 @@ function World() {
9296 leftClick = false ;
9397 element = document . getElementById ( "world" ) ;
9498
99+ //initialize sound for spikes
100+ // audio = document.createElement('audio');
101+ // source = document.createElement('source');
102+ // source.src = 'images/sounds/WoodCrashesDistant FS022705.mp3';
103+ // audio.appendChild(source);
104+
105+ //initialize sound for coins
106+ // source = document.createElement('source');
107+ // source.src = 'images/sounds/zapsplat_multimedia_game_sound_coins_money_collect_bank_006_67722.mp3';
108+ // audio.appendChild(source);
109+ // audio.play();
110+
95111 // Initialize the renderer.
96112 renderer = new THREE . WebGLRenderer ( {
97113 alpha : true ,
@@ -131,6 +147,20 @@ function World() {
131147 character = new Character ( ) ;
132148 scene . add ( character . element ) ;
133149
150+ // //creating sound for coin
151+ // const listener = new
152+ // Three.AudioListener();
153+ // camera.add(listener);
154+ // const sound = new THREE.PositionalAudio(listener);
155+ // const audioLoader = new THREE.AudioLoader();
156+ // audioLoader.load('images/sounds/zapsplat_multimedia_game_sound_coins_money_collect_bank_006_67722.mp3')
157+
158+ // function(buffer){
159+ // sound.setBuffer(buffer);
160+ // sound.setRefDistance(20);
161+
162+ // }
163+
134164 //Create Running Platform
135165 var geometry = new THREE . BoxGeometry ( 8000 , 0 , 120000 ) ;
136166 const loader = new THREE . TextureLoader ( ) . load ( "images/23886804.jpg" , ( texture ) => {
@@ -317,6 +347,12 @@ function World() {
317347 // Check for collisions between the character and coin.
318348 if ( collisionsDetectedCoin ( ) ) {
319349 coinsCollected += 1 ;
350+ //adds sound
351+ audio = document . createElement ( 'audio' ) ;
352+ source = document . createElement ( 'source' ) ;
353+ source . src = 'images/sounds/zapsplat_multimedia_game_sound_coins_money_collect_bank_006_67722.mp3' ;
354+ audio . appendChild ( source ) ;
355+ audio . play ( ) ;
320356
321357 console . log ( coinsCollected )
322358 }
@@ -334,6 +370,13 @@ function World() {
334370 document . addEventListener ( "keydown" , function ( e ) {
335371 if ( e . keyCode == 40 ) document . location . reload ( true ) ;
336372 } ) ;
373+ //Adds crash when character hits the obstacle
374+ audio = document . createElement ( 'audio' ) ;
375+ source = document . createElement ( 'source' ) ;
376+ source . src = 'images/sounds/WoodCrashesDistant FS022705.mp3' ;
377+ audio . appendChild ( source ) ;
378+ audio . play ( ) ;
379+
337380 var variableContent = document . getElementById ( "variable-content" ) ;
338381 variableContent . style . visibility = "visible" ;
339382 variableContent . innerHTML =
@@ -941,6 +984,7 @@ function CoinFunc(x, y, z, s) {
941984 coin . rotation . y = 1.5
942985
943986 this . mesh . add ( coin )
987+ //this.mesh.add(sound)
944988
945989 this . mesh . position . set ( x , y , z ) ;
946990 this . mesh . scale . set ( s , s , s ) ;
0 commit comments