background switcher

This commit is contained in:
Adrien MALINGREY 2023-07-08 17:33:04 +02:00
parent f0f3b2aca5
commit 9877f21818
4 changed files with 53 additions and 4 deletions

BIN
images/colorfull.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 330 KiB

BIN
images/dark.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 977 KiB

View File

@ -1,3 +1,4 @@
import * as THREE from 'three'
import { GUI } from 'three/addons/libs/lil-gui.module.min.js' import { GUI } from 'three/addons/libs/lil-gui.module.min.js'
import * as FPS from 'three/addons/libs/stats.module.js' import * as FPS from 'three/addons/libs/stats.module.js'
import { I, J, L, O, S, T, Z } from './gamelogic.js' import { I, J, L, O, S, T, Z } from './gamelogic.js'
@ -27,6 +28,52 @@ class TetraGUI extends GUI {
this.settings = this.addFolder("Options").open() this.settings = this.addFolder("Options").open()
this.settings.add(settings, "startLevel").name("Niveau initial").min(1).max(15).step(1) this.settings.add(settings, "startLevel").name("Niveau initial").min(1).max(15).step(1)
this.settings.add(scene.vortex, "background", ["Plasma", "Espace"]).name("Fond").onChange(background => {
const loadingManager = new THREE.LoadingManager()
let darkTexture, colorfullTexture
switch (background) {
case "Plasma":
darkTexture = new THREE.TextureLoader(loadingManager).load("./images/plasma.jpg", texture => {
texture.wrapS = THREE.RepeatWrapping
texture.wrapT = THREE.MirroredRepeatWrapping
texture.repeat.set(1, 1)
})
colorfullTexture = new THREE.TextureLoader(loadingManager).load("./images/plasma2.jpg", texture => {
texture.wrapS = THREE.RepeatWrapping
texture.wrapT = THREE.MirroredRepeatWrapping
texture.repeat.set(2, 1)
})
loadingManager.onLoad = function() {
scene.vortex.darkCylinder.material.map = darkTexture
scene.vortex.darkCylinder.material.opacity = 0.1
scene.vortex.colorFullCylinder.material.map = colorfullTexture
scene.vortex.colorFullCylinder.material.opacity = 0.6
}
scene.ambientLight.intensity = 2
scene.directionalLight.intensity = 3
break
case "Espace":
darkTexture = new THREE.TextureLoader(loadingManager).load("./images/dark.jpg", texture => {
texture.wrapS = THREE.RepeatWrapping
texture.wrapT = THREE.MirroredRepeatWrapping
texture.repeat.set(1, 1)
})
colorfullTexture = new THREE.TextureLoader(loadingManager).load("./images/colorfull.jpg", texture => {
texture.wrapS = THREE.RepeatWrapping
texture.wrapT = THREE.MirroredRepeatWrapping
texture.repeat.set(1, 1)
})
loadingManager.onLoad = function() {
scene.vortex.darkCylinder.material.map = darkTexture
scene.vortex.darkCylinder.material.opacity = 0.2
scene.vortex.colorFullCylinder.material.map = colorfullTexture
scene.vortex.colorFullCylinder.material.opacity = 0.2
scene.ambientLight.intensity = 2
scene.directionalLight.intensity = 3
}
break
}
})
this.settings.key = this.settings.addFolder("Commandes").open() this.settings.key = this.settings.addFolder("Commandes").open()
let moveLeftKeyController = this.settings.key.add(settings.key, "moveLeft").name('Gauche') let moveLeftKeyController = this.settings.key.add(settings.key, "moveLeft").name('Gauche')
@ -51,7 +98,7 @@ class TetraGUI extends GUI {
this.settings.delay.add(settings,"dasDelay").name("DAS (ms)").min(100).max(500).step(5); this.settings.delay.add(settings,"dasDelay").name("DAS (ms)").min(100).max(500).step(5);
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 => {
if (volume) { if (volume) {
scene.music.setVolume(volume/100) scene.music.setVolume(volume/100)
if (game.playing) scene.music.play() if (game.playing) scene.music.play()
@ -59,7 +106,7 @@ class TetraGUI extends GUI {
scene.music.pause() 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)
scene.tetrisSound.setVolume(volume/100) scene.tetrisSound.setVolume(volume/100)
scene.hardDropSound.setVolume(volume/100) scene.hardDropSound.setVolume(volume/100)

View File

@ -15,12 +15,14 @@ class Vortex extends THREE.Group {
super() super()
const commonCylinderGeometry = new THREE.CylinderGeometry(35, 35, 500, 12, 1, true) const commonCylinderGeometry = new THREE.CylinderGeometry(35, 35, 500, 12, 1, true)
this.background = "Plasma"
this.darkCylinder = new THREE.Mesh( this.darkCylinder = new THREE.Mesh(
commonCylinderGeometry, commonCylinderGeometry,
new THREE.MeshLambertMaterial({ new THREE.MeshLambertMaterial({
side: THREE.BackSide, side: THREE.BackSide,
map: new THREE.TextureLoader(loadingManager).load("images/plasma.jpg", (texture) => { map: new THREE.TextureLoader(loadingManager).load("./images/plasma.jpg", (texture) => {
texture.wrapS = THREE.RepeatWrapping texture.wrapS = THREE.RepeatWrapping
texture.wrapT = THREE.MirroredRepeatWrapping texture.wrapT = THREE.MirroredRepeatWrapping
texture.repeat.set(1, 1) texture.repeat.set(1, 1)
@ -36,7 +38,7 @@ class Vortex extends THREE.Group {
commonCylinderGeometry, commonCylinderGeometry,
new THREE.MeshBasicMaterial({ new THREE.MeshBasicMaterial({
side: THREE.BackSide, side: THREE.BackSide,
map: new THREE.TextureLoader(loadingManager).load("images/plasma2.jpg", (texture) => { map: new THREE.TextureLoader(loadingManager).load("./images/plasma2.jpg", (texture) => {
texture.wrapS = THREE.RepeatWrapping texture.wrapS = THREE.RepeatWrapping
texture.wrapT = THREE.MirroredRepeatWrapping texture.wrapT = THREE.MirroredRepeatWrapping
texture.repeat.set(2, 1) texture.repeat.set(2, 1)