Skip to content

Commit

Permalink
added boundary motion sounds for masses, see #166
Browse files Browse the repository at this point in the history
  • Loading branch information
jbphet committed Jul 10, 2019
1 parent 28d05d8 commit f72c790
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
39 changes: 39 additions & 0 deletions js/gravity-force-lab-basics/view/GFLBScreenView.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,10 @@ define( require => {
const ResetAllButton = require( 'SCENERY_PHET/buttons/ResetAllButton' );
const ResetAllSoundGenerator = require( 'TAMBO/sound-generators/ResetAllSoundGenerator' );
const ScreenView = require( 'JOIST/ScreenView' );
const SoundClip = require( 'TAMBO/sound-generators/SoundClip' );
const soundManager = require( 'TAMBO/soundManager' );
const SpherePositionsPDOMNode = require( 'GRAVITY_FORCE_LAB/gravity-force-lab/view/SpherePositionsPDOMNode' );
const Util = require( 'DOT/Util' );
const Vector2 = require( 'DOT/Vector2' );

// constants
Expand Down Expand Up @@ -79,6 +81,10 @@ define( require => {
const screenSummarySecondaryDescriptionString = GFLBA11yStrings.screenSummarySecondaryDescription.value;
const basicsSimStateLabelString = GFLBA11yStrings.basicsSimStateLabel.value;

// sounds
const innerBoundarySound = require( 'sound!GRAVITY_FORCE_LAB_BASICS/scrunched-mass-collision-sonic-womp.mp3' );
const outerBoundarySound = require( 'sound!TAMBO/boundary-reached.mp3' );

class GFLBScreenView extends ScreenView {

/**
Expand Down Expand Up @@ -230,6 +236,39 @@ define( require => {
);
soundManager.addSoundGenerator( this.forceSoundGenerator );

// sound generation for outer mass dragging limit
const outerBoundarySoundClip = new SoundClip( outerBoundarySound, { initialOutputLevel: 0.5 } );
soundManager.addSoundGenerator( outerBoundarySoundClip );
model.object1.positionProperty.link( position => {
if ( position === GFLBConstants.PULL_LOCATION_RANGE.min ) {
outerBoundarySoundClip.play();
}
} );
model.object2.positionProperty.link( position => {
if ( position === GFLBConstants.PULL_LOCATION_RANGE.max ) {
outerBoundarySoundClip.play();
}
} );

// sound generation for masses (almost) colliding with one another
const innerBoundarySoundClip = new SoundClip( innerBoundarySound, { initialOutputLevel: 0.5 } );
soundManager.addSoundGenerator( innerBoundarySoundClip );
model.distanceProperty.lazyLink( ( distance, previousDistance ) => {
if ( distance < previousDistance ) {

const distanceInMeters = distance * 1000;

// the distance value from the ISLC model is rounded to 100s of meters, so we do the same thing here
const minDistance = model.object1.radiusProperty.value + model.object2.radiusProperty.value +
GFLBConstants.MIN_DISTANCE_BETWEEN_MASSES;
const roundedMinDistance = Util.roundToInterval( minDistance, 100 );
if ( distanceInMeters === roundedMinDistance ) {
console.log( 'play inner collision sound' );
innerBoundarySoundClip.play();
}
}
} );

const checkboxItems = [
{
label: forceValuesString, property: model.showForceValuesProperty,
Expand Down
8 changes: 8 additions & 0 deletions sounds/license.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,13 @@
"projectURL": "http://phet.colorado.edu",
"license": "contact [email protected]",
"notes": "created by Ashton Morris (PhET Interactive Simulations)"
},
"scrunched-mass-collision-sonic-womp.mp3": {
"text": [
"Copyright 2002-2019 University of Colorado Boulder"
],
"projectURL": "http://phet.colorado.edu",
"license": "contact [email protected]",
"notes": "created by Ashton Morris (PhET Interactive Simulations)"
}
}
Binary file added sounds/scrunched-mass-collision-sonic-womp.mp3
Binary file not shown.

0 comments on commit f72c790

Please sign in to comment.