From 9047890060dee61dcc2a33435b1a77dc8e250a70 Mon Sep 17 00:00:00 2001 From: "PolicyChanges1@gmail.com" Date: Thu, 18 Feb 2021 03:51:08 -0500 Subject: [PATCH] fix reset --- README.md | 4 ++-- dist/tetrion.js | 33 ++++++++++++++++----------------- src/input.js | 8 ++++---- src/main.js | 10 ++++++++-- src/openers.js | 15 ++++----------- 5 files changed, 34 insertions(+), 36 deletions(-) diff --git a/README.md b/README.md index 09db1d6..6c8dd81 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ # MIT Liecense -[Tetrion](http://policychanges.github.io) +#[Tetrion](http://policychanges.github.io) # Tetris @@ -14,7 +14,7 @@ Just a practice, if you are interested in writing html5 games,check the code an # Demo -# [Tetris Game](http://sandywalker.github.io/Tetris/) +[Tetris Game](http://sandywalker.github.io/Tetris/) # License diff --git a/dist/tetrion.js b/dist/tetrion.js index 7bf8070..ada2604 100644 --- a/dist/tetrion.js +++ b/dist/tetrion.js @@ -500,7 +500,7 @@ var UserInputs = { var ARR = 20.0; var isContained = this.gpButtons.includes(finds); var isPrevContained = this.prevGpButtons.includes(finds); - //console.log("but: " + this.gpButtons + " prev but:" + this.prevGpButtons); + if(isPrevContained != isContained ) { this.isGamepadDown = false; // Do once @@ -512,7 +512,7 @@ var UserInputs = { if (gamepadDirectionDasFrames >= DAS) { this.gamepadDirectionPadDeciFrames = 0; this.isGamepadDown = true; - //console.log(this.isGamepadDown + " " + this.gam); + } } else @@ -586,9 +586,9 @@ var UserInputs = { this.inputqueue.push(key); } - //console.log(key + " " + this.held + var keyboardDASFrames = this.keyboardDirectionArrowsDeciframes / 1.0; // why isnt this 10? - //console.log(keyboardDASFrames + " " + this.held); + if (!this.isDirectionArrowDown) { if (keyboardDASFrames >= DAS) { @@ -833,7 +833,8 @@ Tetris.prototype = { views.setLevel(this.level); views.setScore(this.score); views.setGameOver(this.isGameOver); - + openers.reset(); + this._draw(); }, //Start game @@ -950,7 +951,6 @@ Tetris.prototype = { // TODO: put in web worker--limited to 60fps here if(deltaTime >= tenthOfFrame) { // needs to be 600hz // 16 / 10 inputs.incDeciframes(); - //console.log(deltaTime / 600.0); } if(deltaTime >= tenthOfFrame) { @@ -1133,6 +1133,11 @@ Tetris.prototype = { }, + _checkHint: function() { + if(this.shape.y != this.hintMino.y || this.shape.x != this.hintMino.x) + //1console.log("success!"); + this._restartHandler(); + }, // Update game data _update: function() { @@ -1142,6 +1147,7 @@ Tetris.prototype = { this.canPullFromHoldQueue = true; this.shape.copyTo(this.matrix); this._check(); + this._checkHint(); this._fireShape(); new Audio('./dist/Blop2.ogg').play(); } @@ -1255,7 +1261,7 @@ var OpenerGenerator = { } this.isInit = 1; - return;// this.shapeQueue; + return; }, getNextMino() { @@ -1266,10 +1272,8 @@ var OpenerGenerator = { this.idx = 0; this.isInit = 0; } - console.log("mino: " + mino); return mino; - //return this.shapeQueue[this.idx%=6]; }, // L O Z T LR ZR I initHint(matrix) { @@ -1283,7 +1287,6 @@ var OpenerGenerator = { shapes.getShape(4), shapes.getShape(3)); - //console.log("matrix: " + matrix); // L this.hintQueue[0].x = 0; this.hintQueue[0].y = 17; @@ -1291,7 +1294,6 @@ var OpenerGenerator = { this.hintQueue[1].x = 3; this.hintQueue[1].y = 19; this.hintQueue[1].state = this.hintQueue[1].nextState(1); - //this.hintQueue[1].matrix = // O this.hintQueue[2].x = 8; this.hintQueue[2].y = 18; @@ -1316,26 +1318,25 @@ var OpenerGenerator = { this.isHintInit = 1; - return;// this.shapeQueue; + return; }, getNextHint(matrix) { this.initHint(matrix); - console.log("hint " + this.hintIdx); var mino = this.hintQueue[this.hintIdx]; this.hintIdx++; if(this.hintIdx == 7) { this.hintIdx = 0; this.isHintInit = 0; } - console.log("hintmino: " + mino) return mino; - //return this.shapeQueue[this.idx%=6]; }, reset() { this.shapeQueue = []; this.hintQueue = []; this.idx = 0; this.hintIdx = 0; + this.isInit = 0; + this.isHintInit = 0; } }; @@ -1345,12 +1346,10 @@ function reset() { function getNextMino() { var mino = OpenerGenerator.getNextMino(); - //console.log("Mino: " + mino); return mino; } function getNextHint(matrix) { var mino = OpenerGenerator.getNextHint(matrix); - //console.log("Mino: " + mino); return mino; } module.exports.getNextMino = getNextMino; diff --git a/src/input.js b/src/input.js index 878c7f4..c066385 100644 --- a/src/input.js +++ b/src/input.js @@ -80,7 +80,7 @@ var UserInputs = { var ARR = 20.0; var isContained = this.gpButtons.includes(finds); var isPrevContained = this.prevGpButtons.includes(finds); - //console.log("but: " + this.gpButtons + " prev but:" + this.prevGpButtons); + if(isPrevContained != isContained ) { this.isGamepadDown = false; // Do once @@ -92,7 +92,7 @@ var UserInputs = { if (gamepadDirectionDasFrames >= DAS) { this.gamepadDirectionPadDeciFrames = 0; this.isGamepadDown = true; - //console.log(this.isGamepadDown + " " + this.gam); + } } else @@ -166,9 +166,9 @@ var UserInputs = { this.inputqueue.push(key); } - //console.log(key + " " + this.held + var keyboardDASFrames = this.keyboardDirectionArrowsDeciframes / 1.0; // why isnt this 10? - //console.log(keyboardDASFrames + " " + this.held); + if (!this.isDirectionArrowDown) { if (keyboardDASFrames >= DAS) { diff --git a/src/main.js b/src/main.js index 80036f2..e04e67e 100644 --- a/src/main.js +++ b/src/main.js @@ -182,7 +182,8 @@ Tetris.prototype = { views.setLevel(this.level); views.setScore(this.score); views.setGameOver(this.isGameOver); - + openers.reset(); + this._draw(); }, //Start game @@ -299,7 +300,6 @@ Tetris.prototype = { // TODO: put in web worker--limited to 60fps here if(deltaTime >= tenthOfFrame) { // needs to be 600hz // 16 / 10 inputs.incDeciframes(); - //console.log(deltaTime / 600.0); } if(deltaTime >= tenthOfFrame) { @@ -482,6 +482,11 @@ Tetris.prototype = { }, + _checkHint: function() { + if(this.shape.y != this.hintMino.y || this.shape.x != this.hintMino.x) + //1console.log("success!"); + this._restartHandler(); + }, // Update game data _update: function() { @@ -491,6 +496,7 @@ Tetris.prototype = { this.canPullFromHoldQueue = true; this.shape.copyTo(this.matrix); this._check(); + this._checkHint(); this._fireShape(); new Audio('./dist/Blop2.ogg').play(); } diff --git a/src/openers.js b/src/openers.js index 7171206..67dc81e 100644 --- a/src/openers.js +++ b/src/openers.js @@ -65,7 +65,7 @@ var OpenerGenerator = { } this.isInit = 1; - return;// this.shapeQueue; + return; }, getNextMino() { @@ -76,10 +76,8 @@ var OpenerGenerator = { this.idx = 0; this.isInit = 0; } - console.log("mino: " + mino); return mino; - //return this.shapeQueue[this.idx%=6]; }, // L O Z T LR ZR I initHint(matrix) { @@ -93,7 +91,6 @@ var OpenerGenerator = { shapes.getShape(4), shapes.getShape(3)); - //console.log("matrix: " + matrix); // L this.hintQueue[0].x = 0; this.hintQueue[0].y = 17; @@ -101,7 +98,6 @@ var OpenerGenerator = { this.hintQueue[1].x = 3; this.hintQueue[1].y = 19; this.hintQueue[1].state = this.hintQueue[1].nextState(1); - //this.hintQueue[1].matrix = // O this.hintQueue[2].x = 8; this.hintQueue[2].y = 18; @@ -126,26 +122,25 @@ var OpenerGenerator = { this.isHintInit = 1; - return;// this.shapeQueue; + return; }, getNextHint(matrix) { this.initHint(matrix); - console.log("hint " + this.hintIdx); var mino = this.hintQueue[this.hintIdx]; this.hintIdx++; if(this.hintIdx == 7) { this.hintIdx = 0; this.isHintInit = 0; } - console.log("hintmino: " + mino) return mino; - //return this.shapeQueue[this.idx%=6]; }, reset() { this.shapeQueue = []; this.hintQueue = []; this.idx = 0; this.hintIdx = 0; + this.isInit = 0; + this.isHintInit = 0; } }; @@ -155,12 +150,10 @@ function reset() { function getNextMino() { var mino = OpenerGenerator.getNextMino(); - //console.log("Mino: " + mino); return mino; } function getNextHint(matrix) { var mino = OpenerGenerator.getNextHint(matrix); - //console.log("Mino: " + mino); return mino; } module.exports.getNextMino = getNextMino;