grab cursor
This commit is contained in:
parent
2ba22ee7da
commit
af24f0a6ef
190
app.js
190
app.js
@ -2,11 +2,11 @@ import * as THREE from 'three'
|
||||
import { OrbitControls } from 'three/addons/controls/OrbitControls.js'
|
||||
import * as FPS from 'three/addons/libs/stats.module.js';
|
||||
|
||||
let P = (x, y, z=0) => new THREE.Vector3(x, y, z)
|
||||
let P = (x, y, z = 0) => new THREE.Vector3(x, y, z)
|
||||
|
||||
Array.prototype.pick = function() { return this.splice(Math.floor(Math.random()*this.length), 1)[0] }
|
||||
Array.prototype.pick = function () { return this.splice(Math.floor(Math.random() * this.length), 1)[0] }
|
||||
|
||||
HTMLElement.prototype.addNewChild = function(tag, properties) {
|
||||
HTMLElement.prototype.addNewChild = function (tag, properties) {
|
||||
let child = document.createElement(tag)
|
||||
for (let key in properties) {
|
||||
child[key] = properties[key]
|
||||
@ -34,10 +34,10 @@ const FACING = {
|
||||
}
|
||||
|
||||
const TRANSLATION = {
|
||||
NONE: P( 0, 0),
|
||||
NONE: P(0, 0),
|
||||
LEFT: P(-1, 0),
|
||||
RIGHT: P( 1, 0),
|
||||
DOWN: P( 0, -1),
|
||||
RIGHT: P(1, 0),
|
||||
DOWN: P(0, -1),
|
||||
}
|
||||
|
||||
const ROTATION = {
|
||||
@ -141,7 +141,7 @@ class Matrix extends THREE.Group {
|
||||
|
||||
clearLines() {
|
||||
let nbClearedLines = 0
|
||||
for (let y=ROWS-1; y>=0; y--) {
|
||||
for (let y = ROWS - 1; y >= 0; y--) {
|
||||
let row = this.cells[y]
|
||||
if (row.filter(mino => mino).length == COLUMNS) {
|
||||
nbClearedLines++
|
||||
@ -163,7 +163,7 @@ class Matrix extends THREE.Group {
|
||||
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) {
|
||||
if (Math.sqrt(mino.position.x * mino.position.x + mino.position.z * mino.position.z) > 25) {
|
||||
this.remove(mino)
|
||||
this.unlockedMinoes.delete(mino)
|
||||
}
|
||||
@ -202,16 +202,16 @@ const GRAVITY = -20
|
||||
class Mino extends THREE.Mesh {
|
||||
constructor() {
|
||||
super(Mino.prototype.geometry)
|
||||
this.velocity = P(50-100*Math.random(), 50-100*Math.random(), 50-100*Math.random())
|
||||
this.velocity = P(50 - 100 * Math.random(), 50 - 100 * Math.random(), 50 - 100 * Math.random())
|
||||
this.rotationAngle = P(Math.random(), Math.random(), Math.random()).normalize()
|
||||
this.angularVelocity = 5-10*Math.random()
|
||||
this.angularVelocity = 5 - 10 * Math.random()
|
||||
scene.add(this)
|
||||
}
|
||||
|
||||
update(delta) {
|
||||
this.velocity.y += delta * GRAVITY
|
||||
this.position.addScaledVector(this.velocity, delta)
|
||||
this.rotateOnWorldAxis(this.rotationAngle, delta*this.angularVelocity)
|
||||
this.rotateOnWorldAxis(this.rotationAngle, delta * this.angularVelocity)
|
||||
}
|
||||
}
|
||||
const minoFaceShape = new THREE.Shape()
|
||||
@ -234,7 +234,7 @@ Mino.prototype.geometry = new THREE.ExtrudeGeometry(minoFaceShape, minoExtrudeSe
|
||||
|
||||
class MinoMaterial extends THREE.MeshBasicMaterial {
|
||||
|
||||
constructor( color ) {
|
||||
constructor(color) {
|
||||
super({
|
||||
color: color,
|
||||
reflectivity: 0.9,
|
||||
@ -249,7 +249,7 @@ class MinoMaterial extends THREE.MeshBasicMaterial {
|
||||
|
||||
class GhostMaterial extends THREE.MeshBasicMaterial {
|
||||
|
||||
constructor( color ) {
|
||||
constructor(color) {
|
||||
super({
|
||||
side: THREE.DoubleSide,
|
||||
color: color,
|
||||
@ -274,7 +274,7 @@ class Tetromino extends THREE.Group {
|
||||
this.rotatedLast = false
|
||||
this.rotationPoint4Used = false
|
||||
this.holdEnabled = true
|
||||
for (let i=0; i<4; i++) {
|
||||
for (let i = 0; i < 4; i++) {
|
||||
this.add(new Mino())
|
||||
}
|
||||
this.facing = 0
|
||||
@ -305,7 +305,7 @@ class Tetromino extends THREE.Group {
|
||||
return this._locked
|
||||
}
|
||||
|
||||
canMove(translation, facing=this.facing) {
|
||||
canMove(translation, facing = this.facing) {
|
||||
let testPosition = this.position.clone().add(translation)
|
||||
return this.minoesPosition[facing].every(minoPosition => matrix.cellIsEmpty(minoPosition.clone().add(testPosition)))
|
||||
}
|
||||
@ -356,72 +356,72 @@ class Tetromino extends THREE.Group {
|
||||
// Super Rotation System
|
||||
// freedom of movement = srs[piece.facing][rotation]
|
||||
Tetromino.prototype.srs = [
|
||||
{ [ROTATION.CW]: [P(0, 0), P(-1, 0), P(-1, 1), P(0, -2), P(-1, -2)], [ROTATION.CCW]: [P(0, 0), P( 1, 0), P( 1, 1), P(0, -2), P( 1, -2)] },
|
||||
{ [ROTATION.CW]: [P(0, 0), P( 1, 0), P( 1, -1), P(0, 2), P( 1, 2)], [ROTATION.CCW]: [P(0, 0), P( 1, 0), P( 1, -1), P(0, 2), P( 1, 2)] },
|
||||
{ [ROTATION.CW]: [P(0, 0), P( 1, 0), P( 1, 1), P(0, -2), P( 1, -2)], [ROTATION.CCW]: [P(0, 0), P(-1, 0), P(-1, 1), P(0, -2), P(-1, -2)] },
|
||||
{ [ROTATION.CW]: [P(0, 0), P(-1, 0), P(-1, 1), P(0, -2), P(-1, -2)], [ROTATION.CCW]: [P(0, 0), P(1, 0), P(1, 1), P(0, -2), P(1, -2)] },
|
||||
{ [ROTATION.CW]: [P(0, 0), P(1, 0), P(1, -1), P(0, 2), P(1, 2)], [ROTATION.CCW]: [P(0, 0), P(1, 0), P(1, -1), P(0, 2), P(1, 2)] },
|
||||
{ [ROTATION.CW]: [P(0, 0), P(1, 0), P(1, 1), P(0, -2), P(1, -2)], [ROTATION.CCW]: [P(0, 0), P(-1, 0), P(-1, 1), P(0, -2), P(-1, -2)] },
|
||||
{ [ROTATION.CW]: [P(0, 0), P(-1, 0), P(-1, -1), P(0, 2), P(-1, 2)], [ROTATION.CCW]: [P(0, 0), P(-1, 0), P(-1, -1), P(0, 2), P(-1, 2)] },
|
||||
]
|
||||
const minoRenderTarget = new THREE.WebGLCubeRenderTarget(256)
|
||||
minoRenderTarget.texture.type = THREE.HalfFloatType
|
||||
const minoCamera = new THREE.CubeCamera(1, 1000, minoRenderTarget)
|
||||
minoCamera.position.set(5, 10)
|
||||
Tetromino.prototype.lockedMaterial = new MinoMaterial( 0xffffff )
|
||||
Tetromino.prototype.lockedMaterial = new MinoMaterial(0xffffff)
|
||||
|
||||
class I extends Tetromino {}
|
||||
class I extends Tetromino { }
|
||||
I.prototype.minoesPosition = [
|
||||
[P(-1, 0), P(0, 0), P(1, 0), P(2, 0)],
|
||||
[P( 1, 1), P(1, 0), P(1, -1), P(1, -2)],
|
||||
[P(1, 1), P(1, 0), P(1, -1), P(1, -2)],
|
||||
[P(-1, -1), P(0, -1), P(1, -1), P(2, -1)],
|
||||
[P( 0, 1), P(0, 0), P(0, -1), P(0, -2)],
|
||||
[P(0, 1), P(0, 0), P(0, -1), P(0, -2)],
|
||||
]
|
||||
I.prototype.srs = [
|
||||
{ [ROTATION.CW]: [P(0, 0), P(-2, 0), P( 1, 0), P(-2, -1), P( 1, 2)], [ROTATION.CCW]: [P(0, 0), P(-1, 0), P( 2, 0), P(-1, 2), P( 2, -1)] },
|
||||
{ [ROTATION.CW]: [P(0, 0), P(-1, 0), P( 2, 0), P(-1, 2), P( 2, -1)], [ROTATION.CCW]: [P(0, 0), P( 2, 0), P(-1, 0), P( 2, 1), P(-1, -2)] },
|
||||
{ [ROTATION.CW]: [P(0, 0), P( 2, 0), P(-1, 0), P( 2, 1), P(-1, -2)], [ROTATION.CCW]: [P(0, 0), P( 1, 0), P(-2, 0), P( 1, -2), P(-2, 1)] },
|
||||
{ [ROTATION.CW]: [P(0, 0), P( 1, 0), P(-2, 0), P( 1, -2), P(-2, 1)], [ROTATION.CCW]: [P(0, 0), P(-2, 0), P( 1, 0), P(-2, -1), P( 1, 2)] },
|
||||
{ [ROTATION.CW]: [P(0, 0), P(-2, 0), P(1, 0), P(-2, -1), P(1, 2)], [ROTATION.CCW]: [P(0, 0), P(-1, 0), P(2, 0), P(-1, 2), P(2, -1)] },
|
||||
{ [ROTATION.CW]: [P(0, 0), P(-1, 0), P(2, 0), P(-1, 2), P(2, -1)], [ROTATION.CCW]: [P(0, 0), P(2, 0), P(-1, 0), P(2, 1), P(-1, -2)] },
|
||||
{ [ROTATION.CW]: [P(0, 0), P(2, 0), P(-1, 0), P(2, 1), P(-1, -2)], [ROTATION.CCW]: [P(0, 0), P(1, 0), P(-2, 0), P(1, -2), P(-2, 1)] },
|
||||
{ [ROTATION.CW]: [P(0, 0), P(1, 0), P(-2, 0), P(1, -2), P(-2, 1)], [ROTATION.CCW]: [P(0, 0), P(-2, 0), P(1, 0), P(-2, -1), P(1, 2)] },
|
||||
]
|
||||
I.prototype.material = new MinoMaterial( 0xafeff9 )
|
||||
I.prototype.ghostMaterial = new GhostMaterial( 0xafeff9 )
|
||||
I.prototype.material = new MinoMaterial(0xafeff9)
|
||||
I.prototype.ghostMaterial = new GhostMaterial(0xafeff9)
|
||||
|
||||
class J extends Tetromino {}
|
||||
class J extends Tetromino { }
|
||||
J.prototype.minoesPosition = [
|
||||
[P(-1, 1), P(-1, 0), P(0, 0), P(1, 0)],
|
||||
[P( 0, 1), P( 1, 1), P(0, 0), P(0, -1)],
|
||||
[P( 1, -1), P(-1, 0), P(0, 0), P(1, 0)],
|
||||
[P( 0, 1), P(-1, -1), P(0, 0), P(0, -1)],
|
||||
[P(0, 1), P(1, 1), P(0, 0), P(0, -1)],
|
||||
[P(1, -1), P(-1, 0), P(0, 0), P(1, 0)],
|
||||
[P(0, 1), P(-1, -1), P(0, 0), P(0, -1)],
|
||||
]
|
||||
J.prototype.material = new MinoMaterial( 0xb8b4ff )
|
||||
J.prototype.ghostMaterial = new GhostMaterial( 0xb8b4ff )
|
||||
J.prototype.material = new MinoMaterial(0xb8b4ff)
|
||||
J.prototype.ghostMaterial = new GhostMaterial(0xb8b4ff)
|
||||
|
||||
class L extends Tetromino {}
|
||||
class L extends Tetromino { }
|
||||
L.prototype.minoesPosition = [
|
||||
[P(-1, 0), P(0, 0), P(1, 0), P( 1, 1)],
|
||||
[P(0, 1), P(0, 0), P(0, -1), P( 1, -1)],
|
||||
[P(-1, 0), P(0, 0), P(1, 0), P(1, 1)],
|
||||
[P(0, 1), P(0, 0), P(0, -1), P(1, -1)],
|
||||
[P(-1, 0), P(0, 0), P(1, 0), P(-1, -1)],
|
||||
[P(0, 1), P(0, 0), P(0, -1), P(-1, 1)],
|
||||
]
|
||||
L.prototype.material = new MinoMaterial( 0xfdd0b7 )
|
||||
L.prototype.ghostMaterial = new GhostMaterial( 0xfdd0b7 )
|
||||
L.prototype.material = new MinoMaterial(0xfdd0b7)
|
||||
L.prototype.ghostMaterial = new GhostMaterial(0xfdd0b7)
|
||||
|
||||
class O extends Tetromino {}
|
||||
class O extends Tetromino { }
|
||||
O.prototype.minoesPosition = [
|
||||
[P(0, 0), P(1, 0), P(0, 1), P(1, 1)]
|
||||
]
|
||||
O.prototype.srs = [
|
||||
{[ROTATION.CW]: [], [ROTATION.CCW]: []}
|
||||
{ [ROTATION.CW]: [], [ROTATION.CCW]: [] }
|
||||
]
|
||||
O.prototype.material = new MinoMaterial( 0xffedac )
|
||||
O.prototype.ghostMaterial = new GhostMaterial( 0xffedac )
|
||||
O.prototype.material = new MinoMaterial(0xffedac)
|
||||
O.prototype.ghostMaterial = new GhostMaterial(0xffedac)
|
||||
|
||||
class S extends Tetromino {}
|
||||
class S extends Tetromino { }
|
||||
S.prototype.minoesPosition = [
|
||||
[P(-1, 0), P(0, 0), P( 0, 1), P(1, 1)],
|
||||
[P( 0, 1), P(0, 0), P( 1, 0), P(1, -1)],
|
||||
[P(-1, -1), P(0, 0), P( 1, 0), P(0, -1)],
|
||||
[P(-1, 0), P(0, 0), P(0, 1), P(1, 1)],
|
||||
[P(0, 1), P(0, 0), P(1, 0), P(1, -1)],
|
||||
[P(-1, -1), P(0, 0), P(1, 0), P(0, -1)],
|
||||
[P(-1, 1), P(0, 0), P(-1, 0), P(0, -1)],
|
||||
]
|
||||
S.prototype.material = new MinoMaterial( 0xC8FBA8 )
|
||||
S.prototype.ghostMaterial = new GhostMaterial( 0xC8FBA8 )
|
||||
S.prototype.material = new MinoMaterial(0xC8FBA8)
|
||||
S.prototype.ghostMaterial = new GhostMaterial(0xC8FBA8)
|
||||
|
||||
class T extends Tetromino {
|
||||
get tSpin() {
|
||||
@ -437,29 +437,29 @@ class T extends Tetromino {
|
||||
}
|
||||
}
|
||||
T.prototype.minoesPosition = [
|
||||
[P(-1, 0), P(0, 0), P(1, 0), P( 0, 1)],
|
||||
[P( 0, 1), P(0, 0), P(1, 0), P( 0, -1)],
|
||||
[P(-1, 0), P(0, 0), P(1, 0), P( 0, -1)],
|
||||
[P( 0, 1), P(0, 0), P(0, -1), P(-1, 0)],
|
||||
[P(-1, 0), P(0, 0), P(1, 0), P(0, 1)],
|
||||
[P(0, 1), P(0, 0), P(1, 0), P(0, -1)],
|
||||
[P(-1, 0), P(0, 0), P(1, 0), P(0, -1)],
|
||||
[P(0, 1), P(0, 0), P(0, -1), P(-1, 0)],
|
||||
]
|
||||
T.prototype.tSlots = [
|
||||
[P(-1, 1), P( 1, 1), P( 1, -1), P(-1, -1)],
|
||||
[P( 1, 1), P( 1, -1), P(-1, -1), P(-1, 1)],
|
||||
[P( 1, -1), P(-1, -1), P(-1, 1), P( 1, 1)],
|
||||
[P(-1, -1), P(-1, 1), P( 1, 1), P( 1, -1)],
|
||||
[P(-1, 1), P(1, 1), P(1, -1), P(-1, -1)],
|
||||
[P(1, 1), P(1, -1), P(-1, -1), P(-1, 1)],
|
||||
[P(1, -1), P(-1, -1), P(-1, 1), P(1, 1)],
|
||||
[P(-1, -1), P(-1, 1), P(1, 1), P(1, -1)],
|
||||
]
|
||||
T.prototype.material = new MinoMaterial( 0xedb2ff )
|
||||
T.prototype.ghostMaterial = new GhostMaterial( 0xedb2ff )
|
||||
T.prototype.material = new MinoMaterial(0xedb2ff)
|
||||
T.prototype.ghostMaterial = new GhostMaterial(0xedb2ff)
|
||||
|
||||
class Z extends Tetromino {}
|
||||
class Z extends Tetromino { }
|
||||
Z.prototype.minoesPosition = [
|
||||
[P(-1, 1), P( 0, 1), P(0, 0), P( 1, 0)],
|
||||
[P( 1, 1), P( 1, 0), P(0, 0), P( 0, -1)],
|
||||
[P(-1, 0), P( 0, 0), P(0, -1), P( 1, -1)],
|
||||
[P( 0, 1), P(-1, 0), P(0, 0), P(-1, -1)]
|
||||
[P(-1, 1), P(0, 1), P(0, 0), P(1, 0)],
|
||||
[P(1, 1), P(1, 0), P(0, 0), P(0, -1)],
|
||||
[P(-1, 0), P(0, 0), P(0, -1), P(1, -1)],
|
||||
[P(0, 1), P(-1, 0), P(0, 0), P(-1, -1)]
|
||||
]
|
||||
Z.prototype.material = new MinoMaterial( 0xffb8c5 )
|
||||
Z.prototype.ghostMaterial = new GhostMaterial( 0xffb8c5 )
|
||||
Z.prototype.material = new MinoMaterial(0xffb8c5)
|
||||
Z.prototype.ghostMaterial = new GhostMaterial(0xffb8c5)
|
||||
|
||||
class Ghost extends Tetromino {
|
||||
copy(piece) {
|
||||
@ -537,7 +537,7 @@ class Settings {
|
||||
}
|
||||
}
|
||||
|
||||
window.changeKey = function(input) {
|
||||
window.changeKey = function (input) {
|
||||
let prevValue = input.value
|
||||
input.select()
|
||||
input.onkeydown = function (event) {
|
||||
@ -591,7 +591,7 @@ class Stats {
|
||||
set level(level) {
|
||||
this._level = level
|
||||
this.goal += level * 5
|
||||
if (level <= 20){
|
||||
if (level <= 20) {
|
||||
this.fallPeriod = 1000 * Math.pow(0.8 - ((level - 1) * 0.007), level - 1)
|
||||
}
|
||||
if (level > 15)
|
||||
@ -683,7 +683,7 @@ class Stats {
|
||||
}
|
||||
this.score += b2bScore
|
||||
}
|
||||
} else if (nbClearedLines && !tSpin ) {
|
||||
} else if (nbClearedLines && !tSpin) {
|
||||
if (this.b2b >= 1) {
|
||||
messagesSpan.addNewChild("div", {
|
||||
className: "zoom-in-animation",
|
||||
@ -728,18 +728,18 @@ Stats.prototype.timeFormat = new Intl.DateTimeFormat("fr-FR", {
|
||||
/* Scene */
|
||||
|
||||
const manager = new THREE.LoadingManager()
|
||||
manager.onStart = function ( url, itemsLoaded, itemsTotal ) {
|
||||
manager.onStart = function (url, itemsLoaded, itemsTotal) {
|
||||
messagesSpan.innerHTML = 'Chargement : 0%...'
|
||||
}
|
||||
manager.onLoad = function ( ) {
|
||||
manager.onLoad = function () {
|
||||
restart()
|
||||
messagesSpan.innerHTML = ""
|
||||
animate()
|
||||
}
|
||||
manager.onProgress = function ( url, itemsLoaded, itemsTotal ) {
|
||||
manager.onProgress = function (url, itemsLoaded, itemsTotal) {
|
||||
messagesSpan.innerHTML = 'Chargement : ' + 100 * itemsLoaded / itemsTotal + '%...'
|
||||
}
|
||||
manager.onError = function ( url ) {
|
||||
manager.onError = function (url) {
|
||||
messagesSpan.innerHTML = 'Erreur de chargement'
|
||||
}
|
||||
|
||||
@ -757,18 +757,21 @@ document.body.appendChild(renderer.domElement)
|
||||
const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000)
|
||||
camera.position.set(5, 1, 16)
|
||||
|
||||
const controls = new OrbitControls( camera, renderer.domElement )
|
||||
const controls = new OrbitControls(camera, renderer.domElement)
|
||||
controls.autoRotate
|
||||
controls.enableDamping
|
||||
controls.maxDistance = 21
|
||||
controls.keys = {}
|
||||
controls.minPolarAngle = 0.9
|
||||
controls.maxPolarAngle = 2.14
|
||||
controls.minAzimuthAngle = 0.9 - Math.PI/2
|
||||
controls.maxAzimuthAngle = 2.14 - Math.PI/2
|
||||
controls.minAzimuthAngle = 0.9 - Math.PI / 2
|
||||
controls.maxAzimuthAngle = 2.14 - Math.PI / 2
|
||||
controls.target = P(5, 10)
|
||||
controls.update()
|
||||
|
||||
controls.addEventListener("start", () => renderer.domElement.style.cursor = "grabbing")
|
||||
controls.addEventListener("end", () => renderer.domElement.style.cursor = "grab")
|
||||
|
||||
const showFPS = window.location.search.includes("fps")
|
||||
const fps = new FPS.default();
|
||||
if (showFPS) document.body.appendChild(fps.dom);
|
||||
@ -839,12 +842,12 @@ const edgeMaterial = new THREE.MeshBasicMaterial({
|
||||
|
||||
const edgeShape = new THREE.Shape()
|
||||
edgeShape.moveTo(-.3, SKYLINE)
|
||||
edgeShape.lineTo( 0, SKYLINE)
|
||||
edgeShape.lineTo( 0, 0)
|
||||
edgeShape.lineTo(0, SKYLINE)
|
||||
edgeShape.lineTo(0, 0)
|
||||
edgeShape.lineTo(COLUMNS, 0)
|
||||
edgeShape.lineTo(COLUMNS, SKYLINE)
|
||||
edgeShape.lineTo(COLUMNS+.3, SKYLINE)
|
||||
edgeShape.lineTo(COLUMNS+.3, -.3)
|
||||
edgeShape.lineTo(COLUMNS + .3, SKYLINE)
|
||||
edgeShape.lineTo(COLUMNS + .3, -.3)
|
||||
edgeShape.lineTo(-.3, -.3)
|
||||
edgeShape.moveTo(-.3, SKYLINE)
|
||||
const edgeExtrudeSettings = {
|
||||
@ -905,7 +908,7 @@ function animate() {
|
||||
|
||||
/* Game logic */
|
||||
|
||||
messagesSpan.onanimationend = function(event) {
|
||||
messagesSpan.onanimationend = function (event) {
|
||||
event.target.remove()
|
||||
}
|
||||
|
||||
@ -915,7 +918,7 @@ let stats = new Stats()
|
||||
let playing = false
|
||||
//let favicon = document.querySelector("link[rel~='icon']")
|
||||
|
||||
window.restart = function() {
|
||||
window.restart = function () {
|
||||
stats.modal.hide()
|
||||
stats.init()
|
||||
settings.init()
|
||||
@ -941,7 +944,6 @@ function pauseSettings() {
|
||||
|
||||
music.pause()
|
||||
document.onkeydown = null
|
||||
renderer.domElement.style.cursor = "auto"
|
||||
|
||||
settings.show()
|
||||
}
|
||||
@ -977,6 +979,7 @@ function resume(event) {
|
||||
if (settings.form.checkValidity()) {
|
||||
settings.modal.hide()
|
||||
settings.getInputs()
|
||||
renderer.domElement.focus()
|
||||
|
||||
document.onkeydown = onkeydown
|
||||
document.onkeyup = onkeyup
|
||||
@ -990,8 +993,6 @@ function resume(event) {
|
||||
music.play()
|
||||
}
|
||||
|
||||
renderer.domElement.style.cursor = "move"
|
||||
|
||||
if (piece) scheduler.setInterval(fall, stats.fallPeriod)
|
||||
else generate()
|
||||
}
|
||||
@ -1025,18 +1026,18 @@ let playerActions = {
|
||||
|
||||
rotateCounterclockwise: () => piece.rotate(ROTATION.CCW),
|
||||
|
||||
softDrop: function() {
|
||||
softDrop: function () {
|
||||
if (piece.move(TRANSLATION.DOWN)) stats.score++
|
||||
},
|
||||
|
||||
hardDrop: function() {
|
||||
hardDrop: function () {
|
||||
scheduler.clearTimeout(lockDown)
|
||||
//hardDropSound.play()
|
||||
while (piece.move(TRANSLATION.DOWN)) stats.score +=2
|
||||
while (piece.move(TRANSLATION.DOWN)) stats.score += 2
|
||||
lockDown()
|
||||
},
|
||||
|
||||
hold: function() {
|
||||
hold: function () {
|
||||
if (piece.holdEnabled) {
|
||||
scheduler.clearInterval(fall)
|
||||
scheduler.clearTimeout(lockDown)
|
||||
@ -1075,7 +1076,7 @@ function onkeydown(event) {
|
||||
actionsQueue.unshift(action)
|
||||
scheduler.clearTimeout(repeat)
|
||||
scheduler.clearInterval(autorepeat)
|
||||
if (action == playerActions.softDrop) scheduler.setInterval(autorepeat, settings.fallPeriod/20)
|
||||
if (action == playerActions.softDrop) scheduler.setInterval(autorepeat, settings.fallPeriod / 20)
|
||||
else scheduler.setTimeout(repeat, settings.das)
|
||||
}
|
||||
}
|
||||
@ -1129,7 +1130,7 @@ function lockDown() {
|
||||
if (tetrisSound.volume) tetrisSound.play()
|
||||
} else if (nbClearedLines || tSpin) {
|
||||
lineClearSound.currentTime = 0
|
||||
if(lineClearSound.volume) lineClearSound.play()
|
||||
if (lineClearSound.volume) lineClearSound.play()
|
||||
}
|
||||
stats.lockDown(nbClearedLines, tSpin)
|
||||
|
||||
@ -1145,18 +1146,13 @@ function gameOver() {
|
||||
document.onkeydown = null
|
||||
onblur = null
|
||||
playing = false
|
||||
renderer.domElement.style.cursor = "auto"
|
||||
music.pause()
|
||||
|
||||
stats.show()
|
||||
}
|
||||
|
||||
window.onbeforeunload = function(event) {
|
||||
window.onbeforeunload = function (event) {
|
||||
stats.save()
|
||||
settings.save()
|
||||
if (playing) return false
|
||||
}
|
||||
|
||||
/*if ('serviceWorker' in navigator) {
|
||||
navigator.serviceWorker.register('service-worker.js')
|
||||
}*/
|
@ -10,6 +10,10 @@ body {
|
||||
}
|
||||
}
|
||||
|
||||
canvas {
|
||||
cursor: grab;
|
||||
}
|
||||
|
||||
#titleHeader {
|
||||
letter-spacing: 1rem;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user