diff --git a/app.js b/app.js index 9005116..57e4a00 100644 --- a/app.js +++ b/app.js @@ -175,16 +175,23 @@ function playSound(sound, note=0) { /* Handle player inputs */ let playerActions = { - moveLeft: () => scene.playfield.piece.move(TRANSLATION.LEFT), + moveLeft: () => scene.playfield.piece.move(TRANSLATION.LEFT)? scene.moveSound.play() : scene.hitSound.stop() && scene.hitSound.play(), - moveRight: () => scene.playfield.piece.move(TRANSLATION.RIGHT), + moveRight: () => scene.playfield.piece.move(TRANSLATION.RIGHT)? scene.moveSound.play() : scene.hitSound.stop() && scene.hitSound.play(), - rotateCW: () => scene.playfield.piece.rotate(ROTATION.CW), + rotateCW: () => scene.playfield.piece.rotate(ROTATION.CW)? scene.rotateSound.stop() && scene.rotateSound.play() : scene.hitSound.stop() && scene.hitSound.play(), - rotateCCW: () => scene.playfield.piece.rotate(ROTATION.CCW), + rotateCCW: () => scene.playfield.piece.rotate(ROTATION.CCW)? scene.rotateSound.stop() && scene.rotateSound.play() : scene.hitSound.stop() && scene.hitSound.play(), softDrop: function () { - if (scene.playfield.piece.move(TRANSLATION.DOWN)) stats.score++ + if (scene.playfield.piece.move(TRANSLATION.DOWN)) { + stats.score++ + scene.moveSound.stop() + scene.moveSound.play() + } else { + scene.floorSound.stop() + scene.floorSound.play() + } }, hardDrop: function () { diff --git a/audio/floor.ogg b/audio/floor.ogg new file mode 100644 index 0000000..2c34a2c Binary files /dev/null and b/audio/floor.ogg differ diff --git a/audio/hit.mp3 b/audio/hit.mp3 new file mode 100644 index 0000000..3c0c33a Binary files /dev/null and b/audio/hit.mp3 differ diff --git a/audio/move.ogg b/audio/move.ogg new file mode 100644 index 0000000..308ff6d Binary files /dev/null and b/audio/move.ogg differ diff --git a/audio/rotate.ogg b/audio/rotate.ogg new file mode 100644 index 0000000..f7ec104 Binary files /dev/null and b/audio/rotate.ogg differ diff --git a/jsm/TetraScene.js b/jsm/TetraScene.js index f55f0af..4e8a361 100644 --- a/jsm/TetraScene.js +++ b/jsm/TetraScene.js @@ -47,17 +47,37 @@ export class TetraScene extends THREE.Scene { this.lineClearSound = new THREE.Audio(listener) audioLoader.load('audio/line-clear.ogg', function( buffer ) { this.lineClearSound.setBuffer(buffer) + this.lineClearSound.setVolume(settings.sfxVolume/100) }.bind(this)) this.tetrisSound = new THREE.Audio(listener) audioLoader.load('audio/tetris.ogg', function( buffer ) { this.tetrisSound.setBuffer(buffer) - this.lineClearSound.setVolume(settings.sfxVolume/100) this.tetrisSound.setVolume(settings.sfxVolume/100) - this.hardDropSound.setVolume(settings.sfxVolume/100) }.bind(this)) this.hardDropSound = new THREE.Audio(listener) audioLoader.load('audio/hard-drop.wav', function( buffer ) { this.hardDropSound.setBuffer(buffer) + this.hardDropSound.setVolume(settings.sfxVolume/100) + }.bind(this)) + this.hitSound = new THREE.Audio(listener) + audioLoader.load('audio/hit.mp3', function( buffer ) { + this.hitSound.setBuffer(buffer) + this.hitSound.setVolume(settings.sfxVolume/100) + }.bind(this)) + this.floorSound = new THREE.Audio(listener) + audioLoader.load('audio/floor.ogg', function( buffer ) { + this.floorSoung.setBuffer(buffer) + this.floorSoung.setVolume(settings.sfxVolume/100) + }.bind(this)) + this.moveSound = new THREE.Audio(listener) + audioLoader.load('audio/move.ogg', function( buffer ) { + this.moveSound.setBuffer(buffer) + this.moveSound.setVolume(settings.sfxVolume/100) + }.bind(this)) + this.rotateSound = new THREE.Audio(listener) + audioLoader.load('audio/rotate.ogg', function( buffer ) { + this.rotateSound.setBuffer(buffer) + this.rotateSound.setVolume(settings.sfxVolume/100) }.bind(this)) this.playfield = new Playfield(loadingManager) @@ -72,8 +92,8 @@ export class TetraScene extends THREE.Scene { switch (theme) { case "Plasma": this.ambientLight.intensity = 1 - this.directionalLight.intensity = 1 - this.directionalLight.position.set(5, -20, 20) + this.directionalLight.intensity = 3 + this.directionalLight.position.set(5, -20, -10) this.music.src = "audio/Moon-Over-Moscow-DJ-ResiDance-Mix-2022.mp3" this.background = new THREE.Color(0xffffff) this.fog.color.set(0xffffff) diff --git a/jsm/Tetrominoes.js b/jsm/Tetrominoes.js index 48982fe..3ed09f7 100644 --- a/jsm/Tetrominoes.js +++ b/jsm/Tetrominoes.js @@ -96,7 +96,7 @@ export class InstancedMino extends THREE.InstancedMesh { bumpScale: 1.5, envMap: environment, envMapIntensity: 5, - roughness: 0.07, + roughness: 0.03, metalness: 1, transparent: true, }, 8, 8) @@ -112,7 +112,7 @@ export class InstancedMino extends THREE.InstancedMesh { bumpScale: 1.5, envMap: environment, envMapIntensity: 5, - roughness: 0.07, + roughness: 0.03, metalness: 1, transparent: true, }, 1, 1) @@ -168,35 +168,27 @@ InstancedMino.prototype.materials = { envMap: environment, side: THREE.DoubleSide, transparent: true, - opacity: 0.55, + opacity: 0.66, roughness: 0.1, metalness: 0.95, - }), - Space: new THREE.MeshStandardMaterial({ - envMap: environment, - side: THREE.DoubleSide, - transparent: true, - opacity: 0.66, - roughness: 0.01, - metalness: 0.99, + onBeforeCompile: shader => { + shader.vertexShader = ` + varying vec3 vPos; + ${shader.vertexShader} + `.replace( + '#include ', + ` + #include + vPos = position; + + // Bruit basé sur la position du sommet pour irrégularité + float n = sin(position.x*3.1 + position.y*5.2 + position.z*7.3) * 0.03; + transformed += normal * n; + ` + ); + } }) } -InstancedMino.prototype.materials['Plasma'].onBeforeCompile = shader => { - shader.vertexShader = ` - varying vec3 vPos; - ${shader.vertexShader} - `.replace( - '#include ', - ` - #include - vPos = position; - - // Bruit basé sur la position du sommet pour irrégularité - float n = sin(position.x*3.1 + position.y*5.2 + position.z*7.3) * 0.03; - transformed += normal * n; - ` - ); -}; class Mino extends THREE.Object3D { @@ -498,10 +490,10 @@ class Playfield extends THREE.Group { color: COLORS.RETRO, map: retroEdgeTexture, bumpMap: retroEdgeTexture, + bumpScale: 1.5, envMap: environment, envMapIntensity: 5, - bumpScale: 1.5, - roughness: 0.07, + roughness: 0.03, metalness: 1 }) this.retroEdge = new THREE.Mesh(