From f1b4d94dc740802b7043f3ea6563b98a8cf81fdd Mon Sep 17 00:00:00 2001 From: "PolicyChanges1@gmail.com" Date: Mon, 8 Mar 2021 15:52:04 -0500 Subject: [PATCH] odds and ends --- css/styles.css | 10 +- dist/tetrion.js | 274 +++++++++++++++++++++++++----------------------- index.html | 43 ++++---- src/input.js | 100 ++++++++---------- src/main.js | 142 ++++++++++++------------- src/openers.js | 32 ++++++ src/sequence.js | 2 + 7 files changed, 310 insertions(+), 293 deletions(-) diff --git a/css/styles.css b/css/styles.css index f3c61b0..ec6adbc 100644 --- a/css/styles.css +++ b/css/styles.css @@ -42,7 +42,7 @@ body{ left:0px; width:210px; text-align: left; - background:rgba(200,200,200,.03); + background:rgba(20,20,20,.5); } #leftInfo{ @@ -58,12 +58,12 @@ body{ #leftInfo ul {padding:2%;} #hold{ - left:55px; + left:45%; position:relative; width:80px; height:400px; margin:5px auto; - background:rgba(1,1,1,.3); + background: rgba(0,0,0,.8); /*rgba(50,50,50,.5);*/ } #gameOver{ @@ -106,7 +106,7 @@ body{ width:210px; left:210px; margin:0 auto; - background:rgba(200,200,200,.03); + background:rgba(20,20,20,.5); } #preview{ @@ -114,7 +114,7 @@ body{ height:400px; top:0px; margin:10px auto; - background:rgba(1,1,1,.3); + background:rgba(0,0,0,.8); } diff --git a/dist/tetrion.js b/dist/tetrion.js index 867bbfc..b37e80b 100644 --- a/dist/tetrion.js +++ b/dist/tetrion.js @@ -428,12 +428,16 @@ var utils = require('./utils.js'); var UserInputs = { init() { + + this.settingsList = this.keyboardKeySettings.concat(this.keyboardShiftEvents.concat(this.keyboardKeyEvents.concat(this.gamepadSettings.concat(this.gamepadShiftEvents.concat(this.gamepadButtonEvents))))); + //;["Soft Drop Rate [1 - 100]"].concat(this.keyboardSettings.concat(this.gamepadSettings)); this.gamepadShiftTimer = new Date(); this.gamepadButtonTimer = new Date(); this.keyboardKeyTimer = new Date(); this.keyboardShiftTimer = new Date(); - this.settingsMap = new Map(); - + this.settingsMap = new Map(); + this.gamepadEventMap = new Map(); + ///this.gamepadEventMap = new Map(); // var init = utils.getCookie("init"); // if(init == "") for(var i in this.settingsList) @@ -445,6 +449,15 @@ var UserInputs = { for(var i in this.settingsList) this.settingsMap.set(this.settingsList[i], this.settingsDefault[i]); + + this.gamepadEvents = this.gamepadShiftEvents.concat(this.gameButtonsEvents); + + var mapIdx = [14, 7, 13, 5, 4, 1, 2, 12, 8, 3]; + for(var i in mapIdx) { + this.gamepadEventMap.set(this.gamepadEvents[i], gamepad.buttons[mapIdx[i]]); + } + + document.addEventListener('keydown', this.keyDown.bind(this)); document.addEventListener('keyup', this.keyUp.bind(this)); }, @@ -455,25 +468,11 @@ var UserInputs = { gamepadEnabled() { return gamepad.controller || false; }, - processGamepadInput() { - this.gamepadButtonsDown(this.settingsMap.get("Gamepad Harddrop")); // hard drop - this.gamepadButtonsDown(this.settingsMap.get("Gamepad Hold")); // hold - this.gamepadButtonsDown(this.settingsMap.get("Gamepad Rotateccw")); // rotate counter - this.gamepadButtonsDown(this.settingsMap.get("Gamepad Rotate")); // rotate cwise - this.gamepadButtonsDown(this.settingsMap.get("Gamepad Pophold")); // Pop hold stack - this.gamepadButtonsDown(this.settingsMap.get("Gamepad Reset")); // reset - - - return; + this.gamepadButtonEvents.forEach(gamepadButton => this.gamepadButtonsDown(this.settingsMap.get(gamepadButton))); }, - processGamepadDPad() { - this.gamepadDPadDown(this.settingsMap.get("Gamepad Left")); // shift left - this.gamepadDPadDown(this.settingsMap.get("Gamepad Right")); // shift right - this.gamepadDPadDown(this.settingsMap.get("Gamepad Down")); // down - - return; + this.gamepadShiftEvents.forEach(dpadButton => this.gamepadDPadDown(this.settingsMap.get(dpadButton))); }, // Single press gamepad buttons gamepadButtonsDown(finds) { @@ -512,6 +511,7 @@ var UserInputs = { gamepadDPadDown(finds) { var DAS = parseInt(this.settingsMap.get("Gamepad DAS")); var ARR = parseInt(this.settingsMap.get("Gamepad ARR")); + var isContained = this.gpButtons.includes(finds); var isPrevContained = this.prevGpButtons.includes(finds); @@ -538,20 +538,11 @@ var UserInputs = { this.gamepadShiftTimer = new Date(); } } - - return; }, - // doing a lot of back and forth between strings and integers to represtent the same thing -- todo: fix + processKeys() { - this.processKeyDown(parseInt(this.settingsMap.get("Keyboard Harddrop"))); - this.processKeyDown(parseInt(this.settingsMap.get("Keyboard Rotate"))); - this.processKeyDown(parseInt(this.settingsMap.get("Keyboard Rotateccw"))); - this.processKeyDown(parseInt(this.settingsMap.get("Keyboard Hold"))); - this.processKeyDown(parseInt(this.settingsMap.get("Keyboard Pophold"))); - this.processKeyDown(parseInt(this.settingsMap.get("Keyboard Background"))); - this.processKeyDown(parseInt(this.settingsMap.get("Keyboard Reset"))); - //this.processKeyDown(this.settingsMap.get("Keyboard hold"))); // c - pop hold stack + this.keyboardKeyEvents.forEach( key => this.settingsMap.get(key).split(',').forEach( idx => this.processKeyDown( parseInt(idx) ) ) ); }, // keyboard keys z,x,space @@ -583,15 +574,10 @@ var UserInputs = { this.keyboardKeyTimer = new Date(); } } - - - }, // Process applicable key inputs processKeyShift() { - this.processKeyboardArrowKeys(parseInt(this.settingsMap.get("Keyboard Left"))); - this.processKeyboardArrowKeys(parseInt(this.settingsMap.get("Keyboard Right"))); - this.processKeyboardArrowKeys(parseInt(this.settingsMap.get("Keyboard Down"))); + this.keyboardShiftEvents.forEach(arrowKey => arrowKey.split(',').forEach(option => this.processKeyboardArrowKeys(parseInt(this.settingsMap.get(option))))); }, // Direction arrows processKeyboardArrowKeys(key) { @@ -637,11 +623,9 @@ var UserInputs = { this.keyboardKeys[event.keyCode] = false; this.isKeyBoardKeyDown = false; }, - gamepadButtonClear() { - gpButtons = []; - isGamepadDown = false; - isGamepadButtonDown = false; - gamepadQueue = []; + gamepadClear() { + //this.gpButtons = []; + //this.gamepadQueue = []; }, saveButtons() { this.prevGpButtons = this.gpButtons; @@ -665,26 +649,24 @@ var UserInputs = { // button pressed containers inputQueue: [], gamepadQueue: [], - - settingsList: ["Soft Drop Rate [1 - 100]", - "Keyboard DAS", "Keyboard ARR", "Keyboard Harddrop", "Keyboard Hold", - "Keyboard Left", "Keyboard Right", "Keyboard Rotateccw", "Keyboard Rotate", - "Keyboard Down", "Keyboard Pophold", "Keyboard Reset", "Keyboard Background", + + keyboardKeySettings: ["Keyboard DAS", "Keyboard ARR"], + keyboardShiftEvents: ["Keyboard Left", "Keyboard Right", "Keyboard Down"], + keyboardKeyEvents: ["Keyboard Harddrop", "Keyboard Hold", "Keyboard Rotateccw", "Keyboard Rotate", "Keyboard Pophold", "Keyboard Reset", "Keyboard Background"], - "Gamepad DAS", "Gamepad ARR", "Gamepad Harddrop", "Gamepad Hold", - "Gamepad Left", "Gamepad Right", "Gamepad Rotateccw", "Gamepad Rotate", - "Gamepad Down","Gamepad Pophold", "Gamepad Reset", "Gamepad Background", - "path", "High Score"], - - settingsDefault: ["70", - "167.0", "33.0", "32", "16", - "37", "39", "90", "88", - "40", "17", "82", "81", - - "167.0", "33.0", "RB", "LB", - "DPad-Left", "DPad-Right", "A", "B", - "DPad-Down", "DPad-Up", "Back", "", - "=/",""], + gamepadSettings: ["Gamepad DAS", "Gamepad ARR"], + gamepadShiftEvents: ["Gamepad Left", "Gamepad Right","Gamepad Down"], + gamepadButtonEvents: ["Gamepad Harddrop", "Gamepad Hold", "Gamepad Rotateccw", "Gamepad Rotate", "Gamepad Pophold", "Gamepad Reset", "Gamepad Background"], + + settingsList: [], + + settingsDefault: [ "167.0", "33.0", + "37", "39", "40", + "32", "16", "90", "88,38", "17", "82", "81", + + "167.0", "33.0", + "DPad-Left", "DPad-Right", "DPad-Down", + "RB", "LB", "A", "B", "DPad-Up", "Back", ""], settingsMap: [] }; @@ -839,11 +821,7 @@ function Tetris(id) { } Tetris.prototype = { - init: function(options) { - - // this gameStates = {" - // this.state = var cfg = this.config = utils.extend(options, defaults); this.interval = consts.DEFAULT_INTERVAL; @@ -950,6 +928,7 @@ Tetris.prototype = { this.shapeQueue = []; this.hintQueue = []; this.holdStack = []; + this.shape = shapes.getShape(0); // gets set to false after mino has been popped from hold stack; set back to true on mino dropped this.canPopFromHoldStack = false; // manipulation counter for srs extended piece lockdown @@ -1042,14 +1021,19 @@ Tetris.prototype = { if(besttime == "" || deltaTime/1000.0 < parseFloat(besttime)) { document.getElementById("besttime").value = (deltaTime/1000.0).toString(); } - this.isSequenceCompleted = true; - } + + } + this.hintQueue = []; this.shapeQueue = []; + this.isSequenceCompleted = true; // Recursion warning - this._restartHandler(); + this._restartHandler(); + // this.reset(); + // this.start(); + return; } } else { while(this.shapeQueue.length <= 4) @@ -1112,21 +1096,17 @@ Tetris.prototype = { }, + // tick input data -- wont have better than 4-15ms resolution since javascript is single theaded and any ARR or DAS below 15ms will likely be broken _processTick: async function() { - //var deltaTime = (new Date()).getTime() - this.eventTimer.getTime(); - //console.log("desync time: " + deltaTime); - - if(this.isTimerOn) { var deltaPlayTime = new Date().getTime() - this.sequencePrevTime; document.getElementById("Time").value = (deltaPlayTime/1000).toString(); } - // Don't process game related events if game over if(this.isGameOver) return; @@ -1145,56 +1125,52 @@ Tetris.prototype = { // drain gamepad queue // if( inputs.getTickCounter() > halfFrame) // 8 millisecons // { - while((inputs.gamepadQueue != undefined && inputs.gamepadQueue.length >= 1)){ - var curkey = inputs.gamepadQueue.shift(); - if(curkey == "DPad-Left") { - this.shape.goLeft(this.matrix); - this.resetLockdown(); - this._draw(); - } - if(curkey == "DPad-Right") { - this.shape.goRight(this.matrix); - this.resetLockdown(); - this._draw(); - } - if(curkey == "A") { - this.rotationCounter++; - this.shape.rotate(this.matrix); - this.resetLockdown(); - this._draw(); - } - if(curkey == "B") { - this.rotationCounter++; - this.shape.rotateClockwise(this.matrix); - this.resetLockdown(); - this._draw(); - } - if(curkey == "DPad-Down") { - this.shape.goDown(this.matrix); - this._draw(); - } - if(curkey == "RB") { - this.shape.goBottom(this.matrix); - this.lockDownTimer = 5000; - this._update(); - } - if(curkey == "LB") { - this.pushHoldStack(); - this._draw(); - } - if(curkey == "DPad-Up") { - this.popHoldStack(); - this._draw(); - } - if(curkey == "Back") { - this._restartHandler(); - return; - } + while((inputs.gamepadQueue != undefined && inputs.gamepadQueue.length >= 1)){ + var curkey = inputs.gamepadQueue.shift(); + if(inputs.settingsMap.get("Gamepad Left").includes(curkey)) { + this.shape.goLeft(this.matrix); + this.resetLockdown(); + this._draw(); } - - inputs.gamepadQueue = []; - // } - //inputs.gamepadButtonClear(); + else if(inputs.settingsMap.get("Gamepad Right").includes(curkey)) { + this.shape.goRight(this.matrix); + this.resetLockdown(); + this._draw(); + } + else if(inputs.settingsMap.get("Gamepad Rotateccw").includes(curkey)) { + this.shape.rotate(this.matrix); + this.resetLockdown(); + this._draw(); + } + else if(inputs.settingsMap.get("Gamepad Rotate").includes(curkey)) { + this.shape.rotateClockwise(this.matrix); + this.resetLockdown(); + this._draw(); + } + else if(inputs.settingsMap.get("Gamepad Down").includes(curkey)) { + this.shape.goDown(this.matrix); + this._draw(); + } + else if(inputs.settingsMap.get("Gamepad Harddrop").includes(curkey)) { + this.shape.goBottom(this.matrix); + this.lockDownTimer = 5000; + this._update(); + } + else if(inputs.settingsMap.get("Gamepad Hold").includes(curkey)) { + this.pushHoldStack(); + this._draw(); + } + else if(inputs.settingsMap.get("Gamepad Pophold").includes(curkey)) { + this.popHoldStack(); + this._draw(); + } + else if(inputs.settingsMap.get("Gamepad Reset").includes(curkey)) { + this._restartHandler(); + return; + } + } + inputs.saveButtons(); + inputs.gamepadClear(); } @@ -1204,54 +1180,51 @@ Tetris.prototype = { // Keyboard inputs while((inputs.inputQueue != undefined && inputs.inputQueue.length >= 1)){ var curkey = inputs.inputQueue.shift(); - if(curkey == 37) { - this.debugTimer = new Date(); + if(inputs.settingsMap.get("Keyboard Left").includes(curkey)) { this.shape.goLeft(this.matrix); this.resetLockdown(); this._draw(); } - if(curkey == 39){ + else if(inputs.settingsMap.get("Keyboard Right").includes(curkey)) { this.shape.goRight(this.matrix); this.resetLockdown(); this._draw(); } - if(curkey == 40) { + else if(inputs.settingsMap.get("Keyboard Down").includes(curkey)) { this.shape.goDown(this.matrix); this._draw(); } - if(curkey == 90) { - this.rotationCounter++; + else if(inputs.settingsMap.get("Keyboard Rotateccw").includes(curkey)) { this.shape.rotate(this.matrix); this.resetLockdown(); this._draw(); } - if(curkey == 88){ - this.rotationCounter++; + else if(inputs.settingsMap.get("Keyboard Rotate").includes(curkey)) { this.shape.rotateClockwise(this.matrix); this.resetLockdown(); this._draw(); } - if(curkey == 32) { + else if(inputs.settingsMap.get("Keyboard Harddrop").includes(curkey)) { this.shape.goBottom(this.matrix); this.lockDownTimer = 5000; this._update(); } - if(curkey == 16) { + else if(inputs.settingsMap.get("Keyboard Hold").includes(curkey)) { this.pushHoldStack(); this._draw(); } - if(curkey == 17 || curkey == 67) { + else if(inputs.settingsMap.get("Keyboard Pophold").includes(curkey)) { this.popHoldStack(); this._draw(); } - if(curkey == 81) { + else if(inputs.settingsMap.get("Keyboard Hold").includes(curkey)) { if(document.getElementById("divbg").style.display == "none") document.getElementById("divbg").style.display = "initial"; else document.getElementById("divbg").style.display="none"; } - if(curkey == 82) { + if(inputs.settingsMap.get("Keyboard Reset").includes(curkey)) { this._restartHandler(); return; } @@ -1387,7 +1360,8 @@ Tetris.prototype = { views.setLevel(this.level); this.levelTime = currentTime; } - } + }, + } @@ -1539,6 +1513,17 @@ var openerGenerator = { shapes.getShape(2), shapes.getShape(5), shapes.getShape(3)); + break; + case 9: + // Pelican + this.shapeQueue = new Array( + shapes.getShape(5), + shapes.getShape(2), + shapes.getShape(4), + shapes.getShape(0), + shapes.getShape(6), + shapes.getShape(1), + shapes.getShape(3)); break; default: return; @@ -1567,6 +1552,8 @@ var openerGenerator = { switch(opener) { case 0: + this.hintQueue = []; + break; case 1: // Fonzie Variation this.hintQueue = new Array( @@ -1766,6 +1753,25 @@ var openerGenerator = { this.hintQueue[i].state = this.hintQueue[i].nextState(hintDataList[i * 3 + 2]); } break; + case 9: + // Pelican + this.hintQueue = new Array( + shapes.getShape(5), + shapes.getShape(2), + shapes.getShape(4), + shapes.getShape(0), + shapes.getShape(6), + shapes.getShape(1), + shapes.getShape(3)); + + var hintDataList = [0,17,-1, 1,16,2, 5,18,0, 5,16,-1, 8,16,-1, 5,17,0, 3,16,2]; + + for(var i = 0; i < this.hintQueue.length; i++) { + this.hintQueue[i].x = hintDataList[i * 3]; + this.hintQueue[i].y = hintDataList[i * 3 + 1]; + this.hintQueue[i].state = this.hintQueue[i].nextState(hintDataList[i * 3 + 2]); + } + break; default: return; } diff --git a/index.html b/index.html index 594a28a..64db1c9 100644 --- a/index.html +++ b/index.html @@ -39,28 +39,28 @@
- - - - - - - - - - + @@ -124,7 +124,6 @@ document.getElementById("divbg").removeAttribute("tabIndex");
  • Neither L nor J
  • Both L and J
  • T piece
  • -
  • see also
  • @@ -133,11 +132,11 @@ document.getElementById("divbg").removeAttribute("tabIndex");

    - - + + - - + +
    @@ -155,14 +154,14 @@ document.getElementById("divbg").removeAttribute("tabIndex");
    - - - + +
    - - + +
    @@ -185,6 +184,8 @@ document.getElementById("divbg").removeAttribute("tabIndex"); document.getElementById("setHachispinVar").addEventListener("click", function() { tetrion.setCurrentOpener(6); } ); document.getElementById("setAlbatrossVar").addEventListener("click", function() { tetrion.setCurrentOpener(7); } ); document.getElementById("setNumberOneVar").addEventListener("click", function() { tetrion.setCurrentOpener(8); } ); + document.getElementById("setPelicanVar").addEventListener("click", function() { tetrion.setCurrentOpener(9); } ); + document.getElementById("enablegamepad").addEventListener("click", function() { tetrion.toggleGamepad(); } ); @@ -193,6 +194,8 @@ document.getElementById("divbg").removeAttribute("tabIndex"); document.getElementById("test").addEventListener("click", function() { tetrion.setDoTest(); } ); document.getElementById("settings").addEventListener("change", function() { tetrion.updateSettingTextBox(); } ); document.getElementById("submitsetting").addEventListener("click", function() { tetrion.setSettings(); } ); + + tetrion.start(); })(); diff --git a/src/input.js b/src/input.js index 15f007b..975ced0 100644 --- a/src/input.js +++ b/src/input.js @@ -4,12 +4,16 @@ var utils = require('./utils.js'); var UserInputs = { init() { + + this.settingsList = this.keyboardKeySettings.concat(this.keyboardShiftEvents.concat(this.keyboardKeyEvents.concat(this.gamepadSettings.concat(this.gamepadShiftEvents.concat(this.gamepadButtonEvents))))); + //;["Soft Drop Rate [1 - 100]"].concat(this.keyboardSettings.concat(this.gamepadSettings)); this.gamepadShiftTimer = new Date(); this.gamepadButtonTimer = new Date(); this.keyboardKeyTimer = new Date(); this.keyboardShiftTimer = new Date(); - this.settingsMap = new Map(); - + this.settingsMap = new Map(); + this.gamepadEventMap = new Map(); + ///this.gamepadEventMap = new Map(); // var init = utils.getCookie("init"); // if(init == "") for(var i in this.settingsList) @@ -21,6 +25,15 @@ var UserInputs = { for(var i in this.settingsList) this.settingsMap.set(this.settingsList[i], this.settingsDefault[i]); + + this.gamepadEvents = this.gamepadShiftEvents.concat(this.gameButtonsEvents); + + var mapIdx = [14, 7, 13, 5, 4, 1, 2, 12, 8, 3]; + for(var i in mapIdx) { + this.gamepadEventMap.set(this.gamepadEvents[i], gamepad.buttons[mapIdx[i]]); + } + + document.addEventListener('keydown', this.keyDown.bind(this)); document.addEventListener('keyup', this.keyUp.bind(this)); }, @@ -31,25 +44,11 @@ var UserInputs = { gamepadEnabled() { return gamepad.controller || false; }, - processGamepadInput() { - this.gamepadButtonsDown(this.settingsMap.get("Gamepad Harddrop")); // hard drop - this.gamepadButtonsDown(this.settingsMap.get("Gamepad Hold")); // hold - this.gamepadButtonsDown(this.settingsMap.get("Gamepad Rotateccw")); // rotate counter - this.gamepadButtonsDown(this.settingsMap.get("Gamepad Rotate")); // rotate cwise - this.gamepadButtonsDown(this.settingsMap.get("Gamepad Pophold")); // Pop hold stack - this.gamepadButtonsDown(this.settingsMap.get("Gamepad Reset")); // reset - - - return; + this.gamepadButtonEvents.forEach(gamepadButton => this.gamepadButtonsDown(this.settingsMap.get(gamepadButton))); }, - processGamepadDPad() { - this.gamepadDPadDown(this.settingsMap.get("Gamepad Left")); // shift left - this.gamepadDPadDown(this.settingsMap.get("Gamepad Right")); // shift right - this.gamepadDPadDown(this.settingsMap.get("Gamepad Down")); // down - - return; + this.gamepadShiftEvents.forEach(dpadButton => this.gamepadDPadDown(this.settingsMap.get(dpadButton))); }, // Single press gamepad buttons gamepadButtonsDown(finds) { @@ -88,6 +87,7 @@ var UserInputs = { gamepadDPadDown(finds) { var DAS = parseInt(this.settingsMap.get("Gamepad DAS")); var ARR = parseInt(this.settingsMap.get("Gamepad ARR")); + var isContained = this.gpButtons.includes(finds); var isPrevContained = this.prevGpButtons.includes(finds); @@ -114,20 +114,11 @@ var UserInputs = { this.gamepadShiftTimer = new Date(); } } - - return; }, - // doing a lot of back and forth between strings and integers to represtent the same thing -- todo: fix + processKeys() { - this.processKeyDown(parseInt(this.settingsMap.get("Keyboard Harddrop"))); - this.processKeyDown(parseInt(this.settingsMap.get("Keyboard Rotate"))); - this.processKeyDown(parseInt(this.settingsMap.get("Keyboard Rotateccw"))); - this.processKeyDown(parseInt(this.settingsMap.get("Keyboard Hold"))); - this.processKeyDown(parseInt(this.settingsMap.get("Keyboard Pophold"))); - this.processKeyDown(parseInt(this.settingsMap.get("Keyboard Background"))); - this.processKeyDown(parseInt(this.settingsMap.get("Keyboard Reset"))); - //this.processKeyDown(this.settingsMap.get("Keyboard hold"))); // c - pop hold stack + this.keyboardKeyEvents.forEach( key => this.settingsMap.get(key).split(',').forEach( idx => this.processKeyDown( parseInt(idx) ) ) ); }, // keyboard keys z,x,space @@ -159,15 +150,10 @@ var UserInputs = { this.keyboardKeyTimer = new Date(); } } - - - }, // Process applicable key inputs processKeyShift() { - this.processKeyboardArrowKeys(parseInt(this.settingsMap.get("Keyboard Left"))); - this.processKeyboardArrowKeys(parseInt(this.settingsMap.get("Keyboard Right"))); - this.processKeyboardArrowKeys(parseInt(this.settingsMap.get("Keyboard Down"))); + this.keyboardShiftEvents.forEach(arrowKey => arrowKey.split(',').forEach(option => this.processKeyboardArrowKeys(parseInt(this.settingsMap.get(option))))); }, // Direction arrows processKeyboardArrowKeys(key) { @@ -213,11 +199,9 @@ var UserInputs = { this.keyboardKeys[event.keyCode] = false; this.isKeyBoardKeyDown = false; }, - gamepadButtonClear() { - gpButtons = []; - isGamepadDown = false; - isGamepadButtonDown = false; - gamepadQueue = []; + gamepadClear() { + //this.gpButtons = []; + //this.gamepadQueue = []; }, saveButtons() { this.prevGpButtons = this.gpButtons; @@ -241,26 +225,24 @@ var UserInputs = { // button pressed containers inputQueue: [], gamepadQueue: [], - - settingsList: ["Soft Drop Rate [1 - 100]", - "Keyboard DAS", "Keyboard ARR", "Keyboard Harddrop", "Keyboard Hold", - "Keyboard Left", "Keyboard Right", "Keyboard Rotateccw", "Keyboard Rotate", - "Keyboard Down", "Keyboard Pophold", "Keyboard Reset", "Keyboard Background", + + keyboardKeySettings: ["Keyboard DAS", "Keyboard ARR"], + keyboardShiftEvents: ["Keyboard Left", "Keyboard Right", "Keyboard Down"], + keyboardKeyEvents: ["Keyboard Harddrop", "Keyboard Hold", "Keyboard Rotateccw", "Keyboard Rotate", "Keyboard Pophold", "Keyboard Reset", "Keyboard Background"], - "Gamepad DAS", "Gamepad ARR", "Gamepad Harddrop", "Gamepad Hold", - "Gamepad Left", "Gamepad Right", "Gamepad Rotateccw", "Gamepad Rotate", - "Gamepad Down","Gamepad Pophold", "Gamepad Reset", "Gamepad Background", - "path", "High Score"], - - settingsDefault: ["70", - "167.0", "33.0", "32", "16", - "37", "39", "90", "88", - "40", "17", "82", "81", - - "167.0", "33.0", "RB", "LB", - "DPad-Left", "DPad-Right", "A", "B", - "DPad-Down", "DPad-Up", "Back", "", - "=/",""], + gamepadSettings: ["Gamepad DAS", "Gamepad ARR"], + gamepadShiftEvents: ["Gamepad Left", "Gamepad Right","Gamepad Down"], + gamepadButtonEvents: ["Gamepad Harddrop", "Gamepad Hold", "Gamepad Rotateccw", "Gamepad Rotate", "Gamepad Pophold", "Gamepad Reset", "Gamepad Background"], + + settingsList: [], + + settingsDefault: [ "167.0", "33.0", + "37", "39", "40", + "32", "16", "90", "88,38", "17", "82", "81", + + "167.0", "33.0", + "DPad-Left", "DPad-Right", "DPad-Down", + "RB", "LB", "A", "B", "DPad-Up", "Back", ""], settingsMap: [] }; diff --git a/src/main.js b/src/main.js index 14f8044..b54d365 100644 --- a/src/main.js +++ b/src/main.js @@ -146,11 +146,7 @@ function Tetris(id) { } Tetris.prototype = { - init: function(options) { - - // this gameStates = {" - // this.state = var cfg = this.config = utils.extend(options, defaults); this.interval = consts.DEFAULT_INTERVAL; @@ -257,6 +253,7 @@ Tetris.prototype = { this.shapeQueue = []; this.hintQueue = []; this.holdStack = []; + this.shape = shapes.getShape(0); // gets set to false after mino has been popped from hold stack; set back to true on mino dropped this.canPopFromHoldStack = false; // manipulation counter for srs extended piece lockdown @@ -349,14 +346,19 @@ Tetris.prototype = { if(besttime == "" || deltaTime/1000.0 < parseFloat(besttime)) { document.getElementById("besttime").value = (deltaTime/1000.0).toString(); } - this.isSequenceCompleted = true; - } + + } + this.hintQueue = []; this.shapeQueue = []; + this.isSequenceCompleted = true; // Recursion warning - this._restartHandler(); + this._restartHandler(); + // this.reset(); + // this.start(); + return; } } else { while(this.shapeQueue.length <= 4) @@ -419,21 +421,17 @@ Tetris.prototype = { }, + // tick input data -- wont have better than 4-15ms resolution since javascript is single theaded and any ARR or DAS below 15ms will likely be broken _processTick: async function() { - //var deltaTime = (new Date()).getTime() - this.eventTimer.getTime(); - //console.log("desync time: " + deltaTime); - - if(this.isTimerOn) { var deltaPlayTime = new Date().getTime() - this.sequencePrevTime; document.getElementById("Time").value = (deltaPlayTime/1000).toString(); } - // Don't process game related events if game over if(this.isGameOver) return; @@ -452,56 +450,52 @@ Tetris.prototype = { // drain gamepad queue // if( inputs.getTickCounter() > halfFrame) // 8 millisecons // { - while((inputs.gamepadQueue != undefined && inputs.gamepadQueue.length >= 1)){ - var curkey = inputs.gamepadQueue.shift(); - if(curkey == "DPad-Left") { - this.shape.goLeft(this.matrix); - this.resetLockdown(); - this._draw(); - } - if(curkey == "DPad-Right") { - this.shape.goRight(this.matrix); - this.resetLockdown(); - this._draw(); - } - if(curkey == "A") { - this.rotationCounter++; - this.shape.rotate(this.matrix); - this.resetLockdown(); - this._draw(); - } - if(curkey == "B") { - this.rotationCounter++; - this.shape.rotateClockwise(this.matrix); - this.resetLockdown(); - this._draw(); - } - if(curkey == "DPad-Down") { - this.shape.goDown(this.matrix); - this._draw(); - } - if(curkey == "RB") { - this.shape.goBottom(this.matrix); - this.lockDownTimer = 5000; - this._update(); - } - if(curkey == "LB") { - this.pushHoldStack(); - this._draw(); - } - if(curkey == "DPad-Up") { - this.popHoldStack(); - this._draw(); - } - if(curkey == "Back") { - this._restartHandler(); - return; - } + while((inputs.gamepadQueue != undefined && inputs.gamepadQueue.length >= 1)){ + var curkey = inputs.gamepadQueue.shift(); + if(inputs.settingsMap.get("Gamepad Left").includes(curkey)) { + this.shape.goLeft(this.matrix); + this.resetLockdown(); + this._draw(); } - - inputs.gamepadQueue = []; - // } - //inputs.gamepadButtonClear(); + else if(inputs.settingsMap.get("Gamepad Right").includes(curkey)) { + this.shape.goRight(this.matrix); + this.resetLockdown(); + this._draw(); + } + else if(inputs.settingsMap.get("Gamepad Rotateccw").includes(curkey)) { + this.shape.rotate(this.matrix); + this.resetLockdown(); + this._draw(); + } + else if(inputs.settingsMap.get("Gamepad Rotate").includes(curkey)) { + this.shape.rotateClockwise(this.matrix); + this.resetLockdown(); + this._draw(); + } + else if(inputs.settingsMap.get("Gamepad Down").includes(curkey)) { + this.shape.goDown(this.matrix); + this._draw(); + } + else if(inputs.settingsMap.get("Gamepad Harddrop").includes(curkey)) { + this.shape.goBottom(this.matrix); + this.lockDownTimer = 5000; + this._update(); + } + else if(inputs.settingsMap.get("Gamepad Hold").includes(curkey)) { + this.pushHoldStack(); + this._draw(); + } + else if(inputs.settingsMap.get("Gamepad Pophold").includes(curkey)) { + this.popHoldStack(); + this._draw(); + } + else if(inputs.settingsMap.get("Gamepad Reset").includes(curkey)) { + this._restartHandler(); + return; + } + } + inputs.saveButtons(); + inputs.gamepadClear(); } @@ -511,54 +505,51 @@ Tetris.prototype = { // Keyboard inputs while((inputs.inputQueue != undefined && inputs.inputQueue.length >= 1)){ var curkey = inputs.inputQueue.shift(); - if(curkey == 37) { - this.debugTimer = new Date(); + if(inputs.settingsMap.get("Keyboard Left").includes(curkey)) { this.shape.goLeft(this.matrix); this.resetLockdown(); this._draw(); } - if(curkey == 39){ + else if(inputs.settingsMap.get("Keyboard Right").includes(curkey)) { this.shape.goRight(this.matrix); this.resetLockdown(); this._draw(); } - if(curkey == 40) { + else if(inputs.settingsMap.get("Keyboard Down").includes(curkey)) { this.shape.goDown(this.matrix); this._draw(); } - if(curkey == 90) { - this.rotationCounter++; + else if(inputs.settingsMap.get("Keyboard Rotateccw").includes(curkey)) { this.shape.rotate(this.matrix); this.resetLockdown(); this._draw(); } - if(curkey == 88){ - this.rotationCounter++; + else if(inputs.settingsMap.get("Keyboard Rotate").includes(curkey)) { this.shape.rotateClockwise(this.matrix); this.resetLockdown(); this._draw(); } - if(curkey == 32) { + else if(inputs.settingsMap.get("Keyboard Harddrop").includes(curkey)) { this.shape.goBottom(this.matrix); this.lockDownTimer = 5000; this._update(); } - if(curkey == 16) { + else if(inputs.settingsMap.get("Keyboard Hold").includes(curkey)) { this.pushHoldStack(); this._draw(); } - if(curkey == 17 || curkey == 67) { + else if(inputs.settingsMap.get("Keyboard Pophold").includes(curkey)) { this.popHoldStack(); this._draw(); } - if(curkey == 81) { + else if(inputs.settingsMap.get("Keyboard Hold").includes(curkey)) { if(document.getElementById("divbg").style.display == "none") document.getElementById("divbg").style.display = "initial"; else document.getElementById("divbg").style.display="none"; } - if(curkey == 82) { + if(inputs.settingsMap.get("Keyboard Reset").includes(curkey)) { this._restartHandler(); return; } @@ -694,7 +685,8 @@ Tetris.prototype = { views.setLevel(this.level); this.levelTime = currentTime; } - } + }, + } diff --git a/src/openers.js b/src/openers.js index af1eaf6..2ace6ff 100644 --- a/src/openers.js +++ b/src/openers.js @@ -143,6 +143,17 @@ var openerGenerator = { shapes.getShape(2), shapes.getShape(5), shapes.getShape(3)); + break; + case 9: + // Pelican + this.shapeQueue = new Array( + shapes.getShape(5), + shapes.getShape(2), + shapes.getShape(4), + shapes.getShape(0), + shapes.getShape(6), + shapes.getShape(1), + shapes.getShape(3)); break; default: return; @@ -171,6 +182,8 @@ var openerGenerator = { switch(opener) { case 0: + this.hintQueue = []; + break; case 1: // Fonzie Variation this.hintQueue = new Array( @@ -370,6 +383,25 @@ var openerGenerator = { this.hintQueue[i].state = this.hintQueue[i].nextState(hintDataList[i * 3 + 2]); } break; + case 9: + // Pelican + this.hintQueue = new Array( + shapes.getShape(5), + shapes.getShape(2), + shapes.getShape(4), + shapes.getShape(0), + shapes.getShape(6), + shapes.getShape(1), + shapes.getShape(3)); + + var hintDataList = [0,17,-1, 1,16,2, 5,18,0, 5,16,-1, 8,16,-1, 5,17,0, 3,16,2]; + + for(var i = 0; i < this.hintQueue.length; i++) { + this.hintQueue[i].x = hintDataList[i * 3]; + this.hintQueue[i].y = hintDataList[i * 3 + 1]; + this.hintQueue[i].state = this.hintQueue[i].nextState(hintDataList[i * 3 + 2]); + } + break; default: return; } diff --git a/src/sequence.js b/src/sequence.js index 484d8c3..fae5c98 100644 --- a/src/sequence.js +++ b/src/sequence.js @@ -46,6 +46,7 @@ var sequence = { }; +/* var sequences = { this.sequenceList = []; this.currentMino = []; @@ -63,6 +64,7 @@ var sequences = { sequenceList = []; } }; +*/ function getNextMino() { currentSequence.popMino();