something

This commit is contained in:
PolicyChanges1@gmail.com 2021-03-01 14:41:00 -05:00
parent f08a95e9aa
commit 8bc073f84a
7 changed files with 344 additions and 236 deletions

View File

@ -162,7 +162,8 @@ body{
-webkit-animation-name: fadeOutUp;
animation-name: fadeOutUp;
}
#bg {
#bg {
-webkit-filter: blur(3px);
filter: blur(3px);
}
filter: blur(0px);
}

239
dist/tetrion.js vendored
View File

@ -428,6 +428,8 @@ var utils = require('./utils.js');
var UserInputs = {
init() {
this.dt = 0;
this.debugTimer = new Date();
this.settingsMap = new Map();
// var init = utils.getCookie("init");
@ -448,12 +450,16 @@ var UserInputs = {
updateGamepad() {
this.gpButtons = gamepad.update();
},
gamepadEnabled() {
return gamepad.controller || false;
},
incDeciframes() {
this.keyboardButtonsDeciframes++;
this.keyboardDirectionArrowsDeciframes++;
this.gamepadButtonsDeciFrames++;
this.gamepadDirectionPadDeciFrames++;
},
incTickCounter() {
this.ticks++;
@ -565,13 +571,13 @@ var UserInputs = {
var deciDAS = 50.0;
var deciARR = 50.0;
// todo: fix this mess
if(this.prevKeyboardKeys[key] != this.keyboardKeys[key] && this.isKeyBoardKeyDown == true) {
this.isKeyboardKeyDown = false;
if(this.keyboardKeys[key] == true)
this.inputqueue.push(key);
this.keyboardKeys[key] = false;
this.inputQueue.push(key);
//this.keyboardKeys[key] = false;
}
var keyboardDASFrames = this.keyboardButtonsDeciframes;
@ -583,7 +589,7 @@ var UserInputs = {
}
} else {
if (keyboardDASFrames >= deciARR && this.keyboardKeys[key] == true) {
//this.inputqueue.push(key);
//this.inputQueue.push(key);
this.keyboardButtonsDeciframes = 0;
}
}
@ -602,31 +608,27 @@ var UserInputs = {
var DAS = parseInt(this.settingsMap.get("Keyboard DAS")); //65.0;
var ARR = parseInt(this.settingsMap.get("Keyboard ARR")); //20.0;
if(key == 75)
console.log("keyboard key: " + key);
if(this.prevKeyboardKeys[key] != this.keyboardKeys[key]) {
this.isDirectionArrowDown = false;
// Not being held yet
this.isPassedDelay = false;
if(this.keyboardKeys[key] == true)
this.inputqueue.push(key);
this.inputQueue.push(key);
}
var keyboardDASFrames = this.keyboardDirectionArrowsDeciframes;
if (!this.isDirectionArrowDown) {
if (!this.isPassedDelay) {
if (keyboardDASFrames >= DAS) {
this.keyboardDirectionArrowsDeciframes = 0;
this.isDirectionArrowDown = true;
this.isPassedDelay = true;
}
} else {
if (keyboardDASFrames >= ARR && this.keyboardKeys[key] == true) {
this.inputqueue.push(key);
}
else if(keyboardDASFrames >= ARR && this.keyboardKeys[key] == true) {
this.inputQueue.push(key);
this.keyboardDirectionArrowsDeciframes = 0;
}
}
//}
}
},
keyDown(event) {
@ -651,10 +653,11 @@ var UserInputs = {
this.prevGpButtons = this.gpButtons;
},
saveKeyboardKeys() {
//this.prevKeyboardKeys = utils.deepClone(this.keyboardKeys);
this.prevKeyboardKeys = {...this.keyboardKeys};
},
// button states
isDirectionArrowDown: false,
isPassedDelay: false,
isKeyboardKeyDown: false,
isGamepadDown: false,
isGamepadButtonDown: false,
@ -672,7 +675,7 @@ var UserInputs = {
prevKeyboardKeys: [],
// button pressed containers
inputqueue: [],
inputQueue: [],
gamepadQueue: [],
ticks: 0,
@ -853,6 +856,8 @@ Tetris.prototype = {
init: function(options) {
// this gameStates = {"
// this.state =
var cfg = this.config = utils.extend(options, defaults);
this.interval = consts.DEFAULT_INTERVAL;
@ -867,7 +872,9 @@ Tetris.prototype = {
this.currentOpener = 0;
this.doTest = false;
this.matrix = initMatrix(consts.ROW_COUNT, consts.COLUMN_COUNT);
this.eventTimer = new Date();
this.debugTimer = new Date();
this.gamepadEnabled = false;
this.reset();
this._initEvents();
@ -877,6 +884,9 @@ Tetris.prototype = {
toggleTimer: function() {
document.getElementById("Timer").value = (this.isTimerOn = !this.isTimerOn) ? "Seconds:" : "Timer Off";
},
toggleGamepad: function(){
document.getElementById("gamepad").value = (this.gamepadEnabled = !this.gamepadEnabled) ? "Disable Gamepad" : "Enable Gamepad";
},
setFreePlay: function()
{
document.getElementById("Timer").value = "Timer Off";
@ -919,9 +929,13 @@ Tetris.prototype = {
list.add(option);
});
},
},
updateSettingTextBox: function() {
console.log(document.getElementById("setting_value").value = inputs.settingsDefault[document.getElementById("settings").selectedIndex-1]);
document.getElementById("setting_value").value =
inputs.settingsMap.get(inputs.settingsList[document.getElementById("settings").selectedIndex-1]);
//inputs.settingsDefault[document.getElementById("settings").selectedIndex-1];
},
setSettings: function() {
var newVal = document.getElementById("setting_value").value;
@ -931,6 +945,7 @@ Tetris.prototype = {
},
//Reset game
reset: function() {
this.numlefts = 0;
this.running = false;
this.isGameOver = false;
this.level = 1;
@ -1111,23 +1126,25 @@ Tetris.prototype = {
},
// tick input data
// tick input data -- wont have better than 4-15ms resolution since javascript is single theaded
_processTick: async function() {
var deltaTime = 1.0; // 1 millisecond
var tenthOfFrame = 1.0 //1.6; // 1.6ms = 1 fram
var halfFrame = 5.0 //8.0;
var halfFramePlus = 10.0;
//var deltaTime = (new Date()).getTime() - this.eventTimer.getTime();
//console.log("desync time: " + deltaTime);
inputs.incDeciframes();
inputs.incTickCounter();
if(inputs.getTickCounter() >= tenthOfFrame) {
inputs.updateGamepad();
inputs.processGamepadDPad();
inputs.processGamepadInput();
if(this.isTimerOn) {
var deltaPlayTime = new Date().getTime() - this.sequencePrevTime;
if(inputs.getTickCounter() >= 20) { // Set html element at a reasonble rate
document.getElementById("Time").value = (deltaPlayTime/1000).toString();
}
}
@ -1135,80 +1152,82 @@ Tetris.prototype = {
if(this.isGameOver) return;
if(this.isTimerOn) {
var deltaPlayTime = new Date().getTime() - this.sequencePrevTime;
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;
if(inputs.getTickCounter() >= 20) {
document.getElementById("Time").value = (deltaPlayTime/1000).toString();
if(inputs.getTickCounter() >= tenthOfFrame) {
inputs.updateGamepad();
inputs.processGamepadDPad();
inputs.processGamepadInput();
}
}
// 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;
// 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;
}
}
inputs.gamepadQueue = [];
}
inputs.gamepadQueue = [];
//inputs.gamepadButtonClear();
}
//inputs.gamepadButtonClear();
// Do keyboard
if(inputs.getTickCounter() > tenthOfFrame) // 120hz
{
inputs.processKeys();
}
inputs.processKeys();
if (inputs.getTickCounter() > tenthOfFrame) { // 60hz
inputs.processKeyShift();
// Keyboard inputs
while((inputs.inputqueue != undefined && inputs.inputqueue.length >= 1)){
var curkey = inputs.inputqueue.shift();
while((inputs.inputQueue != undefined && inputs.inputQueue.length >= 1)){
var curkey = inputs.inputQueue.shift();
if(curkey == 37) {
this.debugTimer = new Date();
this.shape.goLeft(this.matrix);
this.resetLockdown();
this._draw();
@ -1219,6 +1238,7 @@ Tetris.prototype = {
this._draw();
}
if(curkey == 40) {
this.shape.goDown(this.matrix);
this._draw();
}
@ -1259,15 +1279,12 @@ Tetris.prototype = {
}
}
inputs.inputqueue = [];
}
inputs.inputQueue = [];
if(inputs.getTickCounter() >= halfFramePlus)
inputs.saveKeyboardKeys();
if(inputs.getTickCounter() >= tenthOfFrame)
inputs.saveButtons();
},
// Refresh game canvas
_refresh: function() {
@ -1293,7 +1310,7 @@ Tetris.prototype = {
return;
if(!this.shape.isSameSRS(this.hintMino))
{
new Audio('./dist/Failed.ogg').play();
//new Audio('./dist/Failed.ogg').play();
this._restartHandler();
// Restart
return 1;
@ -1404,7 +1421,7 @@ var shapes = require("./shapes.js");
// https://harddrop.com/wiki/Opener
// https://four.lol/
var OpenerGenerator = {
var openerGenerator = {
shapeQueue: [],
hintQueue: [],
idx: 0,
@ -1808,19 +1825,19 @@ var OpenerGenerator = {
};
function reset() {
OpenerGenerator.reset();
openerGenerator.reset();
}
function getNextMino(opener) {
var mino = OpenerGenerator.getNextMino(opener);
var mino = openerGenerator.getNextMino(opener);
return mino;
}
function getNextHint(opener) {
var mino = OpenerGenerator.getNextHint(opener);
var mino = openerGenerator.getNextHint(opener);
return mino;
}
function getLength() {
return OpenerGenerator.getLength();
return openerGenerator.getLength();
}
module.exports.getNextMino = getNextMino;
module.exports.getNextHint = getNextHint;

View File

@ -46,9 +46,9 @@
<!-- <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/WldfWX?gui=&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="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/MlSSRt?gui=&paused=false&muted=false" allowfullscreen></iframe> -->
<script>
document.getElementById("bg").width = window.innerWidth;
document.getElementById("bg").height = window.innerHeight;
@ -125,11 +125,11 @@ document.getElementById("divbg").removeAttribute("tabIndex");
<canvas style="border: 1px solid DarkGrey;" id="hold"></canvas>
<br>
<br>
<input style="padding:1px;text-decoration:underline;overflow:visible;font-size:12px;background:rgba(40,40,40,.80);color:dodgerblue;border:1px solid DarkGrey;text-align:left;" type="button" id="Timer" value="Timer Off"/>
<input disabled=true style="padding:1px;overflow:visible;width:80px;font-size:12px;background:rgba(40,40,40,.80);color:dodgerblue;border:1px solid DarkGrey;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,.80);color:dodgerblue;border:1px solid DarkGrey;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,.80);color:dodgerblue;border:1px solid DarkGrey;text-align:left;" type="text" id="Time" value=""/>
<input disabled=true style="overflow:visible;width:40%;font-size:12px;background:rgba(40,40,40,.80);color:dodgerblue;border:1px solid DarkGrey;text-align:left;" type="text" id="besttimetext" value="Best Time:"/>
<input disabled=true style="overflow:visible;width:80px;font-size:12px;background:rgba(40,40,40,.80);color:dodgerblue;border:1px solid DarkGrey;text-align:left;" type="text" id="besttime" value=""/>
<input disabled=true style="overflow:visible;width:63px;font-size:12px;background:rgba(40,40,40,.80);color:dodgerblue;border:1px solid DarkGrey;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,.80);color:dodgerblue;border:1px solid DarkGrey;text-align:left;" type="text" id="besttime" value=""/>
</div>
<div id="gameOver">
@ -149,14 +149,16 @@ document.getElementById("divbg").removeAttribute("tabIndex");
<br>
<select style="width:80px;font-size:13px;background:rgba(40,40,40,.80);color:dodgerblue;border: 1px solid DarkGrey;text-align:left;" id="settings" name="setting">
<option selected="">Settings:</option>
</select>
<input style="width:80px;font-size:13px;background:rgba(40,40,40,.80);color:dodgerblue;border:1px solid DarkGrey;text-align:left;" type="text" id="setting_value">
<input style="width:80px;font-size:12px;background:rgba(40,40,40,.80);color:dodgerblue;border:1px solid DarkGrey;" id="submitsetting" type="submit" value="Set Setting"></input>
<input style="width:80px;font-size:12px;background:rgba(40,40,40,.80);color:dodgerblue;border:1px solid DarkGrey;" id="test" type="submit" value="Test Yourself"></input>
<input style="width:50px;font-size:13px;background:rgba(40,40,40,.80);color:dodgerblue;border:1px solid DarkGrey;text-align:left;" type="text" id="setting_value">
<input style="width:45px;font-size:12px;background:rgba(40,40,40,.80);color:dodgerblue;border:1px solid DarkGrey;text-align:left;" id="submitsetting" type="submit" value="Set"></input>
<br>
<input style="width:70px;font-size:12px;background:rgba(40,40,40,.80);color:dodgerblue;border:1px solid DarkGrey;text-align:left;" id="test" type="submit" value="Hide Hints"></input>
<input style="width:110px;font-size:12px;background:rgba(40,40,40,.80);color:dodgerblue;border:1px solid DarkGrey;text-align:left;" id="enablegamepad" type="submit" value="Enable Gamepad"></input>
</div>
</div>
</div>
@ -176,6 +178,8 @@ document.getElementById("divbg").removeAttribute("tabIndex");
document.getElementById("setAlbatrossVar").addEventListener("click", function() { tetrion.setCurrentOpener(7); } );
document.getElementById("setNumberOneVar").addEventListener("click", function() { tetrion.setCurrentOpener(8); } );
document.getElementById("enablegamepad").addEventListener("click", function() { tetrion.toggleGamepad(); } );
document.getElementById("Timer").addEventListener("click", function() { tetrion.toggleTimer(); } );
document.getElementById("test").addEventListener("click", function() { tetrion.setDoTest(); } );

View File

@ -4,6 +4,8 @@ var utils = require('./utils.js');
var UserInputs = {
init() {
this.dt = 0;
this.debugTimer = new Date();
this.settingsMap = new Map();
// var init = utils.getCookie("init");
@ -24,12 +26,16 @@ var UserInputs = {
updateGamepad() {
this.gpButtons = gamepad.update();
},
gamepadEnabled() {
return gamepad.controller || false;
},
incDeciframes() {
this.keyboardButtonsDeciframes++;
this.keyboardDirectionArrowsDeciframes++;
this.gamepadButtonsDeciFrames++;
this.gamepadDirectionPadDeciFrames++;
},
incTickCounter() {
this.ticks++;
@ -141,13 +147,13 @@ var UserInputs = {
var deciDAS = 50.0;
var deciARR = 50.0;
// todo: fix this mess
if(this.prevKeyboardKeys[key] != this.keyboardKeys[key] && this.isKeyBoardKeyDown == true) {
this.isKeyboardKeyDown = false;
if(this.keyboardKeys[key] == true)
this.inputqueue.push(key);
this.keyboardKeys[key] = false;
this.inputQueue.push(key);
//this.keyboardKeys[key] = false;
}
var keyboardDASFrames = this.keyboardButtonsDeciframes;
@ -159,7 +165,7 @@ var UserInputs = {
}
} else {
if (keyboardDASFrames >= deciARR && this.keyboardKeys[key] == true) {
//this.inputqueue.push(key);
//this.inputQueue.push(key);
this.keyboardButtonsDeciframes = 0;
}
}
@ -178,31 +184,27 @@ var UserInputs = {
var DAS = parseInt(this.settingsMap.get("Keyboard DAS")); //65.0;
var ARR = parseInt(this.settingsMap.get("Keyboard ARR")); //20.0;
if(key == 75)
console.log("keyboard key: " + key);
if(this.prevKeyboardKeys[key] != this.keyboardKeys[key]) {
this.isDirectionArrowDown = false;
// Not being held yet
this.isPassedDelay = false;
if(this.keyboardKeys[key] == true)
this.inputqueue.push(key);
this.inputQueue.push(key);
}
var keyboardDASFrames = this.keyboardDirectionArrowsDeciframes;
if (!this.isDirectionArrowDown) {
if (!this.isPassedDelay) {
if (keyboardDASFrames >= DAS) {
this.keyboardDirectionArrowsDeciframes = 0;
this.isDirectionArrowDown = true;
this.isPassedDelay = true;
}
} else {
if (keyboardDASFrames >= ARR && this.keyboardKeys[key] == true) {
this.inputqueue.push(key);
}
else if(keyboardDASFrames >= ARR && this.keyboardKeys[key] == true) {
this.inputQueue.push(key);
this.keyboardDirectionArrowsDeciframes = 0;
}
}
//}
}
},
keyDown(event) {
@ -227,10 +229,11 @@ var UserInputs = {
this.prevGpButtons = this.gpButtons;
},
saveKeyboardKeys() {
//this.prevKeyboardKeys = utils.deepClone(this.keyboardKeys);
this.prevKeyboardKeys = {...this.keyboardKeys};
},
// button states
isDirectionArrowDown: false,
isPassedDelay: false,
isKeyboardKeyDown: false,
isGamepadDown: false,
isGamepadButtonDown: false,
@ -248,7 +251,7 @@ var UserInputs = {
prevKeyboardKeys: [],
// button pressed containers
inputqueue: [],
inputQueue: [],
gamepadQueue: [],
ticks: 0,

View File

@ -149,6 +149,8 @@ Tetris.prototype = {
init: function(options) {
// this gameStates = {"
// this.state =
var cfg = this.config = utils.extend(options, defaults);
this.interval = consts.DEFAULT_INTERVAL;
@ -163,7 +165,9 @@ Tetris.prototype = {
this.currentOpener = 0;
this.doTest = false;
this.matrix = initMatrix(consts.ROW_COUNT, consts.COLUMN_COUNT);
this.eventTimer = new Date();
this.debugTimer = new Date();
this.gamepadEnabled = false;
this.reset();
this._initEvents();
@ -173,6 +177,9 @@ Tetris.prototype = {
toggleTimer: function() {
document.getElementById("Timer").value = (this.isTimerOn = !this.isTimerOn) ? "Seconds:" : "Timer Off";
},
toggleGamepad: function(){
document.getElementById("gamepad").value = (this.gamepadEnabled = !this.gamepadEnabled) ? "Disable Gamepad" : "Enable Gamepad";
},
setFreePlay: function()
{
document.getElementById("Timer").value = "Timer Off";
@ -215,9 +222,13 @@ Tetris.prototype = {
list.add(option);
});
},
},
updateSettingTextBox: function() {
console.log(document.getElementById("setting_value").value = inputs.settingsDefault[document.getElementById("settings").selectedIndex-1]);
document.getElementById("setting_value").value =
inputs.settingsMap.get(inputs.settingsList[document.getElementById("settings").selectedIndex-1]);
//inputs.settingsDefault[document.getElementById("settings").selectedIndex-1];
},
setSettings: function() {
var newVal = document.getElementById("setting_value").value;
@ -227,6 +238,7 @@ Tetris.prototype = {
},
//Reset game
reset: function() {
this.numlefts = 0;
this.running = false;
this.isGameOver = false;
this.level = 1;
@ -407,23 +419,25 @@ Tetris.prototype = {
},
// tick input data
// tick input data -- wont have better than 4-15ms resolution since javascript is single theaded
_processTick: async function() {
var deltaTime = 1.0; // 1 millisecond
var tenthOfFrame = 1.0 //1.6; // 1.6ms = 1 fram
var halfFrame = 5.0 //8.0;
var halfFramePlus = 10.0;
//var deltaTime = (new Date()).getTime() - this.eventTimer.getTime();
//console.log("desync time: " + deltaTime);
inputs.incDeciframes();
inputs.incTickCounter();
if(inputs.getTickCounter() >= tenthOfFrame) {
inputs.updateGamepad();
inputs.processGamepadDPad();
inputs.processGamepadInput();
if(this.isTimerOn) {
var deltaPlayTime = new Date().getTime() - this.sequencePrevTime;
if(inputs.getTickCounter() >= 20) { // Set html element at a reasonble rate
document.getElementById("Time").value = (deltaPlayTime/1000).toString();
}
}
@ -431,80 +445,82 @@ Tetris.prototype = {
if(this.isGameOver) return;
if(this.isTimerOn) {
var deltaPlayTime = new Date().getTime() - this.sequencePrevTime;
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;
if(inputs.getTickCounter() >= 20) {
document.getElementById("Time").value = (deltaPlayTime/1000).toString();
if(inputs.getTickCounter() >= tenthOfFrame) {
inputs.updateGamepad();
inputs.processGamepadDPad();
inputs.processGamepadInput();
}
}
// 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;
// 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;
}
}
inputs.gamepadQueue = [];
}
inputs.gamepadQueue = [];
//inputs.gamepadButtonClear();
}
//inputs.gamepadButtonClear();
// Do keyboard
if(inputs.getTickCounter() > tenthOfFrame) // 120hz
{
inputs.processKeys();
}
inputs.processKeys();
if (inputs.getTickCounter() > tenthOfFrame) { // 60hz
inputs.processKeyShift();
// Keyboard inputs
while((inputs.inputqueue != undefined && inputs.inputqueue.length >= 1)){
var curkey = inputs.inputqueue.shift();
while((inputs.inputQueue != undefined && inputs.inputQueue.length >= 1)){
var curkey = inputs.inputQueue.shift();
if(curkey == 37) {
this.debugTimer = new Date();
this.shape.goLeft(this.matrix);
this.resetLockdown();
this._draw();
@ -515,6 +531,7 @@ Tetris.prototype = {
this._draw();
}
if(curkey == 40) {
this.shape.goDown(this.matrix);
this._draw();
}
@ -555,15 +572,12 @@ Tetris.prototype = {
}
}
inputs.inputqueue = [];
}
inputs.inputQueue = [];
if(inputs.getTickCounter() >= halfFramePlus)
inputs.saveKeyboardKeys();
if(inputs.getTickCounter() >= tenthOfFrame)
inputs.saveButtons();
},
// Refresh game canvas
_refresh: function() {
@ -589,7 +603,7 @@ Tetris.prototype = {
return;
if(!this.shape.isSameSRS(this.hintMino))
{
new Audio('./dist/Failed.ogg').play();
//new Audio('./dist/Failed.ogg').play();
this._restartHandler();
// Restart
return 1;

View File

@ -3,7 +3,7 @@ var shapes = require("./shapes.js");
// https://harddrop.com/wiki/Opener
// https://four.lol/
var OpenerGenerator = {
var openerGenerator = {
shapeQueue: [],
hintQueue: [],
idx: 0,
@ -407,19 +407,19 @@ var OpenerGenerator = {
};
function reset() {
OpenerGenerator.reset();
openerGenerator.reset();
}
function getNextMino(opener) {
var mino = OpenerGenerator.getNextMino(opener);
var mino = openerGenerator.getNextMino(opener);
return mino;
}
function getNextHint(opener) {
var mino = OpenerGenerator.getNextHint(opener);
var mino = openerGenerator.getNextHint(opener);
return mino;
}
function getLength() {
return OpenerGenerator.getLength();
return openerGenerator.getLength();
}
module.exports.getNextMino = getNextMino;
module.exports.getNextHint = getNextHint;

69
src/sequence.js Normal file
View File

@ -0,0 +1,69 @@
var consts = require('./consts.ds');
var utils = require('./utils.js');
var utils. = requre('./shapes.js');
var initMatrix = function(rowCount, columnCount) {
var result = [];
for (var i = 0; i < rowCount; i++) {
var row = [];
result.push(row);
for (var j = 0; j < columnCount; j++) {
row.push(0);
}
}
return result;
};
var sequence = {
this.matrix = initMatrix(consts.ROW_COUNT, consts.COLUMN_COUNT);
this.minoList = [];
this.currentMino = [];
addMino: function(mino) {
this.minoList.push (mino)
this.updateMatrix();
},
//Copy the shape data to the game data
copyTo: function(matrix) {
var smatrix = this.matrix();
for (var i = 0; i < smatrix.length; i++) {
var row = smatrix[i];
for (var j = 0; j < row.length; j++) {
if (row[j] === 1) {
var x = this.x + j;
var y = this.y + i;
if (x >= 0 && x < matrix[0].length && y >= 0 && y < matrix.length) {
matrix[y][x] = this.color;
}
}
}
}
},
};
var sequences = {
this.sequenceList = [];
this.currentMino = [];
init(setSequenceList){
this.sequnceList = setSequenceList;
},
addNewSequence: function(newsequence) {
this.sequenceList.push(newsequence);
},
addMinoToCurrentSequence: function(mino) {
this.currentSequnce.addMino(mino);
},
reset: function() {
sequenceList = [];
}
};
function getNextMino() {
currentSequence.popMino();
};