@@ -49,6 +49,10 @@ function World() {
4949
5050 // Scoped variables in this world.
5151 var element ,
52+ audio ,
53+ audio2 ,
54+ source ,
55+ source2 ,
5256 scene ,
5357 camera ,
5458 character ,
@@ -82,6 +86,18 @@ function World() {
8286 camera_z_look = - 100000 ;
8387 element = document . getElementById ( "world" ) ;
8488
89+ //initialize sound for spikes
90+ // audio = document.createElement('audio');
91+ // source = document.createElement('source');
92+ // source.src = 'images/sounds/WoodCrashesDistant FS022705.mp3';
93+ // audio.appendChild(source);
94+
95+ //initialize sound for coins
96+ // source = document.createElement('source');
97+ // source.src = 'images/sounds/zapsplat_multimedia_game_sound_coins_money_collect_bank_006_67722.mp3';
98+ // audio.appendChild(source);
99+ // audio.play();
100+
85101 // Initialize the renderer.
86102 renderer = new THREE . WebGLRenderer ( {
87103 alpha : true ,
@@ -121,6 +137,20 @@ function World() {
121137 character = new Character ( ) ;
122138 scene . add ( character . element ) ;
123139
140+ // //creating sound for coin
141+ // const listener = new
142+ // Three.AudioListener();
143+ // camera.add(listener);
144+ // const sound = new THREE.PositionalAudio(listener);
145+ // const audioLoader = new THREE.AudioLoader();
146+ // audioLoader.load('images/sounds/zapsplat_multimedia_game_sound_coins_money_collect_bank_006_67722.mp3')
147+
148+ // function(buffer){
149+ // sound.setBuffer(buffer);
150+ // sound.setRefDistance(20);
151+
152+ // }
153+
124154 //Create Running Platform
125155 var geometry = new THREE . BoxGeometry ( 8000 , 0 , 120000 ) ;
126156 const loader = new THREE . TextureLoader ( ) . load ( "images/23886804.jpg" , ( texture ) => {
@@ -307,6 +337,12 @@ function World() {
307337 // Check for collisions between the character and coin.
308338 if ( collisionsDetectedCoin ( ) ) {
309339 coinsCollected += 1 ;
340+ //adds sound
341+ audio = document . createElement ( 'audio' ) ;
342+ source = document . createElement ( 'source' ) ;
343+ source . src = 'images/sounds/zapsplat_multimedia_game_sound_coins_money_collect_bank_006_67722.mp3' ;
344+ audio . appendChild ( source ) ;
345+ audio . play ( ) ;
310346
311347 console . log ( coinsCollected )
312348 }
@@ -324,6 +360,13 @@ function World() {
324360 document . addEventListener ( "keydown" , function ( e ) {
325361 if ( e . keyCode == 40 ) document . location . reload ( true ) ;
326362 } ) ;
363+ //Adds crash when character hits the obstacle
364+ audio = document . createElement ( 'audio' ) ;
365+ source = document . createElement ( 'source' ) ;
366+ source . src = 'images/sounds/WoodCrashesDistant FS022705.mp3' ;
367+ audio . appendChild ( source ) ;
368+ audio . play ( ) ;
369+
327370 var variableContent = document . getElementById ( "variable-content" ) ;
328371 variableContent . style . visibility = "visible" ;
329372 variableContent . innerHTML =
@@ -869,6 +912,7 @@ function CoinFunc(x, y, z, s) {
869912 coin . rotation . y = 1.5
870913
871914 this . mesh . add ( coin )
915+ //this.mesh.add(sound)
872916
873917 this . mesh . position . set ( x , y , z ) ;
874918 this . mesh . scale . set ( s , s , s ) ;
0 commit comments