This commit is contained in:
Adrien MALINGREY 2023-07-03 23:51:11 +02:00
parent ab63295d25
commit 5db16ad50e
9 changed files with 56 additions and 36 deletions

92
app.js
View File

@ -254,10 +254,11 @@ class MinoMaterial extends THREE.MeshBasicMaterial {
super({ super({
side: THREE.DoubleSide, side: THREE.DoubleSide,
color: color, color: color,
reflectivity: 0.95,
envMap: minoRenderTarget.texture, envMap: minoRenderTarget.texture,
roughness: 0.1, reflectivity: 0.97,
metalness: 0.25 //roughness: 0,
//metalness: 0.85,
}) })
} }
@ -504,7 +505,8 @@ class KeyMapper {
set key(key) { set key(key) {
key = KEY_NAMES[key] key = KEY_NAMES[key]
if (this.constructor.actions[this.prevKey] == this.action) delete this.constructor.actions[this.prevKey] if (this.constructor.actions[this.prevKey] == this.action)
delete this.constructor.actions[this.prevKey]
this.prevKey = key this.prevKey = key
this.constructor.actions[key] = this.action this.constructor.actions[key] = this.action
} }
@ -573,7 +575,7 @@ class Settings {
this.gui.volumeFolder.add(this,"musicVolume").name("Musique").min(0).max(100).step(1).onChange((volume) => { this.gui.volumeFolder.add(this,"musicVolume").name("Musique").min(0).max(100).step(1).onChange((volume) => {
music.setVolume(volume/100) music.setVolume(volume/100)
}) })
this.gui.volumeFolder.add(this,"sfxVolume").name("SFX").min(0).max(100).step(1).onChange((volume) => { this.gui.volumeFolder.add(this,"sfxVolume").name("Effets").min(0).max(100).step(1).onChange((volume) => {
lineClearSound.setVolume(volume/100) lineClearSound.setVolume(volume/100)
tetrisSound.setVolume(volume/100) tetrisSound.setVolume(volume/100)
hardDropSound.setVolume(volume/100) hardDropSound.setVolume(volume/100)
@ -811,7 +813,7 @@ controls.minPolarAngle = 0.9
controls.maxPolarAngle = 2.14 controls.maxPolarAngle = 2.14
controls.minAzimuthAngle = 0.9 - Math.PI / 2 controls.minAzimuthAngle = 0.9 - Math.PI / 2
controls.maxAzimuthAngle = 2.14 - Math.PI / 2 controls.maxAzimuthAngle = 2.14 - Math.PI / 2
controls.target = P(5, 9) controls.target.set(5, 9, 0)
controls.update() controls.update()
controls.addEventListener("start", () => renderer.domElement.style.cursor = "grabbing") controls.addEventListener("start", () => renderer.domElement.style.cursor = "grabbing")
@ -821,29 +823,26 @@ const debug = window.location.search.includes("debug")
const fps = new FPS.default(); const fps = new FPS.default();
if (debug) document.body.appendChild(fps.dom); if (debug) document.body.appendChild(fps.dom);
const GLOBAL_ROTATION = 0.028
const GLOBAL_ROTATION = 0.15625 const darkTextureRotation = 0.006
const darkMoveForward = -0.017
const darkTextureRotation = 0.0375 const colorFullTextureRotation = 0.006
const darkMoveForward = -0.04375 const colorFullMoveForward = -0.01
const darkOpacity = 0.2
const colorFullTextureRotation = 0.0375
const colorFullMoveForward = -0.075
const colorFullOpacity = 0.2
const commonCylinderGeometry = new THREE.CylinderGeometry(25, 25, 500, 12, 1, true) const commonCylinderGeometry = new THREE.CylinderGeometry(25, 25, 500, 12, 1, true)
// dark space full of stars - background cylinder const darkCylinderTexture = new THREE.TextureLoader(loadingManager).load("images/plasma2.jpg", (texture) => {
const darkCylinderTexture = new THREE.TextureLoader(loadingManager).load("images/dark.jpg") texture.wrapS = THREE.RepeatWrapping
darkCylinderTexture.wrapS = THREE.RepeatWrapping texture.wrapT = THREE.MirroredRepeatWrapping
darkCylinderTexture.wrapT = THREE.MirroredRepeatWrapping texture.repeat.set(1, 1)
darkCylinderTexture.repeat.set(1, 1) })
const darkCylinderMaterial = new THREE.MeshLambertMaterial({ const darkCylinderMaterial = new THREE.MeshLambertMaterial({
side: THREE.BackSide, side: THREE.BackSide,
map: darkCylinderTexture, map: darkCylinderTexture,
blending: THREE.AdditiveBlending, blending: THREE.AdditiveBlending,
opacity: darkOpacity opacity: 1
}) })
const darkCylinder = new THREE.Mesh( const darkCylinder = new THREE.Mesh(
commonCylinderGeometry, commonCylinderGeometry,
@ -852,16 +851,16 @@ const darkCylinder = new THREE.Mesh(
darkCylinder.position.set(5, 10, -10) darkCylinder.position.set(5, 10, -10)
scene.add(darkCylinder) scene.add(darkCylinder)
// colourfull space full of nebulas - main universe cylinder const colorFullCylinderTexture = new THREE.TextureLoader(loadingManager).load("images/plasma.jpg", (texture) => {
const colorFullCylinderTexture = new THREE.TextureLoader(loadingManager).load("images/colorfull.jpg") texture.wrapS = THREE.RepeatWrapping
colorFullCylinderTexture.wrapS = THREE.RepeatWrapping texture.wrapT = THREE.MirroredRepeatWrapping
colorFullCylinderTexture.wrapT = THREE.MirroredRepeatWrapping texture.repeat.set(1, 1)
colorFullCylinderTexture.repeat.set(1, 1) })
const colorFullCylinderMaterial = new THREE.MeshBasicMaterial({ const colorFullCylinderMaterial = new THREE.MeshBasicMaterial({
side: THREE.BackSide, side: THREE.BackSide,
map: colorFullCylinderTexture, map: colorFullCylinderTexture,
blending: THREE.AdditiveBlending, blending: THREE.AdditiveBlending,
opacity: colorFullOpacity opacity: 0.05
}) })
const colorFullCylinder = new THREE.Mesh( const colorFullCylinder = new THREE.Mesh(
commonCylinderGeometry, commonCylinderGeometry,
@ -870,18 +869,19 @@ const colorFullCylinder = new THREE.Mesh(
colorFullCylinder.position.set(5, 10, -10) colorFullCylinder.position.set(5, 10, -10)
scene.add(colorFullCylinder) scene.add(colorFullCylinder)
const ambientLight = new THREE.AmbientLight(0xffffff, 2) const ambientLight = new THREE.AmbientLight(0xffffff, 0.3)
scene.add(ambientLight) scene.add(ambientLight)
const directionalLight = new THREE.DirectionalLight(0xffffff, 3) const directionalLight = new THREE.DirectionalLight(0xffffff, 5)
directionalLight.position.set(5, -30, 0) directionalLight.position.set(5, -100, -16)
scene.add(directionalLight) scene.add(directionalLight)
const edgeMaterial = new THREE.MeshBasicMaterial({ const edgeMaterial = new THREE.MeshBasicMaterial({
color: 0x88abe0, color: 0x88abe0,
transparent: true, transparent: true,
opacity: 0.5, opacity: 0.3,
reflectivity: 0.9, reflectivity: 0.9,
refractionRatio: 0.5,
envMap: minoRenderTarget.texture envMap: minoRenderTarget.texture
}) })
@ -903,6 +903,7 @@ const edge = new THREE.Mesh(
new THREE.ExtrudeGeometry(edgeShape, edgeExtrudeSettings), new THREE.ExtrudeGeometry(edgeShape, edgeExtrudeSettings),
edgeMaterial edgeMaterial
) )
edge.visible = false
scene.add(edge) scene.add(edge)
const holdQueue = new THREE.Group() const holdQueue = new THREE.Group()
@ -987,6 +988,8 @@ let game = {
stats.gui.show() stats.gui.show()
settings.gui.close() settings.gui.close()
edge.visible = true
this.playing = true this.playing = true
stats.clock.start() stats.clock.start()
@ -1020,6 +1023,7 @@ let game = {
piece.position.set(4, SKYLINE) piece.position.set(4, SKYLINE)
scene.add(piece) scene.add(piece)
ghost.copy(piece) ghost.copy(piece)
//directionalLight.target = piece
scene.add(ghost) scene.add(ghost)
if (piece.canMove(TRANSLATION.NONE)) { if (piece.canMove(TRANSLATION.NONE)) {
@ -1145,12 +1149,12 @@ audioLoader.load('audio/Tetris_CheDDer_OC_ReMix.mp3', function( buffer ) {
if (game.playing) music.play() if (game.playing) music.play()
}) })
const lineClearSound = new THREE.Audio(listener) const lineClearSound = new THREE.Audio(listener)
audioLoader.load('audio/line-clear.wav', function( buffer ) { audioLoader.load('audio/line-clear.ogg', function( buffer ) {
lineClearSound.setBuffer(buffer) lineClearSound.setBuffer(buffer)
lineClearSound.setVolume(settings.sfxVolume/100) lineClearSound.setVolume(settings.sfxVolume/100)
}) })
const tetrisSound = new THREE.Audio(listener) const tetrisSound = new THREE.Audio(listener)
audioLoader.load('audio/tetris.wav', function( buffer ) { audioLoader.load('audio/tetris.ogg', function( buffer ) {
tetrisSound.setBuffer(buffer) tetrisSound.setBuffer(buffer)
tetrisSound.setVolume(settings.sfxVolume/100) tetrisSound.setVolume(settings.sfxVolume/100)
}) })
@ -1168,10 +1172,26 @@ let settings = new Settings(gui)
if (debug) { if (debug) {
let debugFolder = gui.addFolder("debug") let debugFolder = gui.addFolder("debug")
let cameraPosition = debugFolder.addFolder("camera.position") let cameraPositionFolder = debugFolder.addFolder("camera.position")
cameraPosition.add(camera.position, "x") cameraPositionFolder.add(camera.position, "x")
cameraPosition.add(camera.position, "y") cameraPositionFolder.add(camera.position, "y")
cameraPosition.add(camera.position, "z") cameraPositionFolder.add(camera.position, "z")
let lightFolder = debugFolder.addFolder("lights intensity")
lightFolder.add(ambientLight, "intensity").name("ambient").min(-15).max(15)
lightFolder.add(directionalLight, "intensity").name("directional").min(-15).max(15)
let materialsFolder = debugFolder.addFolder("materials opacity")
materialsFolder.add(darkCylinderMaterial, "opacity").name("dark").min(0).max(1)
materialsFolder.add(colorFullCylinderMaterial, "opacity").name("colorFull").min(0).max(1)
materialsFolder.add(I.prototype.material, "reflectivity").min(0).max(2).onChange(() => {
J.prototype.material.reflectivity = I.prototype.material.reflectivity
L.prototype.material.reflectivity = I.prototype.material.reflectivity
O.prototype.material.reflectivity = I.prototype.material.reflectivity
S.prototype.material.reflectivity = I.prototype.material.reflectivity
T.prototype.material.reflectivity = I.prototype.material.reflectivity
Z.prototype.material.reflectivity = I.prototype.material.reflectivity
})
} }
game.init() game.init()

BIN
audio/line-clear.ogg Normal file

Binary file not shown.

Binary file not shown.

BIN
audio/tetris.ogg Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 330 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 977 KiB

BIN
images/plasma.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 128 KiB

BIN
images/plasma2.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 60 KiB