sequence editor start
This commit is contained in:
parent
600bca2ecd
commit
6f27db0588
BIN
dist/sound/Affirm2.ogg
vendored
Normal file
BIN
dist/sound/Affirm2.ogg
vendored
Normal file
Binary file not shown.
221
dist/tetrion.js
vendored
221
dist/tetrion.js
vendored
@ -660,7 +660,7 @@ var UserInputs = {
|
|||||||
gamepadQueue: [],
|
gamepadQueue: [],
|
||||||
|
|
||||||
keyboardKeySettings: ["Keyboard DAS", "Keyboard ARR"],
|
keyboardKeySettings: ["Keyboard DAS", "Keyboard ARR"],
|
||||||
keyboardShiftEvents: ["Keyboard Left", "Keyboard Right", "Keyboard Down"],
|
keyboardShiftEvents: ["Keyboard Left", "Keyboard Right", "Keyboard Down", "Keyboard Up"],
|
||||||
keyboardKeyEvents: ["Keyboard Harddrop", "Keyboard Hold", "Keyboard Rotateccw", "Keyboard Rotate", "Keyboard Pophold", "Keyboard Reset", "Keyboard Background"],
|
keyboardKeyEvents: ["Keyboard Harddrop", "Keyboard Hold", "Keyboard Rotateccw", "Keyboard Rotate", "Keyboard Pophold", "Keyboard Reset", "Keyboard Background"],
|
||||||
|
|
||||||
gamepadSettings: ["Gamepad DAS", "Gamepad ARR"],
|
gamepadSettings: ["Gamepad DAS", "Gamepad ARR"],
|
||||||
@ -670,8 +670,8 @@ var UserInputs = {
|
|||||||
settingsList: [],
|
settingsList: [],
|
||||||
|
|
||||||
settingsDefault: [ "167.0", "33.0",
|
settingsDefault: [ "167.0", "33.0",
|
||||||
"37", "39", "40",
|
"37", "39", "40", "38",
|
||||||
"32", "16", "90", "88,38", "17", "82", "81",
|
"32", "16", "90", "88", "17", "82", "81",
|
||||||
|
|
||||||
"167.0", "33.0",
|
"167.0", "33.0",
|
||||||
"DPad-Left", "DPad-Right", "DPad-Down",
|
"DPad-Left", "DPad-Right", "DPad-Down",
|
||||||
@ -865,6 +865,7 @@ Tetris.prototype = {
|
|||||||
toggleGamepad: function(){
|
toggleGamepad: function(){
|
||||||
document.getElementById("enablegamepad").value = ((this.gamepadEnabled = !this.gamepadEnabled) ? "Disable Gamepad" : "Enable Gamepad");
|
document.getElementById("enablegamepad").value = ((this.gamepadEnabled = !this.gamepadEnabled) ? "Disable Gamepad" : "Enable Gamepad");
|
||||||
},
|
},
|
||||||
|
// Gamestate 1
|
||||||
setFreePlay: function()
|
setFreePlay: function()
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -882,6 +883,7 @@ Tetris.prototype = {
|
|||||||
this.currentOpener = 0;
|
this.currentOpener = 0;
|
||||||
|
|
||||||
},
|
},
|
||||||
|
// Gamestate 2
|
||||||
setCurrentOpener(opener)
|
setCurrentOpener(opener)
|
||||||
{
|
{
|
||||||
document.getElementById("besttime").value = "";
|
document.getElementById("besttime").value = "";
|
||||||
@ -891,6 +893,7 @@ Tetris.prototype = {
|
|||||||
this._restartHandler();
|
this._restartHandler();
|
||||||
|
|
||||||
},
|
},
|
||||||
|
// Gamestate 3
|
||||||
setDoTest: function()
|
setDoTest: function()
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -898,8 +901,24 @@ Tetris.prototype = {
|
|||||||
|
|
||||||
// set game state to do test
|
// set game state to do test
|
||||||
this.gameState = consts.GAMESTATES[2];
|
this.gameState = consts.GAMESTATES[2];
|
||||||
|
|
||||||
this._restartHandler();
|
this._restartHandler();
|
||||||
},
|
},
|
||||||
|
// Gamestate 4
|
||||||
|
setGameStateSequenceEditor: function()
|
||||||
|
{
|
||||||
|
document.getElementById("side").display = "none";
|
||||||
|
|
||||||
|
// change to editor gamestate
|
||||||
|
this.gameState = consts.GAMESTATES[3];
|
||||||
|
this.hintQueue = [];
|
||||||
|
this.shapeQueue = [];
|
||||||
|
this.hintMino = 0;
|
||||||
|
this._restartHandler();
|
||||||
|
this.currentOpener = 0;
|
||||||
|
this.pushHoldStack();
|
||||||
|
},
|
||||||
|
|
||||||
createSettings: function () {
|
createSettings: function () {
|
||||||
var list = document.getElementById("settings");
|
var list = document.getElementById("settings");
|
||||||
var settings = inputs.settingsList;
|
var settings = inputs.settingsList;
|
||||||
@ -926,6 +945,30 @@ Tetris.prototype = {
|
|||||||
inputs.settingsMap.get(inputs.settingsList[document.getElementById("settings").selectedIndex-1]);
|
inputs.settingsMap.get(inputs.settingsList[document.getElementById("settings").selectedIndex-1]);
|
||||||
|
|
||||||
|
|
||||||
|
},
|
||||||
|
addOpener: function() {
|
||||||
|
|
||||||
|
var newOpener = document.createElement('li');
|
||||||
|
//<li style="font-size:12px;padding-left:1em";><a href="#" id="setMrTSpinsSTDreversedVar">Mr. T-Spin's STD (reversed) </a></li>
|
||||||
|
//newOpener.text = "New Sequence";
|
||||||
|
//newOpener.id = this.currentMinoInx;
|
||||||
|
newOpener.style="color:powderblue;text-decoration:underline;font-size:12px;padding-left:1em";
|
||||||
|
|
||||||
|
|
||||||
|
newOpener.appendChild(document.createTextNode("New Sequence: " + this.currentMinoInx));
|
||||||
|
document.getElementById("Openers").appendChild(newOpener);
|
||||||
|
|
||||||
|
|
||||||
|
openers.addSequence(this.shapeQueue);
|
||||||
|
//this.setFreePlay();
|
||||||
|
this.gameState = consts.GAMESTATES[1];
|
||||||
|
this.currentMinoInx = 0;
|
||||||
|
//this.setCurrentOpener(99999);//this.currentMinoInx);
|
||||||
|
clearMatrix(this.matrix);
|
||||||
|
this.currentOpener = 9999;
|
||||||
|
this.shapeQueue = [];
|
||||||
|
this.hintQueue = [];
|
||||||
|
this._recurseGameState();
|
||||||
},
|
},
|
||||||
setSettings: function() {
|
setSettings: function() {
|
||||||
var newVal = document.getElementById("setting_value").value;
|
var newVal = document.getElementById("setting_value").value;
|
||||||
@ -987,6 +1030,13 @@ Tetris.prototype = {
|
|||||||
},
|
},
|
||||||
pushHoldStack: function()
|
pushHoldStack: function()
|
||||||
{
|
{
|
||||||
|
if(this.gameState == consts.GAMESTATES[3]) {
|
||||||
|
while(this.holdStack.length < 7)
|
||||||
|
this.holdStack.unshift(utils.deepClone(shapes.getShape(this.currentMinoInx++%7)));
|
||||||
|
this.shape = this.holdStack.pop();
|
||||||
|
this._draw();
|
||||||
|
return;
|
||||||
|
}
|
||||||
// 1 shape hold queue
|
// 1 shape hold queue
|
||||||
if(this.holdStack.length > 0) {
|
if(this.holdStack.length > 0) {
|
||||||
this.canPopFromHoldStack = false;
|
this.canPopFromHoldStack = false;
|
||||||
@ -1012,6 +1062,19 @@ Tetris.prototype = {
|
|||||||
},
|
},
|
||||||
popHoldStack: function()
|
popHoldStack: function()
|
||||||
{
|
{
|
||||||
|
if(this.gameState == consts.GAMESTATES[3]) {
|
||||||
|
if(this.holdStack.length < 7)
|
||||||
|
while(this.holdStack.length < 7)
|
||||||
|
this.holdStack.unshift(utils.deepClone(shapes.getShape(this.currentMinoInx++%7)));
|
||||||
|
// piece needs to be able to be placed
|
||||||
|
if(this.shape.canDown(this.matrix)) return;
|
||||||
|
this.shape.copyTo(this.matrix);
|
||||||
|
this.shapeQueue.unshift(utils.deepClone(this.shape));
|
||||||
|
this.shape = this.holdStack.pop();
|
||||||
|
this._check();
|
||||||
|
this._draw();
|
||||||
|
return;
|
||||||
|
}
|
||||||
// todo: disable if 1 shape hold queue
|
// todo: disable if 1 shape hold queue
|
||||||
if(this.holdStack.length >= 1 && this.canPopFromHoldStack)
|
if(this.holdStack.length >= 1 && this.canPopFromHoldStack)
|
||||||
{
|
{
|
||||||
@ -1067,7 +1130,7 @@ Tetris.prototype = {
|
|||||||
|
|
||||||
// Opener sequence completed
|
// Opener sequence completed
|
||||||
if(this.currentMinoInx > openers.getLength()) {
|
if(this.currentMinoInx > openers.getLength()) {
|
||||||
new Audio("./dist/sound/Affirm.ogg").play();
|
//new Audio("./dist/sound/Affirm2.ogg").play();
|
||||||
if(this.isTimerOn) {
|
if(this.isTimerOn) {
|
||||||
var besttime = document.getElementById("besttime").value;
|
var besttime = document.getElementById("besttime").value;
|
||||||
var deltaTime = new Date().getTime() - this.sequencePrevTime;
|
var deltaTime = new Date().getTime() - this.sequencePrevTime;
|
||||||
@ -1082,14 +1145,22 @@ Tetris.prototype = {
|
|||||||
this.shapeQueue = [];
|
this.shapeQueue = [];
|
||||||
|
|
||||||
this.isSequenceCompleted = true;
|
this.isSequenceCompleted = true;
|
||||||
|
|
||||||
// Recursion warning
|
// Recursion warning
|
||||||
this._restartHandler();
|
if(this.currentOpener < 1000) // getting real hacky
|
||||||
|
this._restartHandler();
|
||||||
|
else clearMatrix(this.matrix);
|
||||||
// this.reset();
|
// this.reset();
|
||||||
// this.start();
|
// this.start();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
// Fill next queue and set next shape
|
// Process sequence editor
|
||||||
|
_processSequenceEditor: function () {
|
||||||
|
return;
|
||||||
|
},
|
||||||
|
|
||||||
|
// Fill next queue and set next shape
|
||||||
_fireShape: function() {
|
_fireShape: function() {
|
||||||
//todo:should be in shapes.js
|
//todo:should be in shapes.js
|
||||||
this.landed = false;
|
this.landed = false;
|
||||||
@ -1111,6 +1182,8 @@ Tetris.prototype = {
|
|||||||
case consts.GAMESTATES[2]:
|
case consts.GAMESTATES[2]:
|
||||||
this._processOpenerTrainerQueue();
|
this._processOpenerTrainerQueue();
|
||||||
this._fireShape();
|
this._fireShape();
|
||||||
|
case consts.GAMESTATES[3]:
|
||||||
|
this._processSequenceEditor();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@ -1172,18 +1245,10 @@ Tetris.prototype = {
|
|||||||
|
|
||||||
|
|
||||||
if(this.gamepadEnabled && inputs.gamepadEnabled()) {
|
if(this.gamepadEnabled && inputs.gamepadEnabled()) {
|
||||||
var tenthOfFrame = 1.0 //1.6; // 1.6ms = 1 fram
|
|
||||||
var halfFrame = 5.0 //8.0;
|
|
||||||
var halfFramePlus = 10.0;
|
|
||||||
|
|
||||||
|
|
||||||
inputs.updateGamepad();
|
inputs.updateGamepad();
|
||||||
inputs.processGamepadDPad();
|
inputs.processGamepadDPad();
|
||||||
inputs.processGamepadInput();
|
inputs.processGamepadInput();
|
||||||
|
|
||||||
// drain gamepad queue
|
|
||||||
// if( inputs.getTickCounter() > halfFrame) // 8 millisecons
|
|
||||||
// {
|
|
||||||
while((inputs.gamepadQueue != undefined && inputs.gamepadQueue.length >= 1)){
|
while((inputs.gamepadQueue != undefined && inputs.gamepadQueue.length >= 1)){
|
||||||
var curkey = inputs.gamepadQueue.shift();
|
var curkey = inputs.gamepadQueue.shift();
|
||||||
if(inputs.settingsMap.get("Gamepad Left").includes(curkey)) {
|
if(inputs.settingsMap.get("Gamepad Left").includes(curkey)) {
|
||||||
@ -1211,9 +1276,15 @@ Tetris.prototype = {
|
|||||||
this._draw();
|
this._draw();
|
||||||
}
|
}
|
||||||
else if(inputs.settingsMap.get("Gamepad Harddrop").includes(curkey)) {
|
else if(inputs.settingsMap.get("Gamepad Harddrop").includes(curkey)) {
|
||||||
|
// if editor
|
||||||
|
if(this.gameState == consts.GAMESTATES[3]) {
|
||||||
|
this.popHoldStack();
|
||||||
|
this._draw();
|
||||||
|
}else {
|
||||||
this.shape.goBottom(this.matrix);
|
this.shape.goBottom(this.matrix);
|
||||||
this.lockDownTimer = 5000;
|
this.lockDownTimer = 5000;
|
||||||
this._update();
|
this._update();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if(inputs.settingsMap.get("Gamepad Hold").includes(curkey)) {
|
else if(inputs.settingsMap.get("Gamepad Hold").includes(curkey)) {
|
||||||
this.pushHoldStack();
|
this.pushHoldStack();
|
||||||
@ -1254,6 +1325,11 @@ Tetris.prototype = {
|
|||||||
this.shape.goDown(this.matrix);
|
this.shape.goDown(this.matrix);
|
||||||
this._draw();
|
this._draw();
|
||||||
}
|
}
|
||||||
|
else if(this.gameState == consts.GAMESTATES[3] && inputs.settingsMap.get("Keyboard Up").includes(curkey)) {
|
||||||
|
|
||||||
|
this.shape.goUp(this.matrix);
|
||||||
|
this._draw();
|
||||||
|
}
|
||||||
else if(inputs.settingsMap.get("Keyboard Rotateccw").includes(curkey)) {
|
else if(inputs.settingsMap.get("Keyboard Rotateccw").includes(curkey)) {
|
||||||
this.shape.rotate(this.matrix);
|
this.shape.rotate(this.matrix);
|
||||||
this.resetLockdown();
|
this.resetLockdown();
|
||||||
@ -1265,9 +1341,15 @@ Tetris.prototype = {
|
|||||||
this._draw();
|
this._draw();
|
||||||
}
|
}
|
||||||
else if(inputs.settingsMap.get("Keyboard Harddrop").includes(curkey)) {
|
else if(inputs.settingsMap.get("Keyboard Harddrop").includes(curkey)) {
|
||||||
this.shape.goBottom(this.matrix);
|
// if editor
|
||||||
this.lockDownTimer = 5000;
|
if(this.gameState == consts.GAMESTATES[3]) {
|
||||||
this._update();
|
this.popHoldStack();
|
||||||
|
this._draw();
|
||||||
|
}else {
|
||||||
|
this.shape.goBottom(this.matrix);
|
||||||
|
this.lockDownTimer = 5000;
|
||||||
|
this._update();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if(inputs.settingsMap.get("Keyboard Hold").includes(curkey)) {
|
else if(inputs.settingsMap.get("Keyboard Hold").includes(curkey)) {
|
||||||
this.pushHoldStack();
|
this.pushHoldStack();
|
||||||
@ -1330,25 +1412,36 @@ Tetris.prototype = {
|
|||||||
// Update game data
|
// Update game data
|
||||||
_update: function() {
|
_update: function() {
|
||||||
|
|
||||||
if (this.shape.canDown(this.matrix)) {
|
switch(this.gameState) {
|
||||||
this.shape.goDown(this.matrix);
|
case consts.GAMESTATES[0]:
|
||||||
} else if(this.isPieceLocked()){
|
case consts.GAMESTATES[1]:
|
||||||
this.canPopFromHoldStack = true;
|
case consts.GAMESTATES[2]:
|
||||||
this.shape.copyTo(this.matrix);
|
if(this.shape == undefined) break;
|
||||||
this._check();
|
if (this.shape.canDown(this.matrix)) {
|
||||||
if(this._checkHint()) return;
|
this.shape.goDown(this.matrix);
|
||||||
//this._fireShape();
|
} else if(this.isPieceLocked()){
|
||||||
this._recurseGameState();
|
this.canPopFromHoldStack = true;
|
||||||
new Audio('./dist/sound/Blop2.ogg').play();
|
this.shape.copyTo(this.matrix);
|
||||||
}
|
this._check();
|
||||||
this._draw();
|
if(this._checkHint()) return;
|
||||||
this.isGameOver = checkGameOver(this.matrix);
|
//this._fireShape();
|
||||||
|
this._recurseGameState();
|
||||||
// if game over and gamestate is free play
|
new Audio('./dist/sound/Blop2.ogg').play();
|
||||||
views.setGameOver(this.gameState == consts.GAMESTATES[0] && this.isGameOver);
|
}
|
||||||
|
this._draw();
|
||||||
if (this.isGameOver)
|
this.isGameOver = checkGameOver(this.matrix);
|
||||||
views.setFinalScore(this.score);
|
|
||||||
|
// if game over and gamestate is free play
|
||||||
|
views.setGameOver(this.gameState == consts.GAMESTATES[0] && this.isGameOver);
|
||||||
|
|
||||||
|
if (this.isGameOver)
|
||||||
|
views.setFinalScore(this.score);
|
||||||
|
break;
|
||||||
|
case consts.GAMESTATES[3]:
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
// 0 - none, 1 - mini, 2 - tspin
|
// 0 - none, 1 - mini, 2 - tspin
|
||||||
@ -1434,6 +1527,7 @@ window.Tetris = Tetris;
|
|||||||
// export {Tetris};
|
// export {Tetris};
|
||||||
},{"./canvas.js":1,"./consts.js":2,"./input.js":4,"./openers.js":6,"./shapes.js":7,"./utils.js":8,"./views.js":9}],6:[function(require,module,exports){
|
},{"./canvas.js":1,"./consts.js":2,"./input.js":4,"./openers.js":6,"./shapes.js":7,"./utils.js":8,"./views.js":9}],6:[function(require,module,exports){
|
||||||
var shapes = require("./shapes.js");
|
var shapes = require("./shapes.js");
|
||||||
|
var utils = require("./utils.js");
|
||||||
// import * as shapes from './shapes.js';
|
// import * as shapes from './shapes.js';
|
||||||
|
|
||||||
// https://harddrop.com/wiki/Opener
|
// https://harddrop.com/wiki/Opener
|
||||||
@ -1606,6 +1700,7 @@ var openerGenerator = {
|
|||||||
shapes.getShape(3));
|
shapes.getShape(3));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
this.shapeQueue.unshift(utils.deepClone(shapes.randomShape()));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1620,7 +1715,9 @@ var openerGenerator = {
|
|||||||
this.idx++;
|
this.idx++;
|
||||||
if(this.idx == this.shapeQueue.length) {
|
if(this.idx == this.shapeQueue.length) {
|
||||||
this.idx = 0;
|
this.idx = 0;
|
||||||
this.isInit = 0;
|
if(opener < 1000)
|
||||||
|
this.isInit = 0;
|
||||||
|
else this.isInit = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return mino;
|
return mino;
|
||||||
@ -1876,6 +1973,7 @@ var openerGenerator = {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
this.hintQueue.unshift(utils.deepClone(shapes.randomShape()));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1893,7 +1991,9 @@ var openerGenerator = {
|
|||||||
this.hintIdx++;
|
this.hintIdx++;
|
||||||
if(this.hintIdx == this.hintQueue.length) {
|
if(this.hintIdx == this.hintQueue.length) {
|
||||||
this.hintIdx = 0;
|
this.hintIdx = 0;
|
||||||
this.isHintInit = 0;
|
if(opener < 1000)
|
||||||
|
this.isHintInit = 0;
|
||||||
|
else this.isHintInit = 1;
|
||||||
}
|
}
|
||||||
return mino;
|
return mino;
|
||||||
},
|
},
|
||||||
@ -1908,6 +2008,27 @@ var openerGenerator = {
|
|||||||
},
|
},
|
||||||
getLength() {
|
getLength() {
|
||||||
return this.hintQueue.length;
|
return this.hintQueue.length;
|
||||||
|
},
|
||||||
|
addSequence(sequence) {
|
||||||
|
//this.reset();
|
||||||
|
//this.shapeQueue = utils.deepClone(sequence);
|
||||||
|
//this.hintQueue = utils.deepClone(sequence);
|
||||||
|
for(var i in sequence)
|
||||||
|
{
|
||||||
|
var shape;
|
||||||
|
shape = sequence[i];
|
||||||
|
shape.x = sequence[i].x;
|
||||||
|
shape.y = sequence[i].y;
|
||||||
|
shape.state = sequence[i].state;
|
||||||
|
this.hintQueue.unshift(utils.deepClone(shape));
|
||||||
|
shape.x = shape.originX;
|
||||||
|
shape.y = shape.originY;
|
||||||
|
this.shapeQueue.unshift(utils.deepClone(shape));
|
||||||
|
this.isInit = 1;
|
||||||
|
this.isHintInit = 1;
|
||||||
|
this.idx = 0;
|
||||||
|
this.hintIdx = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -1926,6 +2047,12 @@ function getNextHint(opener) {
|
|||||||
function getLength() {
|
function getLength() {
|
||||||
return openerGenerator.getLength();
|
return openerGenerator.getLength();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function addSequence(sequence) {
|
||||||
|
openerGenerator.addSequence(sequence);
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports.addSequence = addSequence;
|
||||||
module.exports.getNextMino = getNextMino;
|
module.exports.getNextMino = getNextMino;
|
||||||
module.exports.getNextHint = getNextHint;
|
module.exports.getNextHint = getNextHint;
|
||||||
module.exports.getLength = getLength;
|
module.exports.getLength = getLength;
|
||||||
@ -1937,7 +2064,7 @@ module.exports.reset = reset;
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
},{"./shapes.js":7}],7:[function(require,module,exports){
|
},{"./shapes.js":7,"./utils.js":8}],7:[function(require,module,exports){
|
||||||
var consts = require('./consts.js');
|
var consts = require('./consts.js');
|
||||||
var utils = require('./utils.js');
|
var utils = require('./utils.js');
|
||||||
// import * as consts from './const.js';
|
// import * as consts from './const.js';
|
||||||
@ -2011,6 +2138,7 @@ function ShapeL() {
|
|||||||
this.states = [state1, state2, state3, state4];
|
this.states = [state1, state2, state3, state4];
|
||||||
this.x = 3;
|
this.x = 3;
|
||||||
this.y = -3;
|
this.y = -3;
|
||||||
|
this.originX = 3;
|
||||||
this.originY = -3;
|
this.originY = -3;
|
||||||
this.flag = 'L';
|
this.flag = 'L';
|
||||||
}
|
}
|
||||||
@ -2077,6 +2205,7 @@ function ShapeLR() {
|
|||||||
this.states = [state1, state2, state3, state4];
|
this.states = [state1, state2, state3, state4];
|
||||||
this.x = 3;
|
this.x = 3;
|
||||||
this.y = -3;
|
this.y = -3;
|
||||||
|
this.originX = 3;
|
||||||
this.originY = -3;
|
this.originY = -3;
|
||||||
this.flag = 'LR';
|
this.flag = 'LR';
|
||||||
}
|
}
|
||||||
@ -2141,6 +2270,7 @@ function ShapeO() {
|
|||||||
this.states = [state1, state2, state3, state4];
|
this.states = [state1, state2, state3, state4];
|
||||||
this.x = 2;
|
this.x = 2;
|
||||||
this.y = -2;
|
this.y = -2;
|
||||||
|
this.originX = 2;
|
||||||
this.originY = -2;
|
this.originY = -2;
|
||||||
this.flag = 'O';
|
this.flag = 'O';
|
||||||
}
|
}
|
||||||
@ -2245,6 +2375,7 @@ function ShapeI() {
|
|||||||
|
|
||||||
this.x = 3;
|
this.x = 3;
|
||||||
this.y = -4;
|
this.y = -4;
|
||||||
|
this.originX = 3;
|
||||||
this.originY = -4;
|
this.originY = -4;
|
||||||
this.flag = 'I';
|
this.flag = 'I';
|
||||||
}
|
}
|
||||||
@ -2311,6 +2442,7 @@ function ShapeT() {
|
|||||||
|
|
||||||
this.x = 3;
|
this.x = 3;
|
||||||
this.y = -2;
|
this.y = -2;
|
||||||
|
this.originX = 3;
|
||||||
this.originY = -2;
|
this.originY = -2;
|
||||||
this.flag = 'T';
|
this.flag = 'T';
|
||||||
}
|
}
|
||||||
@ -2376,6 +2508,7 @@ function ShapeZ() {
|
|||||||
this.states = [state1, state2, state3, state4];
|
this.states = [state1, state2, state3, state4];
|
||||||
this.x = 3;
|
this.x = 3;
|
||||||
this.y = -2;
|
this.y = -2;
|
||||||
|
this.originX = 3;
|
||||||
this.originY = -2;
|
this.originY = -2;
|
||||||
this.flag = 'Z';
|
this.flag = 'Z';
|
||||||
}
|
}
|
||||||
@ -2441,6 +2574,7 @@ function ShapeZR() {
|
|||||||
this.states = [state1, state2, state3, state4];
|
this.states = [state1, state2, state3, state4];
|
||||||
this.x = 3;
|
this.x = 3;
|
||||||
this.y = -2
|
this.y = -2
|
||||||
|
this.originX = 3;
|
||||||
this.originY = -2;
|
this.originY = -2;
|
||||||
this.flag = 'ZR';
|
this.flag = 'ZR';
|
||||||
}
|
}
|
||||||
@ -2545,6 +2679,9 @@ var isShapeCanMove = function(shape, matrix, action) {
|
|||||||
} else if (action === 'right') {
|
} else if (action === 'right') {
|
||||||
x += 1;
|
x += 1;
|
||||||
return x >= 0 && x < cols && matrix[y][x] == 0;
|
return x >= 0 && x < cols && matrix[y][x] == 0;
|
||||||
|
} else if (action === 'up') {
|
||||||
|
y -= 1;
|
||||||
|
return y >= 0 && matrix[y][x] == 0;
|
||||||
} else if (action === 'down') {
|
} else if (action === 'down') {
|
||||||
y += 1;
|
y += 1;
|
||||||
return y < rows && matrix[y][x] == 0;
|
return y < rows && matrix[y][x] == 0;
|
||||||
@ -2715,6 +2852,12 @@ ShapeZR.prototype = {
|
|||||||
this.y += 1;
|
this.y += 1;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
//Move the shape up
|
||||||
|
goUp: function(matrix) {
|
||||||
|
if (isShapeCanMove(this, matrix, 'up')) {
|
||||||
|
this.y -= 1;
|
||||||
|
}
|
||||||
|
},
|
||||||
//Move the shape to the Bottommost
|
//Move the shape to the Bottommost
|
||||||
bottomAt: function(matrix) {
|
bottomAt: function(matrix) {
|
||||||
var save = this.y;
|
var save = this.y;
|
||||||
|
19
index.html
19
index.html
@ -47,10 +47,9 @@
|
|||||||
|
|
||||||
<!-- <iframe id="bg" width="640" height="360" frameborder="0" src="https://www.shadertoy.com/embed/3sy3Wy?gui=true&t=10&paused=false&muted=false" ></iframe> -->
|
<!-- <iframe id="bg" width="640" height="360" frameborder="0" src="https://www.shadertoy.com/embed/3sy3Wy?gui=true&t=10&paused=false&muted=false" ></iframe> -->
|
||||||
|
|
||||||
<iframe id="bg" width="640" height="360" frameborder="0" src="" ></iframe>
|
<iframe id="bg" width="640" height="360" frameborder="0" src="" ></iframe>
|
||||||
<script>
|
<script>
|
||||||
|
|
||||||
|
|
||||||
if( (Math.floor(Math.random() * Math.floor(10)) % 10) == 0) {
|
if( (Math.floor(Math.random() * Math.floor(10)) % 10) == 0) {
|
||||||
document.getElementById("bg").src="https://www.shadertoy.com/embed/MlSSRt?gui=&paused=false&muted=false";
|
document.getElementById("bg").src="https://www.shadertoy.com/embed/MlSSRt?gui=&paused=false&muted=false";
|
||||||
document.getElementById("bg").style.webkitFilter = "blur(4px)";
|
document.getElementById("bg").style.webkitFilter = "blur(4px)";
|
||||||
@ -58,12 +57,14 @@ if( (Math.floor(Math.random() * Math.floor(10)) % 10) == 0) {
|
|||||||
else
|
else
|
||||||
document.getElementById("bg").src="https://www.shadertoy.com/embed/WldfWX?gui=&paused=false&muted=false";
|
document.getElementById("bg").src="https://www.shadertoy.com/embed/WldfWX?gui=&paused=false&muted=false";
|
||||||
|
|
||||||
|
var resizebg = function() {
|
||||||
document.getElementById("bg").width = window.innerWidth;
|
document.getElementById("bg").width = window.innerWidth;
|
||||||
document.getElementById("bg").height = window.innerHeight;
|
document.getElementById("bg").height = window.innerHeight;
|
||||||
|
};
|
||||||
|
window.addEventListener("resize", function() { this.resizebg(); } );
|
||||||
document.getElementById("bg").removeAttribute("tabIndex");
|
document.getElementById("bg").removeAttribute("tabIndex");
|
||||||
document.getElementById("divbg").removeAttribute("tabIndex");
|
document.getElementById("divbg").removeAttribute("tabIndex");
|
||||||
|
this.resizebg();
|
||||||
</script>
|
</script>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@ -163,9 +164,11 @@ document.getElementById("divbg").removeAttribute("tabIndex");
|
|||||||
<br>
|
<br>
|
||||||
<input style="width:70px;font-size:12px;background:rgba(40,40,40,.5);color:dodgerblue;border:1px solid #6666;text-align:left;" id="test" type="submit" value="Hide Hints"></input>
|
<input style="width:70px;font-size:12px;background:rgba(40,40,40,.5);color:dodgerblue;border:1px solid #6666;text-align:left;" id="test" type="submit" value="Hide Hints"></input>
|
||||||
<input style="width:110px;font-size:12px;background:rgba(40,40,40,.5);color:dodgerblue;border:1px solid #6666;text-align:left;" id="enablegamepad" type="button" value="Enable Gamepad"/>
|
<input style="width:110px;font-size:12px;background:rgba(40,40,40,.5);color:dodgerblue;border:1px solid #6666;text-align:left;" id="enablegamepad" type="button" value="Enable Gamepad"/>
|
||||||
|
<input style="width:100px;font-size:12px;background:rgba(40,40,40,.5);color:dodgerblue;border:1px solid #6666;text-align:left;" id="sequenceeditor" type="button" value="Opener Editor"/>
|
||||||
|
<input style="width:80px;font-size:12px;background:rgba(40,40,40,.5);color:dodgerblue;border:1px solid #6666;text-align:left;" id="addopener" type="button" value="Add Opener"/>
|
||||||
|
</div>
|
||||||
|
<div id="editor" style="visibility:hidden">
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -195,8 +198,8 @@ document.getElementById("divbg").removeAttribute("tabIndex");
|
|||||||
document.getElementById("test").addEventListener("click", function() { tetrion.setDoTest(); } );
|
document.getElementById("test").addEventListener("click", function() { tetrion.setDoTest(); } );
|
||||||
document.getElementById("settings").addEventListener("change", function() { tetrion.updateSettingTextBox(); } );
|
document.getElementById("settings").addEventListener("change", function() { tetrion.updateSettingTextBox(); } );
|
||||||
document.getElementById("submitsetting").addEventListener("click", function() { tetrion.setSettings(); } );
|
document.getElementById("submitsetting").addEventListener("click", function() { tetrion.setSettings(); } );
|
||||||
|
document.getElementById("sequenceeditor").addEventListener("click", function() { tetrion.setGameStateSequenceEditor(); } );
|
||||||
|
document.getElementById("addopener").addEventListener("click", function() { tetrion.addOpener(); } );
|
||||||
tetrion.start();
|
tetrion.start();
|
||||||
})();
|
})();
|
||||||
</script>
|
</script>
|
||||||
|
@ -227,7 +227,7 @@ var UserInputs = {
|
|||||||
gamepadQueue: [],
|
gamepadQueue: [],
|
||||||
|
|
||||||
keyboardKeySettings: ["Keyboard DAS", "Keyboard ARR"],
|
keyboardKeySettings: ["Keyboard DAS", "Keyboard ARR"],
|
||||||
keyboardShiftEvents: ["Keyboard Left", "Keyboard Right", "Keyboard Down"],
|
keyboardShiftEvents: ["Keyboard Left", "Keyboard Right", "Keyboard Down", "Keyboard Up"],
|
||||||
keyboardKeyEvents: ["Keyboard Harddrop", "Keyboard Hold", "Keyboard Rotateccw", "Keyboard Rotate", "Keyboard Pophold", "Keyboard Reset", "Keyboard Background"],
|
keyboardKeyEvents: ["Keyboard Harddrop", "Keyboard Hold", "Keyboard Rotateccw", "Keyboard Rotate", "Keyboard Pophold", "Keyboard Reset", "Keyboard Background"],
|
||||||
|
|
||||||
gamepadSettings: ["Gamepad DAS", "Gamepad ARR"],
|
gamepadSettings: ["Gamepad DAS", "Gamepad ARR"],
|
||||||
@ -237,8 +237,8 @@ var UserInputs = {
|
|||||||
settingsList: [],
|
settingsList: [],
|
||||||
|
|
||||||
settingsDefault: [ "167.0", "33.0",
|
settingsDefault: [ "167.0", "33.0",
|
||||||
"37", "39", "40",
|
"37", "39", "40", "38",
|
||||||
"32", "16", "90", "88,38", "17", "82", "81",
|
"32", "16", "90", "88", "17", "82", "81",
|
||||||
|
|
||||||
"167.0", "33.0",
|
"167.0", "33.0",
|
||||||
"DPad-Left", "DPad-Right", "DPad-Down",
|
"DPad-Left", "DPad-Right", "DPad-Down",
|
||||||
|
159
src/main.js
159
src/main.js
@ -181,6 +181,7 @@ Tetris.prototype = {
|
|||||||
toggleGamepad: function(){
|
toggleGamepad: function(){
|
||||||
document.getElementById("enablegamepad").value = ((this.gamepadEnabled = !this.gamepadEnabled) ? "Disable Gamepad" : "Enable Gamepad");
|
document.getElementById("enablegamepad").value = ((this.gamepadEnabled = !this.gamepadEnabled) ? "Disable Gamepad" : "Enable Gamepad");
|
||||||
},
|
},
|
||||||
|
// Gamestate 1
|
||||||
setFreePlay: function()
|
setFreePlay: function()
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -198,6 +199,7 @@ Tetris.prototype = {
|
|||||||
this.currentOpener = 0;
|
this.currentOpener = 0;
|
||||||
|
|
||||||
},
|
},
|
||||||
|
// Gamestate 2
|
||||||
setCurrentOpener(opener)
|
setCurrentOpener(opener)
|
||||||
{
|
{
|
||||||
document.getElementById("besttime").value = "";
|
document.getElementById("besttime").value = "";
|
||||||
@ -207,6 +209,7 @@ Tetris.prototype = {
|
|||||||
this._restartHandler();
|
this._restartHandler();
|
||||||
|
|
||||||
},
|
},
|
||||||
|
// Gamestate 3
|
||||||
setDoTest: function()
|
setDoTest: function()
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -214,8 +217,24 @@ Tetris.prototype = {
|
|||||||
|
|
||||||
// set game state to do test
|
// set game state to do test
|
||||||
this.gameState = consts.GAMESTATES[2];
|
this.gameState = consts.GAMESTATES[2];
|
||||||
|
|
||||||
this._restartHandler();
|
this._restartHandler();
|
||||||
},
|
},
|
||||||
|
// Gamestate 4
|
||||||
|
setGameStateSequenceEditor: function()
|
||||||
|
{
|
||||||
|
document.getElementById("side").display = "none";
|
||||||
|
|
||||||
|
// change to editor gamestate
|
||||||
|
this.gameState = consts.GAMESTATES[3];
|
||||||
|
this.hintQueue = [];
|
||||||
|
this.shapeQueue = [];
|
||||||
|
this.hintMino = 0;
|
||||||
|
this._restartHandler();
|
||||||
|
this.currentOpener = 0;
|
||||||
|
this.pushHoldStack();
|
||||||
|
},
|
||||||
|
|
||||||
createSettings: function () {
|
createSettings: function () {
|
||||||
var list = document.getElementById("settings");
|
var list = document.getElementById("settings");
|
||||||
var settings = inputs.settingsList;
|
var settings = inputs.settingsList;
|
||||||
@ -242,6 +261,30 @@ Tetris.prototype = {
|
|||||||
inputs.settingsMap.get(inputs.settingsList[document.getElementById("settings").selectedIndex-1]);
|
inputs.settingsMap.get(inputs.settingsList[document.getElementById("settings").selectedIndex-1]);
|
||||||
|
|
||||||
|
|
||||||
|
},
|
||||||
|
addOpener: function() {
|
||||||
|
|
||||||
|
var newOpener = document.createElement('li');
|
||||||
|
//<li style="font-size:12px;padding-left:1em";><a href="#" id="setMrTSpinsSTDreversedVar">Mr. T-Spin's STD (reversed) </a></li>
|
||||||
|
//newOpener.text = "New Sequence";
|
||||||
|
//newOpener.id = this.currentMinoInx;
|
||||||
|
newOpener.style="color:powderblue;text-decoration:underline;font-size:12px;padding-left:1em";
|
||||||
|
|
||||||
|
|
||||||
|
newOpener.appendChild(document.createTextNode("New Sequence: " + this.currentMinoInx));
|
||||||
|
document.getElementById("Openers").appendChild(newOpener);
|
||||||
|
|
||||||
|
|
||||||
|
openers.addSequence(this.shapeQueue);
|
||||||
|
//this.setFreePlay();
|
||||||
|
this.gameState = consts.GAMESTATES[1];
|
||||||
|
this.currentMinoInx = 0;
|
||||||
|
//this.setCurrentOpener(99999);//this.currentMinoInx);
|
||||||
|
clearMatrix(this.matrix);
|
||||||
|
this.currentOpener = 9999;
|
||||||
|
this.shapeQueue = [];
|
||||||
|
this.hintQueue = [];
|
||||||
|
this._recurseGameState();
|
||||||
},
|
},
|
||||||
setSettings: function() {
|
setSettings: function() {
|
||||||
var newVal = document.getElementById("setting_value").value;
|
var newVal = document.getElementById("setting_value").value;
|
||||||
@ -303,6 +346,13 @@ Tetris.prototype = {
|
|||||||
},
|
},
|
||||||
pushHoldStack: function()
|
pushHoldStack: function()
|
||||||
{
|
{
|
||||||
|
if(this.gameState == consts.GAMESTATES[3]) {
|
||||||
|
while(this.holdStack.length < 7)
|
||||||
|
this.holdStack.unshift(utils.deepClone(shapes.getShape(this.currentMinoInx++%7)));
|
||||||
|
this.shape = this.holdStack.pop();
|
||||||
|
this._draw();
|
||||||
|
return;
|
||||||
|
}
|
||||||
// 1 shape hold queue
|
// 1 shape hold queue
|
||||||
if(this.holdStack.length > 0) {
|
if(this.holdStack.length > 0) {
|
||||||
this.canPopFromHoldStack = false;
|
this.canPopFromHoldStack = false;
|
||||||
@ -328,6 +378,19 @@ Tetris.prototype = {
|
|||||||
},
|
},
|
||||||
popHoldStack: function()
|
popHoldStack: function()
|
||||||
{
|
{
|
||||||
|
if(this.gameState == consts.GAMESTATES[3]) {
|
||||||
|
if(this.holdStack.length < 7)
|
||||||
|
while(this.holdStack.length < 7)
|
||||||
|
this.holdStack.unshift(utils.deepClone(shapes.getShape(this.currentMinoInx++%7)));
|
||||||
|
// piece needs to be able to be placed
|
||||||
|
if(this.shape.canDown(this.matrix)) return;
|
||||||
|
this.shape.copyTo(this.matrix);
|
||||||
|
this.shapeQueue.unshift(utils.deepClone(this.shape));
|
||||||
|
this.shape = this.holdStack.pop();
|
||||||
|
this._check();
|
||||||
|
this._draw();
|
||||||
|
return;
|
||||||
|
}
|
||||||
// todo: disable if 1 shape hold queue
|
// todo: disable if 1 shape hold queue
|
||||||
if(this.holdStack.length >= 1 && this.canPopFromHoldStack)
|
if(this.holdStack.length >= 1 && this.canPopFromHoldStack)
|
||||||
{
|
{
|
||||||
@ -383,7 +446,7 @@ Tetris.prototype = {
|
|||||||
|
|
||||||
// Opener sequence completed
|
// Opener sequence completed
|
||||||
if(this.currentMinoInx > openers.getLength()) {
|
if(this.currentMinoInx > openers.getLength()) {
|
||||||
new Audio("./dist/sound/Affirm.ogg").play();
|
//new Audio("./dist/sound/Affirm2.ogg").play();
|
||||||
if(this.isTimerOn) {
|
if(this.isTimerOn) {
|
||||||
var besttime = document.getElementById("besttime").value;
|
var besttime = document.getElementById("besttime").value;
|
||||||
var deltaTime = new Date().getTime() - this.sequencePrevTime;
|
var deltaTime = new Date().getTime() - this.sequencePrevTime;
|
||||||
@ -398,14 +461,22 @@ Tetris.prototype = {
|
|||||||
this.shapeQueue = [];
|
this.shapeQueue = [];
|
||||||
|
|
||||||
this.isSequenceCompleted = true;
|
this.isSequenceCompleted = true;
|
||||||
|
|
||||||
// Recursion warning
|
// Recursion warning
|
||||||
this._restartHandler();
|
if(this.currentOpener < 1000) // getting real hacky
|
||||||
|
this._restartHandler();
|
||||||
|
else clearMatrix(this.matrix);
|
||||||
// this.reset();
|
// this.reset();
|
||||||
// this.start();
|
// this.start();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
// Fill next queue and set next shape
|
// Process sequence editor
|
||||||
|
_processSequenceEditor: function () {
|
||||||
|
return;
|
||||||
|
},
|
||||||
|
|
||||||
|
// Fill next queue and set next shape
|
||||||
_fireShape: function() {
|
_fireShape: function() {
|
||||||
//todo:should be in shapes.js
|
//todo:should be in shapes.js
|
||||||
this.landed = false;
|
this.landed = false;
|
||||||
@ -427,6 +498,8 @@ Tetris.prototype = {
|
|||||||
case consts.GAMESTATES[2]:
|
case consts.GAMESTATES[2]:
|
||||||
this._processOpenerTrainerQueue();
|
this._processOpenerTrainerQueue();
|
||||||
this._fireShape();
|
this._fireShape();
|
||||||
|
case consts.GAMESTATES[3]:
|
||||||
|
this._processSequenceEditor();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@ -488,18 +561,10 @@ Tetris.prototype = {
|
|||||||
|
|
||||||
|
|
||||||
if(this.gamepadEnabled && inputs.gamepadEnabled()) {
|
if(this.gamepadEnabled && inputs.gamepadEnabled()) {
|
||||||
var tenthOfFrame = 1.0 //1.6; // 1.6ms = 1 fram
|
|
||||||
var halfFrame = 5.0 //8.0;
|
|
||||||
var halfFramePlus = 10.0;
|
|
||||||
|
|
||||||
|
|
||||||
inputs.updateGamepad();
|
inputs.updateGamepad();
|
||||||
inputs.processGamepadDPad();
|
inputs.processGamepadDPad();
|
||||||
inputs.processGamepadInput();
|
inputs.processGamepadInput();
|
||||||
|
|
||||||
// drain gamepad queue
|
|
||||||
// if( inputs.getTickCounter() > halfFrame) // 8 millisecons
|
|
||||||
// {
|
|
||||||
while((inputs.gamepadQueue != undefined && inputs.gamepadQueue.length >= 1)){
|
while((inputs.gamepadQueue != undefined && inputs.gamepadQueue.length >= 1)){
|
||||||
var curkey = inputs.gamepadQueue.shift();
|
var curkey = inputs.gamepadQueue.shift();
|
||||||
if(inputs.settingsMap.get("Gamepad Left").includes(curkey)) {
|
if(inputs.settingsMap.get("Gamepad Left").includes(curkey)) {
|
||||||
@ -527,9 +592,15 @@ Tetris.prototype = {
|
|||||||
this._draw();
|
this._draw();
|
||||||
}
|
}
|
||||||
else if(inputs.settingsMap.get("Gamepad Harddrop").includes(curkey)) {
|
else if(inputs.settingsMap.get("Gamepad Harddrop").includes(curkey)) {
|
||||||
|
// if editor
|
||||||
|
if(this.gameState == consts.GAMESTATES[3]) {
|
||||||
|
this.popHoldStack();
|
||||||
|
this._draw();
|
||||||
|
}else {
|
||||||
this.shape.goBottom(this.matrix);
|
this.shape.goBottom(this.matrix);
|
||||||
this.lockDownTimer = 5000;
|
this.lockDownTimer = 5000;
|
||||||
this._update();
|
this._update();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if(inputs.settingsMap.get("Gamepad Hold").includes(curkey)) {
|
else if(inputs.settingsMap.get("Gamepad Hold").includes(curkey)) {
|
||||||
this.pushHoldStack();
|
this.pushHoldStack();
|
||||||
@ -570,6 +641,11 @@ Tetris.prototype = {
|
|||||||
this.shape.goDown(this.matrix);
|
this.shape.goDown(this.matrix);
|
||||||
this._draw();
|
this._draw();
|
||||||
}
|
}
|
||||||
|
else if(this.gameState == consts.GAMESTATES[3] && inputs.settingsMap.get("Keyboard Up").includes(curkey)) {
|
||||||
|
|
||||||
|
this.shape.goUp(this.matrix);
|
||||||
|
this._draw();
|
||||||
|
}
|
||||||
else if(inputs.settingsMap.get("Keyboard Rotateccw").includes(curkey)) {
|
else if(inputs.settingsMap.get("Keyboard Rotateccw").includes(curkey)) {
|
||||||
this.shape.rotate(this.matrix);
|
this.shape.rotate(this.matrix);
|
||||||
this.resetLockdown();
|
this.resetLockdown();
|
||||||
@ -581,9 +657,15 @@ Tetris.prototype = {
|
|||||||
this._draw();
|
this._draw();
|
||||||
}
|
}
|
||||||
else if(inputs.settingsMap.get("Keyboard Harddrop").includes(curkey)) {
|
else if(inputs.settingsMap.get("Keyboard Harddrop").includes(curkey)) {
|
||||||
this.shape.goBottom(this.matrix);
|
// if editor
|
||||||
this.lockDownTimer = 5000;
|
if(this.gameState == consts.GAMESTATES[3]) {
|
||||||
this._update();
|
this.popHoldStack();
|
||||||
|
this._draw();
|
||||||
|
}else {
|
||||||
|
this.shape.goBottom(this.matrix);
|
||||||
|
this.lockDownTimer = 5000;
|
||||||
|
this._update();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if(inputs.settingsMap.get("Keyboard Hold").includes(curkey)) {
|
else if(inputs.settingsMap.get("Keyboard Hold").includes(curkey)) {
|
||||||
this.pushHoldStack();
|
this.pushHoldStack();
|
||||||
@ -646,25 +728,36 @@ Tetris.prototype = {
|
|||||||
// Update game data
|
// Update game data
|
||||||
_update: function() {
|
_update: function() {
|
||||||
|
|
||||||
if (this.shape.canDown(this.matrix)) {
|
switch(this.gameState) {
|
||||||
this.shape.goDown(this.matrix);
|
case consts.GAMESTATES[0]:
|
||||||
} else if(this.isPieceLocked()){
|
case consts.GAMESTATES[1]:
|
||||||
this.canPopFromHoldStack = true;
|
case consts.GAMESTATES[2]:
|
||||||
this.shape.copyTo(this.matrix);
|
if(this.shape == undefined) break;
|
||||||
this._check();
|
if (this.shape.canDown(this.matrix)) {
|
||||||
if(this._checkHint()) return;
|
this.shape.goDown(this.matrix);
|
||||||
//this._fireShape();
|
} else if(this.isPieceLocked()){
|
||||||
this._recurseGameState();
|
this.canPopFromHoldStack = true;
|
||||||
new Audio('./dist/sound/Blop2.ogg').play();
|
this.shape.copyTo(this.matrix);
|
||||||
}
|
this._check();
|
||||||
this._draw();
|
if(this._checkHint()) return;
|
||||||
this.isGameOver = checkGameOver(this.matrix);
|
//this._fireShape();
|
||||||
|
this._recurseGameState();
|
||||||
// if game over and gamestate is free play
|
new Audio('./dist/sound/Blop2.ogg').play();
|
||||||
views.setGameOver(this.gameState == consts.GAMESTATES[0] && this.isGameOver);
|
}
|
||||||
|
this._draw();
|
||||||
if (this.isGameOver)
|
this.isGameOver = checkGameOver(this.matrix);
|
||||||
views.setFinalScore(this.score);
|
|
||||||
|
// if game over and gamestate is free play
|
||||||
|
views.setGameOver(this.gameState == consts.GAMESTATES[0] && this.isGameOver);
|
||||||
|
|
||||||
|
if (this.isGameOver)
|
||||||
|
views.setFinalScore(this.score);
|
||||||
|
break;
|
||||||
|
case consts.GAMESTATES[3]:
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
// 0 - none, 1 - mini, 2 - tspin
|
// 0 - none, 1 - mini, 2 - tspin
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
var shapes = require("./shapes.js");
|
var shapes = require("./shapes.js");
|
||||||
|
var utils = require("./utils.js");
|
||||||
// import * as shapes from './shapes.js';
|
// import * as shapes from './shapes.js';
|
||||||
|
|
||||||
// https://harddrop.com/wiki/Opener
|
// https://harddrop.com/wiki/Opener
|
||||||
@ -171,6 +172,7 @@ var openerGenerator = {
|
|||||||
shapes.getShape(3));
|
shapes.getShape(3));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
this.shapeQueue.unshift(utils.deepClone(shapes.randomShape()));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -185,7 +187,9 @@ var openerGenerator = {
|
|||||||
this.idx++;
|
this.idx++;
|
||||||
if(this.idx == this.shapeQueue.length) {
|
if(this.idx == this.shapeQueue.length) {
|
||||||
this.idx = 0;
|
this.idx = 0;
|
||||||
this.isInit = 0;
|
if(opener < 1000)
|
||||||
|
this.isInit = 0;
|
||||||
|
else this.isInit = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return mino;
|
return mino;
|
||||||
@ -441,6 +445,7 @@ var openerGenerator = {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
this.hintQueue.unshift(utils.deepClone(shapes.randomShape()));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -458,7 +463,9 @@ var openerGenerator = {
|
|||||||
this.hintIdx++;
|
this.hintIdx++;
|
||||||
if(this.hintIdx == this.hintQueue.length) {
|
if(this.hintIdx == this.hintQueue.length) {
|
||||||
this.hintIdx = 0;
|
this.hintIdx = 0;
|
||||||
this.isHintInit = 0;
|
if(opener < 1000)
|
||||||
|
this.isHintInit = 0;
|
||||||
|
else this.isHintInit = 1;
|
||||||
}
|
}
|
||||||
return mino;
|
return mino;
|
||||||
},
|
},
|
||||||
@ -473,6 +480,27 @@ var openerGenerator = {
|
|||||||
},
|
},
|
||||||
getLength() {
|
getLength() {
|
||||||
return this.hintQueue.length;
|
return this.hintQueue.length;
|
||||||
|
},
|
||||||
|
addSequence(sequence) {
|
||||||
|
//this.reset();
|
||||||
|
//this.shapeQueue = utils.deepClone(sequence);
|
||||||
|
//this.hintQueue = utils.deepClone(sequence);
|
||||||
|
for(var i in sequence)
|
||||||
|
{
|
||||||
|
var shape;
|
||||||
|
shape = sequence[i];
|
||||||
|
shape.x = sequence[i].x;
|
||||||
|
shape.y = sequence[i].y;
|
||||||
|
shape.state = sequence[i].state;
|
||||||
|
this.hintQueue.unshift(utils.deepClone(shape));
|
||||||
|
shape.x = shape.originX;
|
||||||
|
shape.y = shape.originY;
|
||||||
|
this.shapeQueue.unshift(utils.deepClone(shape));
|
||||||
|
this.isInit = 1;
|
||||||
|
this.isHintInit = 1;
|
||||||
|
this.idx = 0;
|
||||||
|
this.hintIdx = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -491,6 +519,12 @@ function getNextHint(opener) {
|
|||||||
function getLength() {
|
function getLength() {
|
||||||
return openerGenerator.getLength();
|
return openerGenerator.getLength();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function addSequence(sequence) {
|
||||||
|
openerGenerator.addSequence(sequence);
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports.addSequence = addSequence;
|
||||||
module.exports.getNextMino = getNextMino;
|
module.exports.getNextMino = getNextMino;
|
||||||
module.exports.getNextHint = getNextHint;
|
module.exports.getNextHint = getNextHint;
|
||||||
module.exports.getLength = getLength;
|
module.exports.getLength = getLength;
|
||||||
|
@ -71,6 +71,7 @@ function ShapeL() {
|
|||||||
this.states = [state1, state2, state3, state4];
|
this.states = [state1, state2, state3, state4];
|
||||||
this.x = 3;
|
this.x = 3;
|
||||||
this.y = -3;
|
this.y = -3;
|
||||||
|
this.originX = 3;
|
||||||
this.originY = -3;
|
this.originY = -3;
|
||||||
this.flag = 'L';
|
this.flag = 'L';
|
||||||
}
|
}
|
||||||
@ -137,6 +138,7 @@ function ShapeLR() {
|
|||||||
this.states = [state1, state2, state3, state4];
|
this.states = [state1, state2, state3, state4];
|
||||||
this.x = 3;
|
this.x = 3;
|
||||||
this.y = -3;
|
this.y = -3;
|
||||||
|
this.originX = 3;
|
||||||
this.originY = -3;
|
this.originY = -3;
|
||||||
this.flag = 'LR';
|
this.flag = 'LR';
|
||||||
}
|
}
|
||||||
@ -201,6 +203,7 @@ function ShapeO() {
|
|||||||
this.states = [state1, state2, state3, state4];
|
this.states = [state1, state2, state3, state4];
|
||||||
this.x = 2;
|
this.x = 2;
|
||||||
this.y = -2;
|
this.y = -2;
|
||||||
|
this.originX = 2;
|
||||||
this.originY = -2;
|
this.originY = -2;
|
||||||
this.flag = 'O';
|
this.flag = 'O';
|
||||||
}
|
}
|
||||||
@ -305,6 +308,7 @@ function ShapeI() {
|
|||||||
|
|
||||||
this.x = 3;
|
this.x = 3;
|
||||||
this.y = -4;
|
this.y = -4;
|
||||||
|
this.originX = 3;
|
||||||
this.originY = -4;
|
this.originY = -4;
|
||||||
this.flag = 'I';
|
this.flag = 'I';
|
||||||
}
|
}
|
||||||
@ -371,6 +375,7 @@ function ShapeT() {
|
|||||||
|
|
||||||
this.x = 3;
|
this.x = 3;
|
||||||
this.y = -2;
|
this.y = -2;
|
||||||
|
this.originX = 3;
|
||||||
this.originY = -2;
|
this.originY = -2;
|
||||||
this.flag = 'T';
|
this.flag = 'T';
|
||||||
}
|
}
|
||||||
@ -436,6 +441,7 @@ function ShapeZ() {
|
|||||||
this.states = [state1, state2, state3, state4];
|
this.states = [state1, state2, state3, state4];
|
||||||
this.x = 3;
|
this.x = 3;
|
||||||
this.y = -2;
|
this.y = -2;
|
||||||
|
this.originX = 3;
|
||||||
this.originY = -2;
|
this.originY = -2;
|
||||||
this.flag = 'Z';
|
this.flag = 'Z';
|
||||||
}
|
}
|
||||||
@ -501,6 +507,7 @@ function ShapeZR() {
|
|||||||
this.states = [state1, state2, state3, state4];
|
this.states = [state1, state2, state3, state4];
|
||||||
this.x = 3;
|
this.x = 3;
|
||||||
this.y = -2
|
this.y = -2
|
||||||
|
this.originX = 3;
|
||||||
this.originY = -2;
|
this.originY = -2;
|
||||||
this.flag = 'ZR';
|
this.flag = 'ZR';
|
||||||
}
|
}
|
||||||
@ -605,6 +612,9 @@ var isShapeCanMove = function(shape, matrix, action) {
|
|||||||
} else if (action === 'right') {
|
} else if (action === 'right') {
|
||||||
x += 1;
|
x += 1;
|
||||||
return x >= 0 && x < cols && matrix[y][x] == 0;
|
return x >= 0 && x < cols && matrix[y][x] == 0;
|
||||||
|
} else if (action === 'up') {
|
||||||
|
y -= 1;
|
||||||
|
return y >= 0 && matrix[y][x] == 0;
|
||||||
} else if (action === 'down') {
|
} else if (action === 'down') {
|
||||||
y += 1;
|
y += 1;
|
||||||
return y < rows && matrix[y][x] == 0;
|
return y < rows && matrix[y][x] == 0;
|
||||||
@ -775,6 +785,12 @@ ShapeZR.prototype = {
|
|||||||
this.y += 1;
|
this.y += 1;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
//Move the shape up
|
||||||
|
goUp: function(matrix) {
|
||||||
|
if (isShapeCanMove(this, matrix, 'up')) {
|
||||||
|
this.y -= 1;
|
||||||
|
}
|
||||||
|
},
|
||||||
//Move the shape to the Bottommost
|
//Move the shape to the Bottommost
|
||||||
bottomAt: function(matrix) {
|
bottomAt: function(matrix) {
|
||||||
var save = this.y;
|
var save = this.y;
|
||||||
|
Loading…
Reference in New Issue
Block a user