spread out unlocked minoes
This commit is contained in:
parent
dd1c0fe0c6
commit
55bc6be4bd
27
app.js
27
app.js
@ -126,6 +126,7 @@ class Scheduler {
|
|||||||
class Matrix extends THREE.Group {
|
class Matrix extends THREE.Group {
|
||||||
init() {
|
init() {
|
||||||
this.cells = Array(ROWS).fill().map(() => Array(COLUMNS))
|
this.cells = Array(ROWS).fill().map(() => Array(COLUMNS))
|
||||||
|
this.unlockedMinoes = new Set()
|
||||||
}
|
}
|
||||||
|
|
||||||
cellIsEmpty(p) {
|
cellIsEmpty(p) {
|
||||||
@ -153,7 +154,7 @@ class Matrix extends THREE.Group {
|
|||||||
let row = this.cells[y]
|
let row = this.cells[y]
|
||||||
if (row.filter(mino => mino).length == COLUMNS) {
|
if (row.filter(mino => mino).length == COLUMNS) {
|
||||||
nbClearedLines++
|
nbClearedLines++
|
||||||
row.forEach(mino => this.remove(mino))
|
row.forEach(mino => this.unlockedMinoes.add(mino))
|
||||||
this.cells.splice(y, 1)
|
this.cells.splice(y, 1)
|
||||||
this.cells.push(Array(COLUMNS))
|
this.cells.push(Array(COLUMNS))
|
||||||
}
|
}
|
||||||
@ -167,6 +168,16 @@ class Matrix extends THREE.Group {
|
|||||||
}
|
}
|
||||||
return nbClearedLines
|
return nbClearedLines
|
||||||
}
|
}
|
||||||
|
|
||||||
|
updateUnlockedMinoes(delta) {
|
||||||
|
this.unlockedMinoes.forEach(mino => {
|
||||||
|
mino.update(delta)
|
||||||
|
if (Math.sqrt(mino.position.x*mino.position.x + mino.position.z*mino.position.z) > 25) {
|
||||||
|
this.remove(mino)
|
||||||
|
this.unlockedMinoes.delete(mino)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -197,8 +208,16 @@ NextQueue.prototype.positions = [P(0, 0, 0), P(0, -4, 0), P(0, -8, 0), P(0, -12,
|
|||||||
class Mino extends THREE.Mesh {
|
class Mino extends THREE.Mesh {
|
||||||
constructor() {
|
constructor() {
|
||||||
super(Mino.prototype.geometry)
|
super(Mino.prototype.geometry)
|
||||||
|
this.velocity = P(5-10*Math.random(), 5-10*Math.random(), 5-10*Math.random())
|
||||||
|
this.rotationAngle = P(Math.random(), Math.random(), Math.random()).normalize()
|
||||||
|
this.angularVelocity = 5-10*Math.random()
|
||||||
scene.add(this)
|
scene.add(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
update(delta) {
|
||||||
|
this.position.addScaledVector(this.velocity, delta)
|
||||||
|
this.rotateOnWorldAxis(this.rotationAngle, delta*this.angularVelocity)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
const minoFaceShape = new THREE.Shape()
|
const minoFaceShape = new THREE.Shape()
|
||||||
minoFaceShape.moveTo(.1, .1)
|
minoFaceShape.moveTo(.1, .1)
|
||||||
@ -887,6 +906,8 @@ window.addEventListener("resize", () => {
|
|||||||
camera.updateProjectionMatrix()
|
camera.updateProjectionMatrix()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
let clock = new THREE.Clock()
|
||||||
|
|
||||||
function animate() {
|
function animate() {
|
||||||
requestAnimationFrame(animate)
|
requestAnimationFrame(animate)
|
||||||
|
|
||||||
@ -898,7 +919,9 @@ function animate() {
|
|||||||
colorFullCylinderTexture.offset.y -= COLORFULL_MOVE_FORWARD
|
colorFullCylinderTexture.offset.y -= COLORFULL_MOVE_FORWARD
|
||||||
colorFullCylinderTexture.offset.x -= COLORFULL_TEXTURE_ROTATION
|
colorFullCylinderTexture.offset.x -= COLORFULL_TEXTURE_ROTATION
|
||||||
|
|
||||||
controls.update();
|
controls.update()
|
||||||
|
|
||||||
|
matrix.updateUnlockedMinoes(clock.getDelta())
|
||||||
|
|
||||||
renderer.render(scene, camera)
|
renderer.render(scene, camera)
|
||||||
minoCamera.update(renderer, scene)
|
minoCamera.update(renderer, scene)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user