Skip to content

Commit

Permalink
'add sounds'
Browse files Browse the repository at this point in the history
  • Loading branch information
foglabs committed Nov 2, 2020
1 parent 7611630 commit 8c18fca
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 32 deletions.
2 changes: 1 addition & 1 deletion lib/Game.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class Game {
scene.add( newcube.mesh )
}

handleGame(){
handle(){

}

Expand Down
32 changes: 20 additions & 12 deletions lib/Place.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,21 @@ class Place {
// this.sounds[sk[0]].play()
}

handlePlace(){
this.handleJunk()
this.handleCharacters()
// this.handleSounds()
}
handleSounds(){
let sound, soundKeys = util.k(this.sounds)
for(var i=0; i<soundKeys.length; i++){
sound = this.sounds[ soundKeys[i] ]

// handleSounds(){
// let sound, soundKeys = util.k(this.sounds)
// for(var i=0; i<soundKeys.length; i++){
// sound = soundKeys[i]

// }
// }
if(sound){
sound.handle()
}
// if(sound.playing){
// console.log("she playin wittem")
// } else {
// console.log( 'she is not playin wittem' )
// }
}
}

handleCharacters(){

Expand Down Expand Up @@ -119,6 +121,12 @@ class Place {
}
}
}

handle(){
this.handleJunk()
this.handleCharacters()
this.handleSounds()
}
}

export { Place }
28 changes: 22 additions & 6 deletions lib/Sound.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import * as THREE from "./three.module.js"
import { Character } from "./Character.js"
// import { Timer } from "./Timer.js"
import { listener, loader, scene } from "./main.js"
import { Timer } from "./Timer.js"
import { listener, audioLoader, scene } from "./main.js"

class Sound extends Character {
constructor(soundFilePath, volume=3.0, omni=null){
constructor(soundFilePath, volume=3.0, loop=true, playLength=null, omni=null){
let sphere = new THREE.SphereBufferGeometry( 1, 32, 16 )
let material = new THREE.MeshPhongMaterial( { color: 0xff2200 } )
super(sphere, new THREE.Box3(new THREE.Vector3(), new THREE.Vector3()), [0,0,255], material)
Expand All @@ -24,17 +24,25 @@ class Sound extends Character {
this.volume = volume
this.loaded = false

this.loadSound(this.soundFile, this.volume, () => {
this.loadSound(this.soundFile, this.volume, this.loop, () => {
this.loaded = true
this.play()
console.log( 'oh boy im done' )
})

this.playLength = playLength
this.playTimer = new Timer()
this.playTimer.start()
}

loadSound(soundFile, volume, imDone){
loadSound(soundFile, volume, loop, imDone){
let loaded = false
loader.load(this.soundFilePath, function(buff) {
audioLoader.load(this.soundFilePath, function(buff) {

// need to pass in above to get this crap (args) in scope
soundFile.setBuffer( buff )
soundFile.setVolume( volume )
soundFile.setLoop( loop )

imDone()
})
Expand Down Expand Up @@ -62,6 +70,14 @@ class Sound extends Character {
stop(){
this.soundFile.stop()
}

handle(){
// lets change all this crap over bby!
if(this.playTimer.time() > this.playLength){
// iiim done
this.stop()
}
}
}

export { Sound }
Expand Down
24 changes: 11 additions & 13 deletions lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
var place
var pointer

const loader = new THREE.TextureLoader()
const textureLoader = new THREE.TextureLoader()
const audioLoader = new THREE.AudioLoader()
const listener = new THREE.AudioListener();

var markerJunkTimer = new Timer()
Expand Down Expand Up @@ -77,8 +78,8 @@
scene.add( light )


// // const loader = new THREE.TextureLoader()
// let textyMap = loader.load('/textures/floor-text.jpg')
// // const textureLoader = new THREE.TextureLoader()
// let textyMap = textureLoader.load('/textures/floor-text.jpg')
// textyMap.wrapS = THREE.RepeatWrapping
// textyMap.wrapT = THREE.RepeatWrapping

Expand Down Expand Up @@ -222,7 +223,7 @@
let floor

if(type == DEMO){
let textyMap = loader.load('/textures/floor-text.jpg')
let textyMap = textureLoader.load('/textures/floor-text.jpg')
textyMap.wrapS = THREE.RepeatWrapping
textyMap.wrapT = THREE.RepeatWrapping

Expand All @@ -231,7 +232,7 @@
floor.pushable = false
scene.add(floor.mesh)
} else if(type == RELAXINGRAIN){
let textyMap = loader.load('/textures/rain-floor-text.jpg')
let textyMap = textureLoader.load('/textures/rain-floor-text.jpg')
textyMap.wrapS = THREE.RepeatWrapping
textyMap.wrapT = THREE.RepeatWrapping

Expand All @@ -252,12 +253,9 @@
// nothin
} else if(type == RELAXINGRAIN){

let sound = new Sound("/sounds/thunder2.mp3", 1)
let sound = new Sound("/sounds/rain-Rclip.mp3", 1)
sound.mesh.position.set(0, 1.2,-1)
sounds[sound.mesh.id] = sound
sounds[sound.mesh.id].play()


}

return sounds
Expand All @@ -272,7 +270,7 @@
let sounds = createSounds(type)
// add dat floro baby
chars[floor.mesh.id] = floor
return new Place(background, chars, floor)
return new Place(background, chars, floor, sounds)
}

function addCubeAtPointer(){
Expand All @@ -290,7 +288,7 @@
scene = new THREE.Scene()

place = createPlace(RELAXINGRAIN)

place.sounds[util.k(place.sounds)[0]].play()

// scene.background = new THREE.Color( '#330203' );
scene.background = new THREE.Color( place.backgroundHex );
Expand Down Expand Up @@ -565,7 +563,7 @@
game.addRandomCube()
}

place.handlePlace()
place.handle()

// check controller interactions
handleController( controller );
Expand All @@ -582,4 +580,4 @@

}

export { util, loader, listener, pointer, scene, place, game, controller }
export { util, textureLoader, audioLoader, listener, pointer, scene, place, game, controller }
Binary file added sounds/rain-Rclip.mp3
Binary file not shown.

0 comments on commit 8c18fca

Please sign in to comment.