music start

This commit is contained in:
Adrien MALINGREY 2023-07-18 19:57:44 +02:00
parent 32d4126873
commit 401218bdbe
3 changed files with 24 additions and 29 deletions

39
app.js
View File

@ -65,7 +65,7 @@ let game = {
stats.clock.start() stats.clock.start()
stats.clock.elapsedTime = stats.elapsedTime stats.clock.elapsedTime = stats.elapsedTime
scene.music.play() if (settings.musicVolume) scene.music.play()
if (playfield.piece) scheduler.setInterval(game.fall, stats.fallPeriod) if (playfield.piece) scheduler.setInterval(game.fall, stats.fallPeriod)
else this.generate() else this.generate()
@ -253,22 +253,6 @@ function onkeyup(event) {
/* Scene */ /* 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({ const renderer = new THREE.WebGLRenderer({
powerPreference: "high-performance", powerPreference: "high-performance",
@ -284,12 +268,10 @@ document.body.appendChild(renderer.domElement)
const stats = new Stats() const stats = new Stats()
const settings = new Settings() const settings = new Settings()
const scene = new TetraScene(loadingManager, settings) const scene = new TetraScene(settings)
const gui = new TetraGUI(game, settings, stats, scene) const gui = new TetraGUI(game, settings, stats, scene)
const clock = new THREE.Clock()
scene.add(Mino.mesh) scene.add(Mino.mesh)
const holdQueue = new HoldQueue() const holdQueue = new HoldQueue()
@ -305,6 +287,23 @@ messagesSpan.onanimationend = function (event) {
event.target.remove() 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() { function animate() {

View File

@ -114,11 +114,6 @@ export class TetraGUI extends GUI {
this.settings.volume = this.settings.addFolder("Volume").open() this.settings.volume = this.settings.addFolder("Volume").open()
this.settings.volume.add(settings,"musicVolume").name("Musique").min(0).max(100).step(1).onChange(volume => { this.settings.volume.add(settings,"musicVolume").name("Musique").min(0).max(100).step(1).onChange(volume => {
scene.music.setVolume(volume/100) 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 => { this.settings.volume.add(settings,"sfxVolume").name("Effets").min(0).max(100).step(1).onChange(volume => {
scene.lineClearSound.setVolume(volume/100) scene.lineClearSound.setVolume(volume/100)

View File

@ -3,13 +3,15 @@ import { Vortex } from './Vortex.js'
export class TetraScene extends THREE.Scene { export class TetraScene extends THREE.Scene {
constructor(loadingManager, settings) { constructor(settings) {
super() super()
this.loadingManager = new THREE.LoadingManager()
this.camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000) this.camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000)
this.camera.position.set(5, 0, 16) this.camera.position.set(5, 0, 16)
this.vortex = new Vortex(loadingManager) this.vortex = new Vortex(this.loadingManager)
this.add(this.vortex) this.add(this.vortex)
this.ambientLight = new THREE.AmbientLight(0xffffff, 1) this.ambientLight = new THREE.AmbientLight(0xffffff, 1)
@ -24,14 +26,13 @@ export class TetraScene extends THREE.Scene {
const listener = new THREE.AudioListener() const listener = new THREE.AudioListener()
this.camera.add( listener ) this.camera.add( listener )
const audioLoader = new THREE.AudioLoader(loadingManager) const audioLoader = new THREE.AudioLoader(this.loadingManager)
this.music = new THREE.Audio(listener) this.music = new THREE.Audio(listener)
audioLoader.load('audio/Tetris_T-Spin_OC_ReMix.mp3', function( buffer ) { audioLoader.load('audio/Tetris_T-Spin_OC_ReMix.mp3', function( buffer ) {
this.music.setBuffer(buffer) this.music.setBuffer(buffer)
this.music.setLoop(true) this.music.setLoop(true)
this.music.setVolume(settings.musicVolume/100) this.music.setVolume(settings.musicVolume/100)
//if (game.playing) this.music.play()
}.bind(this)) }.bind(this))
this.lineClearSound = new THREE.Audio(listener) this.lineClearSound = new THREE.Audio(listener)
audioLoader.load('audio/line-clear.ogg', function( buffer ) { audioLoader.load('audio/line-clear.ogg', function( buffer ) {