From 7acb3a6def571d7ca864e42eeef337f0c1266a45 Mon Sep 17 00:00:00 2001 From: adrien Date: Mon, 17 Jul 2023 02:56:21 +0200 Subject: [PATCH] fix ghost --- app.js | 2 ++ jsm/TetraGUI.js | 2 +- jsm/gamelogic.js | 24 ++++++++++-------------- 3 files changed, 13 insertions(+), 15 deletions(-) diff --git a/app.js b/app.js index e816e1e..45ad13d 100644 --- a/app.js +++ b/app.js @@ -27,6 +27,8 @@ let game = { stats.init() gui.stats.show() gui.settings.close() + + Mino.instances.clear() holdQueue.remove(holdQueue.piece) holdQueue.piece = undefined diff --git a/jsm/TetraGUI.js b/jsm/TetraGUI.js index cad2d2e..8397659 100644 --- a/jsm/TetraGUI.js +++ b/jsm/TetraGUI.js @@ -152,7 +152,7 @@ export class TetraGUI extends GUI { if ("reflectivity" in Mino.mesh.material) material.add(Mino.mesh.material, "reflectivity").min(0).max(1) if ("roughness" in Mino.mesh.material) material.add(Mino.mesh.material, "roughness").min(0).max(1) if ("metalness" in Mino.mesh.material) material.add(Mino.mesh.material, "metalness").min(0).max(1) - if ("attenuationDistance" in Mino.mesh.material) material.add(Mino.mesh.material, "attenuationDistance").min(0).max(1) + if ("attenuationDistance" in Mino.mesh.material) material.add(Mino.mesh.material, "attenuationDistance").min(0) if ("ior" in Mino.mesh.material) material.add(Mino.mesh.material, "ior").min(1).max(2) if ("sheen" in Mino.mesh.material) material.add(Mino.mesh.material, "sheen").min(0).max(1) if ("sheenRoughness" in Mino.mesh.material) material.add(Mino.mesh.material, "sheenRoughness").min(0).max(1) diff --git a/jsm/gamelogic.js b/jsm/gamelogic.js index fd900b3..d661354 100644 --- a/jsm/gamelogic.js +++ b/jsm/gamelogic.js @@ -96,8 +96,7 @@ class Mino extends THREE.Object3D { roughness: 0.1, metalness: 0.95, }) - /* - let minoMaterial = new THREE.MeshPhysicalMaterial({ + /*let minoMaterial = new THREE.MeshPhysicalMaterial({ envMap: environnement, side: THREE.DoubleSide, transparent: true, @@ -116,10 +115,10 @@ class Mino extends THREE.Object3D { this.mesh = new THREE.InstancedMesh(minoGeometry, minoMaterial, 2*ROWS*COLUMNS) } - static update(delta) { + static update() { let i = 0 this.instances.forEach(mino => { - if (mino.parent.visible) { + if (mino.parent?.visible) { mino.updateMatrixWorld() this.mesh.setColorAt(i, mino.color) this.mesh.setMatrixAt(i, mino.matrixWorld) @@ -146,7 +145,7 @@ class Mino extends THREE.Object3D { this.velocity.y += delta * GRAVITY this.position.addScaledVector(this.velocity, delta) this.rotateOnWorldAxis(this.rotationAngle, delta * this.angularVelocity) - if (Math.sqrt(mino.position.x * mino.position.x + mino.position.z * mino.position.z) > 40 || mino.position.y < -50) { + if (Math.sqrt(this.position.x * this.position.x + this.position.z * this.position.z) > 40 || this.position.y < -50) { this.dispose() return false } else { @@ -255,15 +254,13 @@ Tetromino.prototype.lockDelay = 500 class Ghost extends Tetromino { - copy(piece) { this.position.copy(piece.position) this.minoesPosition = piece.minoesPosition this.facing = piece.facing - while (this.canMove(TRANSLATION.DOWN)) this.position.y-- this.visible = true + while (this.canMove(TRANSLATION.DOWN)) this.position.y-- } - } Ghost.prototype.freeColor = new THREE.Color(COLORS.GHOST) Ghost.prototype.minoesPosition = [ @@ -400,10 +397,6 @@ class Playfield extends THREE.Group { this.hardDropAnimation.loop = THREE.LoopOnce this.hardDropAnimation.setDuration(0.2) - this.ghost = new Ghost() - this.add(this.ghost) - this.ghost.visible = false - this.freedMinoes = new Set() this.init() @@ -411,7 +404,10 @@ class Playfield extends THREE.Group { init() { this.cells = Array(ROWS).fill().map(() => Array(COLUMNS)) - this.lockedMeshes.count = 0 + + this.ghost = new Ghost() + this.ghost.visible = false + this.add(this.ghost) } cellIsEmpty(p) { @@ -514,11 +510,11 @@ class NextQueue extends THREE.Group { shift() { let fistPiece = this.pieces.shift() let lastPiece = new Tetromino.random() - this.add(lastPiece) this.pieces.push(lastPiece) this.positions.forEach((position, i) => { this.pieces[i].position.copy(position) }) + this.add(lastPiece) return fistPiece }