/% -------------------------------------------------------------------------------------- % SPECIALLY-TAGGED PASSAGE FOR PLACING JAVASCRIPT TO BE RUN AT STORY INITIALIZATION % See http://www.motoslave.net/sugarcube/2/docs/special-names.html#special-tags % -------------------------------------------------------------------------------------%/ :: javascript [script] /********************************************************************* * SUGARCUBE 2 CONFIGURATION * See http://www.motoslave.net/sugarcube/2/docs/config-object.html *********************************************************************/ config.ui.stowBarInitially = true; // the UI bar will start stowed (shut) /********************************************************************* * FAVICON *********************************************************************/ (function () { var favicon = document.createElement("link"); favicon.type = 'image/x-icon'; favicon.rel = "shortcut icon"; favicon.href = "favicon.png"; document.head.appendChild(favicon); }()); /********************************************************************* * INITIALIZE STORY *********************************************************************/ window.initializeStory = function() { window.upDownCount = 0; window.putDownEndingPassages = Array( "put_down_story_1", "put_down_story_2", "put_down_story_3", "put_down_story_4", "put_down_story_5" ); window.putDownEndingPassagesCopy = window.putDownEndingPassages.slice(0); window.violentImageArrayCopy = Array(); window.facesImageArrayCopy = Array(); try { clearAllTimeouts(); } catch(e) {}; window.allTimeouts = Array(); $('#puppetsheet').remove(); $('#puppetbg-container').remove(); $('#ground').remove(); $('#cover-image').remove(); $('#sunset-overlay').remove(); $('#night-overlay').remove(); $('#sunrise-overlay').remove(); $('#fade-out').remove(); $('#blood-overlay').remove(); $('#gun').remove(); $('#gun-shadow').remove(); // Note that in-game variables referenced via $foo can be set in javascript via: // State.variables.foo = 'bar'; /********************************************************************* * DOM MODIFICATIONS *********************************************************************/ // Add a div beneath body that we will use to handle our puppets. $('body').prepend('
'); $('body').prepend('
'); $("#puppetsheet").hide(); // Add the puppets. $('#puppetbg').append(''); $('#puppetbg').append(''); $('#puppetbg').append(''); $('#puppetbg').append(''); $('#puppetbg').append(''); $('#puppetbg').append(''); $('#puppetbg').append(''); $('#puppetbg').append(''); $('#puppetbg').append(''); $('#puppetbg').append(''); $('#puppetbg').append(''); $(".puppet").hide(); // Add ground. $('body').prepend('
'); // Add cover image. $('body').prepend('
'); // Add sunset overlay. $('body').prepend('
'); // Add night overlay. $('body').prepend('
'); // Add sunrise overlay. $('body').prepend('
'); // Add fade out. $('body').prepend('
'); /********************************************************************* * INITIALIZE SOUND OBJECTS (these make use of the howler.js library) *********************************************************************/ window.sndTest = new Howl({ src: ['assets/sounds/sound_volume_check_test.mp3'], loop: false, volume: 0.8 }); window.sndCelebration = new Howl({ src: ['assets/sounds/209982__yuval__distant-turkish-wedding.mp3'], loop: true, volume: 0.3 }); window.sndHollering = new Howl({ src: ['assets/sounds/17343__audiblepie-com__welcome-scream.mp3'], loop: true, volume: 0.1 }); window.sndShouting = new Howl({ src: ['assets/sounds/101871__dickblox__crowd-shouting.mp3'], loop: true, volume: 0.7 }); window.sndChildrenCheering = new Howl({ src: ['assets/sounds/346814__robinhood76__06684-children-hooray-joy-shout.mp3'], loop: false, volume: 0.6 }); window.sndShush = new Howl({ src: ['assets/sounds/360590__fallbackcrush__shh.mp3'], loop: false, volume: 1 }); window.sndMachinegunLoop = new Howl({ src: ['assets/sounds/101961__cgeffex__heavy-machine-gun.mp3'], loop: true, volume: 0.5 }); window.sndBackgroundChatter01 = new Howl({ src: ['assets/sounds/background_chatter_01_171986__klankbeeld__school-is-out-kids-121218-00.mp3'], loop: true, volume: 0.5 }); window.sndBackgroundChatter02 = new Howl({ src: ['assets/sounds/background_chatter_02_7209__corsica-s__people-sitting-by-fire.mp3'], loop: true, volume: 0.7 }); window.sndBackgroundChatter03 = new Howl({ src: ['assets/sounds/background_chatter_03_260122__mentalsanityoff__indoor-adult-murmur-medium-group.mp3'], loop: true, volume: 1 }); window.sndBackgroundMurmur= new Howl({ src: ['assets/sounds/background_murmur_238980__qubodup__crowd-talk-loop.mp3'], loop: true, volume: 0 }); window.sndYell01 = new Howl({ src: ['assets/sounds/yell01_17343__audiblepie-com__welcome-scream.mp3'], loop: false, volume: 0.7 }); window.sndYell01B = new Howl({ src: ['assets/sounds/yell01B_17343__audiblepie-com__welcome-scream.mp3'], loop: false, volume: 0.5 }); window.sndYell01C = new Howl({ src: ['assets/sounds/yell01C_17343__audiblepie-com__welcome-scream.mp3'], loop: false, volume: 0.5 }); window.sndYell02 = new Howl({ src: ['assets/sounds/yell02_17343__audiblepie-com__welcome-scream.mp3'], loop: false, volume: 0.7 }); window.sndGreetingYell = new Howl({ src: ['assets/sounds/greeting_yell_02_17343__audiblepie-com__welcome-scream.mp3'], loop: false, volume: 0.5 }); window.sndBreathing = new Howl({ src: ['assets/sounds/54776__bevangoldswain__heavy-breathing-off-mic-loop.mp3'], loop: true, volume: 0.4 }); window.sndHeartbeat = new Howl({ src: ['assets/sounds/250845__niedec__heartbeat.mp3'], loop: true, volume: 0.5 }); window.sndWar = new Howl({ src: ['assets/sounds/96533__omar-alvarado__modern-day-war_01.mp3'], loop: false, volume: 0.4 }); window.sndExplosion = new Howl({ src: ['assets/sounds/259300__unfa__huge-explosion.mp3'], loop: false, volume: 1 }); /** window.sndScream = new Howl({ src: ['assets/sounds/HumanScream_DIGII07-25-05.mp3'], loop: false, volume: 1 }); window.sndHurt01 = new Howl({ src: ['assets/sounds/hurt01.mp3'], loop: false, volume: 1 }); window.sndHurt02 = new Howl({ src: ['assets/sounds/hurt02.mp3'], loop: false, volume: 1 }); window.sndHurt03 = new Howl({ src: ['assets/sounds/hurt03.mp3'], loop: false, volume: 1 }); window.sndHurt04 = new Howl({ src: ['assets/sounds/hurt04.mp3'], loop: false, volume: 1 }); window.sndHurt05 = new Howl({ src: ['assets/sounds/hurt05.mp3'], loop: false, volume: 1 }); window.sndHurt06 = new Howl({ src: ['assets/sounds/hurt06.mp3'], loop: false, volume: 1 }); window.sndHurt07 = new Howl({ src: ['assets/sounds/hurt07.mp3'], loop: false, volume: 1 }); window.sndHurt08 = new Howl({ src: ['assets/sounds/hurt08.mp3'], loop: false, volume: 1 }); window.sndHurt09 = new Howl({ src: ['assets/sounds/hurt09.mp3'], loop: false, volume: 1 }); window.sndHurt10 = new Howl({ src: ['assets/sounds/hurt10.mp3'], loop: false, volume: 1 }); var sndHurtArray = Array(sndHurt01, sndHurt02, sndHurt03, sndHurt04, sndHurt05,sndHurt06, sndHurt07, sndHurt08, sndHurt09, sndHurt10); **/ }; /********************************************************************* * Make the initial call to initialize story. *********************************************************************/ initializeStory(); /********************************************************************* * PRELOAD IMAGES *********************************************************************/ // Add the blood overlay. $('body').prepend('
'); // Gun $('body').prepend('
'); $('body').prepend('
'); // Puppets window.puppetImageArray = Array( "puppet_boy.png", "puppet_boy_rock.png", "puppet_father.png", "puppet_mother.png", "puppet_house.png", "puppet_hospital.png", "puppet_wire.png", "puppet_soldier.png", "puppet_soldier_shooting.png", "puppet_bulldozer.png", "puppet_question.png" ); for(var i = puppetImageArray.length - 1; i >= 0; i--){ var preloadImage = puppetImageArray[i]; $('body').prepend('
'); } // Violent images. window.violentImageArray = Array( "2190176602_9c4e70b78b.jpg", "3298081311_d75e5d5c1f_o.jpg", "Another_injury_caused_by_the_bombing_of_Israeli_Air_Forces_over_Gaza_Strip,_reached_the_hospital_unconscious.jpg", "Chemical_burns_follwong_Israeli_bombings1.jpg", "Fatally_wounded_Israeli_school_boy.jpg", "Flickr_-_Israel_Defense_Forces_-_Bil-in_Riot,_Jan_2011_6.jpg", "Gazaday14.jpg", "n721725932_1613535_8023.jpg", "Near_Beit_El_-_north_of_Ramallah_10.10.2015_10.jpg", "Near_Beit_El_-_north_of_Ramallah_10.10.jpg", "Palestinian_Demonstrator_picks_Tear_gas_grenade_to_throw_back_Kafr_Qaddum_August_2014_2.jpg", "Palestinian_militant_with_rifle.jpg" ); for(var i = violentImageArray.length - 1; i >= 0; i--){ var preloadImage = violentImageArray[i]; $('body').prepend('
'); } // Face images. window.facesImageArray = Array( "3202880684_763846e8f4_o.jpg", "3286208380_176e6f164f_o.jpg", "3286231988_ae66a85935_o.jpg", "3286249224_6e31fba579_o.jpg", "3286256664_0fac09c4e0_o.jpg", "3286467903_1cf6aba0b7_o.jpg", "4742026797_dbfb4c57e0_o.jpg", "4991232884_ac841ee310_o.jpg", "5513283076_05ec4fc98b_o.jpg", "Shaymaa_al-Masri_five_years_old_at_a-Shifaa_Hospital_Gaza.jpg" ); for(var i = facesImageArray.length - 1; i >= 0; i--){ var preloadImage = facesImageArray[i]; $('body').prepend('
'); } /********************************************************************* * WINDOW RESIZING AND OTHER POSTDISPLAY *********************************************************************/ // Resize the puppet background after scene display. // (The puppet background should take up the space between the top of the screen and the passage.) postdisplay.resizePuppetBG = function() { if (tags().contains('puppet-show')) { $('#puppetbg-container').height(function(index, height) { return $('.passage').offset().top; }); } } // Resize the tic-tac-toe iframe after scene display. postdisplay.resizeTicTacToe = function() { if (tags().contains('tic-tac-toe')) { $('iframe#tictactoe').height(function(index, height) { return $('.passage').offset().top; }); } } // Also handle onresize() window size changes. window.onresize = function() { if (tags().contains('puppet-show')) { $('#puppetbg-container').height(function(index, height) { return $('.passage').offset().top; }); } if (tags().contains('tic-tac-toe')) { $('iframe#tictactoe').height(function(index, height) { return $('.passage').offset().top; }); } } // Handle links that we want to automatically advance when the user hovers over them. postdisplay.handleHoverLlinks = function() { $('.hoverlink a').mouseover(function() { this.click(); }); } /********************************************************************* * UTILITY FUNCTIONS *********************************************************************/ window.holdGunUp = function(element) { if (!$(element).hasClass('clickable')) { console.log('unclickable'); return false; } // Track where the gun is. upDownCount += 1; // Game end. if (upDownCount >= 8) { $('#the-choice').remove(); $('#gun').remove(); $('#gun-shadow').remove(); sndWar.stop(); window.sndBreathing.stop(); /*window.sndScream.play();*/ window.sndHeartbeat.stop(); window.sndCelebration.stop(); window.sndShouting.stop(); window.sndHollering.stop(); window.sndMachinegunLoop.stop(); //clearAllTimeouts(); //stopAllHurtSounds(); //sndExplosion.play(); State.play("Story End"); return false; } // Show the end story passages. if (upDownCount == 1) { //$('#the-choice').finish().hide(); State.play("hold_up_story_1"); } else if (upDownCount == 2) { //$('#the-choice').finish().hide(); State.play("hold_up_story_2"); } else if (upDownCount == 4) { //$('#the-choice').finish().hide(); State.play("hold_up_story_3"); } else if (upDownCount == 6) { //$('#the-choice').finish().hide(); State.play("hold_up_story_4"); } // Move the the choice text and gun up (use % from top, so that movement is relative to window height) $('#the-choice').animate({ top : "-=5%" }, 500, 'swing'); $('#gun').animate({ top : "-=12%" }, 500, 'swing'); $('#gun-shadow').animate({ top : "-=8%" }, 500, 'swing'); // Show an image. if (upDownCount >= 4) { // Initialize image array. if (typeof violentImageArrayCopy == 'undefined' || violentImageArrayCopy.length < 1) { console.log('reinitialize array'); window.violentImageArrayCopy = violentImageArray.slice(0); } console.log(violentImageArrayCopy); // Get a random image from the array. var randomImage = violentImageArrayCopy.splice(Math.floor(Math.random()*violentImageArrayCopy.length), 1); console.log(randomImage); // Move any existing background images down on the z-index, so that the new one will be on top. $('.background-image').css('z-index', 19); // Prepend the image to the body with a random div id so that we can access it / fade it out. var randomID = idGenerator(); $('body').prepend('
'); $('#' + randomID).fadeOut(5000, function() { $(this).remove(); }); // Fade link text out and prevent clicking temporarily. /* $('#the-choice').finish().hide().fadeIn(5000); $('.choice').removeClass('clickable'); setTimeout(function() { $('.choice').addClass('clickable'); }, 2000); */ // War sounds. sndWar.play(); } // Increase blood overlay. var bloodOverlayOpacity = $('#blood-overlay').css('opacity'); bloodOverlayOpacity = Number(bloodOverlayOpacity) if (bloodOverlayOpacity < 1) { bloodOverlayOpacity = bloodOverlayOpacity + 0.1; console.log('bloodOverlayOpacity: ' + bloodOverlayOpacity); //$('#blood-overlay').css('opacity', bloodOverlayOpacity); $('#blood-overlay').animate({ opacity : bloodOverlayOpacity }, 500, 'swing'); } // Increase breathing and heartbeat volume. var currentVol = sndBreathing.volume(); currentVol += .1; if (currentVol <= .7) sndBreathing.volume(currentVol); var currentVol = sndHeartbeat.volume(); currentVol += .1; if (currentVol <= 1) sndHeartbeat.volume(currentVol); }; window.putGunDown = function(element) { if (!$(element).hasClass('clickable')) { console.log('unclickable'); return false; } // Track where the gun is. upDownCount -= 1; // Show the end story passages as we go down. /* if (upDownCount == -2) { //$('#the-choice').finish().hide(); State.play("put_down_story_1"); } else if (upDownCount == -4) { //$('#the-choice').finish().hide(); State.play("put_down_story_2"); } else if (upDownCount == -6) { //$('#the-choice').finish().hide(); State.play("put_down_story_3"); } */ // Move the whole passage down (use % from top, so that movement is relative to window height). if (upDownCount > -7) { $('#the-choice').animate({ top : "+=5%" }, 500, 'swing'); $('#gun').animate({ top : "+=12%" }, 500, 'swing'); $('#gun-shadow').animate({ top : "+=8%" }, 500, 'swing'); } // Last stop: won't go any further. else { // Hurt sound // playRandomHurtSound(); // Pop back up. $('#the-choice').animate({ top : "+=5%" }, 750, 'swing').animate({ top : "-=5%" }, 250, 'swing'); $('#gun-shadow').animate({ top : "+=5%" }, 750, 'swing').animate({ top : "-=5%" }, 250, 'swing'); upDownCount += 1; // Show a random end sentence. if (typeof window.putDownEndingPassagesCopy == 'undefined' || window.putDownEndingPassagesCopy.length < 1) { console.log('time to shuffle'); window.putDownEndingPassagesCopy = putDownEndingPassages.slice(0); shuffle(putDownEndingPassagesCopy); } var randomPassage = putDownEndingPassagesCopy.shift(); console.log(putDownEndingPassagesCopy); console.log(randomPassage); State.play(randomPassage); // Initialize image array. if (typeof facesImageArrayCopy == 'undefined' || facesImageArrayCopy.length < 1) { console.log('reinitialize array'); window.facesImageArrayCopy = facesImageArray.slice(0); } console.log(facesImageArrayCopy); // Get a random image from the array. var randomImage = facesImageArrayCopy.splice(Math.floor(Math.random()*facesImageArrayCopy.length), 1); console.log(randomImage); // Move any existing background images down on the z-index, so that the new one will be on top. $('.background-image').css('z-index', 19); // Prepend the image to the body with a random div id so that we can access it / fade it out. var randomID = idGenerator(); $('body').prepend('
'); $('#' + randomID).fadeOut(10000, function() { $(this).remove(); }); // Fade link text out and prevent clicking temporarily. /* $('#the-choice').finish().hide().fadeIn(5000); $('.choice').removeClass('clickable'); setTimeout(function() { $('.choice').addClass('clickable'); }, 2000); */ // Crowd shouting. //sndShouting.fade(1, 0.1, 5000); } // Increase breathing and heartbeat volume. var currentVol = window.sndBreathing.volume(); currentVol += .1; if (currentVol <= .7) window.sndBreathing.volume(currentVol); var currentVol = sndHeartbeat.volume(); currentVol += .1; if (currentVol <= 1) sndHeartbeat.volume(currentVol); // Stop war sounds. sndWar.stop(); }; window.playRandomHurtSound = function(volume) { do { var sndRandom = sndHurtArray[Math.floor(Math.random() * sndHurtArray.length)]; } while (sndRandom.playing()); window.sndBreathing.pause(); sndRandom.play(); var pauseDuration = 500; var id = window.setTimeout(function() { if (!window.sndBreathing.playing()) { window.sndBreathing.play(); } stopAllHurtSounds(); }, pauseDuration); window.allTimeouts.push(id); }; window.stopAllHurtSounds = function(volume) { for (var i=0; i