music start
This commit is contained in:
parent
32d4126873
commit
401218bdbe
39
app.js
39
app.js
@ -65,7 +65,7 @@ let game = {
|
||||
|
||||
stats.clock.start()
|
||||
stats.clock.elapsedTime = stats.elapsedTime
|
||||
scene.music.play()
|
||||
if (settings.musicVolume) scene.music.play()
|
||||
|
||||
if (playfield.piece) scheduler.setInterval(game.fall, stats.fallPeriod)
|
||||
else this.generate()
|
||||
@ -253,22 +253,6 @@ function onkeyup(event) {
|
||||
|
||||
/* Scene */
|
||||
|
||||
const loadingManager = new THREE.LoadingManager()
|
||||
loadingManager.onStart = function (url, itemsLoaded, itemsTotal) {
|
||||
loadingPercent.innerText = "0%"
|
||||
}
|
||||
loadingManager.onProgress = function (url, itemsLoaded, itemsTotal) {
|
||||
loadingPercent.innerText = Math.floor(100 * itemsLoaded / itemsTotal) + '%'
|
||||
}
|
||||
loadingManager.onLoad = function () {
|
||||
loaddingCircle.remove()
|
||||
renderer.setAnimationLoop(animate)
|
||||
gui.startButton.show()
|
||||
}
|
||||
loadingManager.onError = function (url) {
|
||||
loadingPercent.innerText = "Erreur"
|
||||
}
|
||||
|
||||
|
||||
const renderer = new THREE.WebGLRenderer({
|
||||
powerPreference: "high-performance",
|
||||
@ -284,12 +268,10 @@ document.body.appendChild(renderer.domElement)
|
||||
const stats = new Stats()
|
||||
const settings = new Settings()
|
||||
|
||||
const scene = new TetraScene(loadingManager, settings)
|
||||
const scene = new TetraScene(settings)
|
||||
|
||||
const gui = new TetraGUI(game, settings, stats, scene)
|
||||
|
||||
const clock = new THREE.Clock()
|
||||
|
||||
scene.add(Mino.mesh)
|
||||
|
||||
const holdQueue = new HoldQueue()
|
||||
@ -305,6 +287,23 @@ messagesSpan.onanimationend = function (event) {
|
||||
event.target.remove()
|
||||
}
|
||||
|
||||
scene.loadingManager.onStart = function (url, itemsLoaded, itemsTotal) {
|
||||
loadingPercent.innerText = "0%"
|
||||
}
|
||||
scene.loadingManager.onProgress = function (url, itemsLoaded, itemsTotal) {
|
||||
loadingPercent.innerText = Math.floor(100 * itemsLoaded / itemsTotal) + '%'
|
||||
}
|
||||
scene.loadingManager.onLoad = function () {
|
||||
loaddingCircle.remove()
|
||||
gui.startButton.show()
|
||||
renderer.setAnimationLoop(animate)
|
||||
}
|
||||
scene.loadingManager.onError = function (url) {
|
||||
loadingPercent.innerText = "Erreur"
|
||||
}
|
||||
|
||||
|
||||
const clock = new THREE.Clock()
|
||||
|
||||
function animate() {
|
||||
|
||||
|
@ -114,11 +114,6 @@ export class TetraGUI extends GUI {
|
||||
this.settings.volume = this.settings.addFolder("Volume").open()
|
||||
this.settings.volume.add(settings,"musicVolume").name("Musique").min(0).max(100).step(1).onChange(volume => {
|
||||
scene.music.setVolume(volume/100)
|
||||
if (game.playing) {
|
||||
if (volume) scene.music.play()
|
||||
} else {
|
||||
scene.music.pause()
|
||||
}
|
||||
})
|
||||
this.settings.volume.add(settings,"sfxVolume").name("Effets").min(0).max(100).step(1).onChange(volume => {
|
||||
scene.lineClearSound.setVolume(volume/100)
|
||||
|
@ -3,13 +3,15 @@ import { Vortex } from './Vortex.js'
|
||||
|
||||
|
||||
export class TetraScene extends THREE.Scene {
|
||||
constructor(loadingManager, settings) {
|
||||
constructor(settings) {
|
||||
super()
|
||||
|
||||
this.loadingManager = new THREE.LoadingManager()
|
||||
|
||||
this.camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000)
|
||||
this.camera.position.set(5, 0, 16)
|
||||
|
||||
this.vortex = new Vortex(loadingManager)
|
||||
this.vortex = new Vortex(this.loadingManager)
|
||||
this.add(this.vortex)
|
||||
|
||||
this.ambientLight = new THREE.AmbientLight(0xffffff, 1)
|
||||
@ -24,14 +26,13 @@ export class TetraScene extends THREE.Scene {
|
||||
|
||||
const listener = new THREE.AudioListener()
|
||||
this.camera.add( listener )
|
||||
const audioLoader = new THREE.AudioLoader(loadingManager)
|
||||
const audioLoader = new THREE.AudioLoader(this.loadingManager)
|
||||
|
||||
this.music = new THREE.Audio(listener)
|
||||
audioLoader.load('audio/Tetris_T-Spin_OC_ReMix.mp3', function( buffer ) {
|
||||
this.music.setBuffer(buffer)
|
||||
this.music.setLoop(true)
|
||||
this.music.setVolume(settings.musicVolume/100)
|
||||
//if (game.playing) this.music.play()
|
||||
}.bind(this))
|
||||
this.lineClearSound = new THREE.Audio(listener)
|
||||
audioLoader.load('audio/line-clear.ogg', function( buffer ) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user