odds and ends

pull/1/head
PolicyChanges1@gmail.com 2021-03-08 15:52:04 -05:00
parent 1cccd4adf5
commit f1b4d94dc7
7 changed files with 310 additions and 293 deletions

View File

@ -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);
}

274
dist/tetrion.js vendored
View File

@ -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;
}

View File

@ -39,28 +39,28 @@
<div id="divbg">
<!-- <iframe id="bg" width="640" height="360" frameborder="0" src="https://www.shadertoy.com/embed/4lBGDh?gui=true&t=10&paused=true&muted=false" allowfullscreen></iframe> -->
<!-- <iframe width="640" height="360" frameborder="0" src="https://www.shadertoy.com/embed/3tXBWj?gui=true&t=10&paused=true&muted=false" allowfullscreen></iframe> -->
<!-- <iframe id="bg" width="640" height="360" frameborder="0" src="https://www.shadertoy.com/embed/Xlf3Rj?gui=true&t=10&paused=false&muted=false" allowfullscreen></iframe> -->
<!-- <iframe id="bg" width="640" height="360" frameborder="0" src="https://www.shadertoy.com/embed/tdjyzz?gui=true&t=10&paused=false&muted=false" allowfullscreen></iframe> -->
<!-- <iframe id="bg" width="640" height="360" frameborder="0" src="https://www.shadertoy.com/embed/3lVfDm?gui=true&t=10&paused=true&muted=false" allowfullscreen></iframe> -->
<iframe id="bg" width="640" height="360" frameborder="0" src="https://www.shadertoy.com/embed/WldfWX?gui=&paused=false&muted=false" ></iframe>
<!-- <iframe id="bg" width="640" height="360" frameborder="0" src="https://www.shadertoy.com/embed/MlSSRt?gui=&paused=false&muted=false" allowfullscreen></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>
<script>
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").style.webkitFilter = "blur(4px)";
}
else
document.getElementById("bg").src="https://www.shadertoy.com/embed/WldfWX?gui=&paused=false&muted=false";
document.getElementById("bg").width = window.innerWidth;
document.getElementById("bg").height = window.innerHeight;
document.getElementById("bg").removeAttribute("tabIndex");
document.getElementById("divbg").removeAttribute("tabIndex");
</script>
@ -124,7 +124,6 @@ document.getElementById("divbg").removeAttribute("tabIndex");
<li style="font-size:12px;padding-left:1em;"><a href="#" id="setLnJVar">Neither L nor J </a></li>
<li style="font-size:12px;padding-left:1em;"><a href="#" id="setLaJVar">Both L and J </a></li>
<li style="font-size:12px;padding-left:1em;"><a href="#" id="setPCTPieceVar">T piece </a></li>
<li style="font-size:12px;padding-left:1em;"><a href="#" id="setSAVar">see also </a></li>
</ul>
</ul>
</ul>
@ -133,11 +132,11 @@ document.getElementById("divbg").removeAttribute("tabIndex");
<canvas style="border: 1px solid #6666;" id="hold"></canvas>
<br>
<br>
<input style="padding-left:12px;text-decoration:underline;overflow:visible;font-size:12px;background:rgba(40,40,40,0);color:dodgerblue;border:1px solid #6666;text-align:left;" type="button" id="Timer" value="Timer Off"/>
<input disabled=true style="padding:1px;overflow:visible;width:70px;font-size:12px;background:rgba(40,40,40,0);color:dodgerblue;border:1px solid #6666;text-align:left;" type="text" id="Time" value=""/>
<input style="padding-left:12px;text-decoration:underline;overflow:visible;font-size:12px;background:rgba(40,40,40,.5);color:powderblue;border:1px solid #6666;text-align:left;" type="button" id="Timer" value="Timer Off"/>
<input disabled=true style="padding:1px;overflow:visible;width:70px;font-size:12px;background:rgba(40,40,40,.5);color:dodgerblue;border:1px solid #6666;text-align:left;" type="text" id="Time" value=""/>
<input disabled=true style="overflow:visible;width:63px;font-size:12px;background:rgba(40,40,40,0);color:dodgerblue;border:1px solid #6666;text-align:left;" type="text" id="besttimetext" value="Best Time:"/>
<input disabled=true style="overflow:visible;width:68px;font-size:12px;background:rgba(40,40,40,0);color:dodgerblue;border:1px solid #6666;text-align:left;" type="text" id="besttime" value=""/>
<input disabled=true style="overflow:visible;width:63px;font-size:12px;background:rgba(40,40,40,.5);color:dodgerblue;border:1px solid #6666;text-align:left;" type="text" id="besttimetext" value="Best Time:"/>
<input disabled=true style="overflow:visible;width:68px;font-size:12px;background:rgba(40,40,40,.5);color:dodgerblue;border:1px solid #6666;text-align:left;" type="text" id="besttime" value=""/>
</div>
<div id="gameOver">
@ -155,14 +154,14 @@ document.getElementById("divbg").removeAttribute("tabIndex");
<canvas style="border: 1px solid #6666;" id="preview"></canvas>
<br>
<select style="width:80px;font-size:13px;background:rgba(40,40,40,0);color:dodgerblue;border: 1px solid #6666;text-align:left;" id="settings" name="setting">
<select style="width:80px;font-size:13px;background:rgba(40,40,40,.5);color:dodgerblue;border: 1px solid #6666;text-align:left;" id="settings" name="setting">
<option selected="">Settings:</option>
</select>
<input style="width:50px;font-size:13px;background:rgba(40,40,40,0);color:dodgerblue;border:1px solid #6666;text-align:left;" type="text" id="setting_value">
<input style="width:45px;font-size:12px;background:rgba(40,40,40,0);color:dodgerblue;border:1px solid #6666;text-align:left;" id="submitsetting" type="submit" value="Set"></input>
<input style="width:50px;font-size:13px;background:rgba(40,40,40,.5);color:dodgerblue;border:1px solid #6666;text-align:left;" type="text" id="setting_value">
<input style="width:45px;font-size:12px;background:rgba(40,40,40,.5);color:dodgerblue;border:1px solid #6666;text-align:left;" id="submitsetting" type="submit" value="Set"></input>
<br>
<input style="width:70px;font-size:12px;background:rgba(40,40,40,0);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,0);color:dodgerblue;border:1px solid #6666;text-align:left;" id="enablegamepad" type="button" value="Enable Gamepad"/>
<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"/>
</div>
@ -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();
})();
</script>

View File

@ -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: []
};

View File

@ -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;
}
}
},
}

View File

@ -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;
}

View File

@ -46,6 +46,7 @@ var sequence = {
};
/*
var sequences = {
this.sequenceList = [];
this.currentMino = [];
@ -63,6 +64,7 @@ var sequences = {
sequenceList = [];
}
};
*/
function getNextMino() {
currentSequence.popMino();