fix audio restart, game restart, pause on gui

This commit is contained in:
2023-07-18 21:49:14 +02:00
parent 401218bdbe
commit b34a968dd2
4 changed files with 41 additions and 40 deletions

View File

@ -7,7 +7,6 @@ import { Mino, environnement } from './gamelogic.js'
export class TetraGUI extends GUI {
constructor(game, settings, stats, scene) {
super({title: "teTra"})
this.domElement.tabIndex = 1
this.startButton = this.add(game, "start").name("Jouer").hide()
this.pauseButton = this.add(game, "pause").name("Pause").hide()
@ -45,7 +44,7 @@ export class TetraGUI extends GUI {
})
loadingManager.onLoad = function() {
scene.vortex.darkCylinder.material.map = darkTexture
scene.vortex.darkCylinder.material.opacity = 0.006
scene.vortex.darkCylinder.material.opacity = 0.03
scene.vortex.colorFullCylinder.material.map = colorfullTexture
scene.vortex.colorFullCylinder.material.opacity = 0.7

View File

@ -27,7 +27,7 @@ export class Vortex extends THREE.Group {
texture.repeat.set(1, 1)
}),
blending: THREE.AdditiveBlending,
opacity: 0.006
opacity: 0.03
})
)
this.add(this.darkCylinder)

View File

@ -141,12 +141,16 @@ class Mino extends THREE.Object3D {
this.position.addScaledVector(this.velocity, delta)
this.rotateOnWorldAxis(this.rotationAngle, delta * this.angularVelocity)
if (Math.sqrt(this.position.x * this.position.x + this.position.z * this.position.z) > 40 || this.position.y < -50) {
this.constructor.mesh.delete(this)
this.dispose()
return false
} else {
return true
}
}
dispose() {
this.constructor.mesh.delete(this)
}
}
@ -388,16 +392,18 @@ class Playfield extends THREE.Group {
this.hardDropAnimation.setDuration(0.2)
this.freedMinoes = new Set()
this.init()
}
init() {
this.cells = Array(ROWS).fill().map(() => Array(COLUMNS))
if (this.piece) this.remove(this.piece)
this.piece = undefined
this.ghost = new Ghost()
this.ghost.visible = false
this.add(this.ghost)
this.visible = true
}
cellIsEmpty(p) {
@ -421,12 +427,16 @@ class Playfield extends THREE.Group {
lock() {
this.piece.locking = false
return Array.from(this.piece.children).every(mino => {
let minoes = Array.from(this.piece.children)
minoes.forEach(mino => {
this.add(mino)
mino.position.add(this.piece.position)
})
if (minoes.every(mino => mino.position.y >= SKYLINE)) return false
return minoes.every(mino => {
if (this.cellIsEmpty(mino.position)) {
this.cells[mino.position.y][mino.position.x] = mino
return mino.position.y < SKYLINE
return true
} else {
return false
}
@ -490,17 +500,14 @@ class NextQueue extends THREE.Group {
}
init() {
this.positions.forEach((position) => {
this.add(new Tetromino.random(position))
})
this.clear()
this.positions.forEach(position => this.add(new Tetromino.random(position)))
}
shift() {
let fistPiece = this.children.shift()
this.add(new Tetromino.random())
this.positions.forEach((position, i) => {
this.children[i].position.copy(position)
})
this.positions.forEach((position, i) => this.children[i].position.copy(position))
return fistPiece
}