something
This commit is contained in:
parent
f08a95e9aa
commit
8bc073f84a
@ -162,7 +162,8 @@ body{
|
|||||||
-webkit-animation-name: fadeOutUp;
|
-webkit-animation-name: fadeOutUp;
|
||||||
animation-name: fadeOutUp;
|
animation-name: fadeOutUp;
|
||||||
}
|
}
|
||||||
#bg {
|
|
||||||
|
#bg {
|
||||||
-webkit-filter: blur(3px);
|
-webkit-filter: blur(3px);
|
||||||
filter: blur(3px);
|
filter: blur(0px);
|
||||||
}
|
}
|
239
dist/tetrion.js
vendored
239
dist/tetrion.js
vendored
@ -428,6 +428,8 @@ var utils = require('./utils.js');
|
|||||||
|
|
||||||
var UserInputs = {
|
var UserInputs = {
|
||||||
init() {
|
init() {
|
||||||
|
this.dt = 0;
|
||||||
|
this.debugTimer = new Date();
|
||||||
this.settingsMap = new Map();
|
this.settingsMap = new Map();
|
||||||
|
|
||||||
// var init = utils.getCookie("init");
|
// var init = utils.getCookie("init");
|
||||||
@ -448,12 +450,16 @@ var UserInputs = {
|
|||||||
updateGamepad() {
|
updateGamepad() {
|
||||||
this.gpButtons = gamepad.update();
|
this.gpButtons = gamepad.update();
|
||||||
},
|
},
|
||||||
|
gamepadEnabled() {
|
||||||
|
return gamepad.controller || false;
|
||||||
|
},
|
||||||
incDeciframes() {
|
incDeciframes() {
|
||||||
this.keyboardButtonsDeciframes++;
|
this.keyboardButtonsDeciframes++;
|
||||||
this.keyboardDirectionArrowsDeciframes++;
|
this.keyboardDirectionArrowsDeciframes++;
|
||||||
this.gamepadButtonsDeciFrames++;
|
this.gamepadButtonsDeciFrames++;
|
||||||
this.gamepadDirectionPadDeciFrames++;
|
this.gamepadDirectionPadDeciFrames++;
|
||||||
|
|
||||||
|
|
||||||
},
|
},
|
||||||
incTickCounter() {
|
incTickCounter() {
|
||||||
this.ticks++;
|
this.ticks++;
|
||||||
@ -565,13 +571,13 @@ var UserInputs = {
|
|||||||
var deciDAS = 50.0;
|
var deciDAS = 50.0;
|
||||||
var deciARR = 50.0;
|
var deciARR = 50.0;
|
||||||
|
|
||||||
|
|
||||||
// todo: fix this mess
|
// todo: fix this mess
|
||||||
if(this.prevKeyboardKeys[key] != this.keyboardKeys[key] && this.isKeyBoardKeyDown == true) {
|
if(this.prevKeyboardKeys[key] != this.keyboardKeys[key] && this.isKeyBoardKeyDown == true) {
|
||||||
|
|
||||||
this.isKeyboardKeyDown = false;
|
this.isKeyboardKeyDown = false;
|
||||||
if(this.keyboardKeys[key] == true)
|
if(this.keyboardKeys[key] == true)
|
||||||
this.inputqueue.push(key);
|
this.inputQueue.push(key);
|
||||||
this.keyboardKeys[key] = false;
|
//this.keyboardKeys[key] = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
var keyboardDASFrames = this.keyboardButtonsDeciframes;
|
var keyboardDASFrames = this.keyboardButtonsDeciframes;
|
||||||
@ -583,7 +589,7 @@ var UserInputs = {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (keyboardDASFrames >= deciARR && this.keyboardKeys[key] == true) {
|
if (keyboardDASFrames >= deciARR && this.keyboardKeys[key] == true) {
|
||||||
//this.inputqueue.push(key);
|
//this.inputQueue.push(key);
|
||||||
this.keyboardButtonsDeciframes = 0;
|
this.keyboardButtonsDeciframes = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -602,31 +608,27 @@ var UserInputs = {
|
|||||||
var DAS = parseInt(this.settingsMap.get("Keyboard DAS")); //65.0;
|
var DAS = parseInt(this.settingsMap.get("Keyboard DAS")); //65.0;
|
||||||
var ARR = parseInt(this.settingsMap.get("Keyboard ARR")); //20.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]) {
|
if(this.prevKeyboardKeys[key] != this.keyboardKeys[key]) {
|
||||||
this.isDirectionArrowDown = false;
|
// Not being held yet
|
||||||
|
this.isPassedDelay = false;
|
||||||
if(this.keyboardKeys[key] == true)
|
if(this.keyboardKeys[key] == true)
|
||||||
this.inputqueue.push(key);
|
this.inputQueue.push(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
var keyboardDASFrames = this.keyboardDirectionArrowsDeciframes;
|
var keyboardDASFrames = this.keyboardDirectionArrowsDeciframes;
|
||||||
|
|
||||||
if (!this.isDirectionArrowDown) {
|
if (!this.isPassedDelay) {
|
||||||
|
|
||||||
if (keyboardDASFrames >= DAS) {
|
if (keyboardDASFrames >= DAS) {
|
||||||
this.keyboardDirectionArrowsDeciframes = 0;
|
this.keyboardDirectionArrowsDeciframes = 0;
|
||||||
this.isDirectionArrowDown = true;
|
this.isPassedDelay = true;
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
if (keyboardDASFrames >= ARR && this.keyboardKeys[key] == true) {
|
else if(keyboardDASFrames >= ARR && this.keyboardKeys[key] == true) {
|
||||||
this.inputqueue.push(key);
|
this.inputQueue.push(key);
|
||||||
this.keyboardDirectionArrowsDeciframes = 0;
|
this.keyboardDirectionArrowsDeciframes = 0;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
//}
|
|
||||||
},
|
},
|
||||||
keyDown(event) {
|
keyDown(event) {
|
||||||
|
|
||||||
@ -651,10 +653,11 @@ var UserInputs = {
|
|||||||
this.prevGpButtons = this.gpButtons;
|
this.prevGpButtons = this.gpButtons;
|
||||||
},
|
},
|
||||||
saveKeyboardKeys() {
|
saveKeyboardKeys() {
|
||||||
|
//this.prevKeyboardKeys = utils.deepClone(this.keyboardKeys);
|
||||||
this.prevKeyboardKeys = {...this.keyboardKeys};
|
this.prevKeyboardKeys = {...this.keyboardKeys};
|
||||||
},
|
},
|
||||||
// button states
|
// button states
|
||||||
isDirectionArrowDown: false,
|
isPassedDelay: false,
|
||||||
isKeyboardKeyDown: false,
|
isKeyboardKeyDown: false,
|
||||||
isGamepadDown: false,
|
isGamepadDown: false,
|
||||||
isGamepadButtonDown: false,
|
isGamepadButtonDown: false,
|
||||||
@ -672,7 +675,7 @@ var UserInputs = {
|
|||||||
prevKeyboardKeys: [],
|
prevKeyboardKeys: [],
|
||||||
|
|
||||||
// button pressed containers
|
// button pressed containers
|
||||||
inputqueue: [],
|
inputQueue: [],
|
||||||
gamepadQueue: [],
|
gamepadQueue: [],
|
||||||
|
|
||||||
ticks: 0,
|
ticks: 0,
|
||||||
@ -853,6 +856,8 @@ Tetris.prototype = {
|
|||||||
|
|
||||||
init: function(options) {
|
init: function(options) {
|
||||||
|
|
||||||
|
// this gameStates = {"
|
||||||
|
// this.state =
|
||||||
var cfg = this.config = utils.extend(options, defaults);
|
var cfg = this.config = utils.extend(options, defaults);
|
||||||
this.interval = consts.DEFAULT_INTERVAL;
|
this.interval = consts.DEFAULT_INTERVAL;
|
||||||
|
|
||||||
@ -867,7 +872,9 @@ Tetris.prototype = {
|
|||||||
this.currentOpener = 0;
|
this.currentOpener = 0;
|
||||||
this.doTest = false;
|
this.doTest = false;
|
||||||
this.matrix = initMatrix(consts.ROW_COUNT, consts.COLUMN_COUNT);
|
this.matrix = initMatrix(consts.ROW_COUNT, consts.COLUMN_COUNT);
|
||||||
|
this.eventTimer = new Date();
|
||||||
|
this.debugTimer = new Date();
|
||||||
|
this.gamepadEnabled = false;
|
||||||
this.reset();
|
this.reset();
|
||||||
|
|
||||||
this._initEvents();
|
this._initEvents();
|
||||||
@ -877,6 +884,9 @@ Tetris.prototype = {
|
|||||||
toggleTimer: function() {
|
toggleTimer: function() {
|
||||||
document.getElementById("Timer").value = (this.isTimerOn = !this.isTimerOn) ? "Seconds:" : "Timer Off";
|
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()
|
setFreePlay: function()
|
||||||
{
|
{
|
||||||
document.getElementById("Timer").value = "Timer Off";
|
document.getElementById("Timer").value = "Timer Off";
|
||||||
@ -919,9 +929,13 @@ Tetris.prototype = {
|
|||||||
|
|
||||||
list.add(option);
|
list.add(option);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
updateSettingTextBox: function() {
|
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() {
|
setSettings: function() {
|
||||||
var newVal = document.getElementById("setting_value").value;
|
var newVal = document.getElementById("setting_value").value;
|
||||||
@ -931,6 +945,7 @@ Tetris.prototype = {
|
|||||||
},
|
},
|
||||||
//Reset game
|
//Reset game
|
||||||
reset: function() {
|
reset: function() {
|
||||||
|
this.numlefts = 0;
|
||||||
this.running = false;
|
this.running = false;
|
||||||
this.isGameOver = false;
|
this.isGameOver = false;
|
||||||
this.level = 1;
|
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() {
|
_processTick: async function() {
|
||||||
|
|
||||||
var deltaTime = 1.0; // 1 millisecond
|
|
||||||
var tenthOfFrame = 1.0 //1.6; // 1.6ms = 1 fram
|
//var deltaTime = (new Date()).getTime() - this.eventTimer.getTime();
|
||||||
var halfFrame = 5.0 //8.0;
|
//console.log("desync time: " + deltaTime);
|
||||||
var halfFramePlus = 10.0;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
inputs.incDeciframes();
|
inputs.incDeciframes();
|
||||||
inputs.incTickCounter();
|
inputs.incTickCounter();
|
||||||
|
|
||||||
|
|
||||||
if(inputs.getTickCounter() >= tenthOfFrame) {
|
if(this.isTimerOn) {
|
||||||
inputs.updateGamepad();
|
var deltaPlayTime = new Date().getTime() - this.sequencePrevTime;
|
||||||
inputs.processGamepadDPad();
|
|
||||||
inputs.processGamepadInput();
|
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.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) {
|
if(inputs.getTickCounter() >= tenthOfFrame) {
|
||||||
document.getElementById("Time").value = (deltaPlayTime/1000).toString();
|
inputs.updateGamepad();
|
||||||
|
inputs.processGamepadDPad();
|
||||||
|
inputs.processGamepadInput();
|
||||||
}
|
}
|
||||||
}
|
// drain gamepad queue
|
||||||
|
if( inputs.getTickCounter() > halfFrame) // 8 millisecons
|
||||||
// drain gamepad queue
|
{
|
||||||
if(inputs.getTickCounter() > halfFrame) // 8 millisecons
|
while((inputs.gamepadQueue != undefined && inputs.gamepadQueue.length >= 1)){
|
||||||
{
|
var curkey = inputs.gamepadQueue.shift();
|
||||||
while((inputs.gamepadQueue != undefined && inputs.gamepadQueue.length >= 1)){
|
if(curkey == "DPad-Left") {
|
||||||
var curkey = inputs.gamepadQueue.shift();
|
this.shape.goLeft(this.matrix);
|
||||||
if(curkey == "DPad-Left") {
|
this.resetLockdown();
|
||||||
this.shape.goLeft(this.matrix);
|
this._draw();
|
||||||
this.resetLockdown();
|
}
|
||||||
this._draw();
|
if(curkey == "DPad-Right") {
|
||||||
}
|
this.shape.goRight(this.matrix);
|
||||||
if(curkey == "DPad-Right") {
|
this.resetLockdown();
|
||||||
this.shape.goRight(this.matrix);
|
this._draw();
|
||||||
this.resetLockdown();
|
}
|
||||||
this._draw();
|
if(curkey == "A") {
|
||||||
}
|
this.rotationCounter++;
|
||||||
if(curkey == "A") {
|
this.shape.rotate(this.matrix);
|
||||||
this.rotationCounter++;
|
this.resetLockdown();
|
||||||
this.shape.rotate(this.matrix);
|
this._draw();
|
||||||
this.resetLockdown();
|
}
|
||||||
this._draw();
|
if(curkey == "B") {
|
||||||
}
|
this.rotationCounter++;
|
||||||
if(curkey == "B") {
|
this.shape.rotateClockwise(this.matrix);
|
||||||
this.rotationCounter++;
|
this.resetLockdown();
|
||||||
this.shape.rotateClockwise(this.matrix);
|
this._draw();
|
||||||
this.resetLockdown();
|
}
|
||||||
this._draw();
|
if(curkey == "DPad-Down") {
|
||||||
}
|
this.shape.goDown(this.matrix);
|
||||||
if(curkey == "DPad-Down") {
|
this._draw();
|
||||||
this.shape.goDown(this.matrix);
|
}
|
||||||
this._draw();
|
if(curkey == "RB") {
|
||||||
}
|
this.shape.goBottom(this.matrix);
|
||||||
if(curkey == "RB") {
|
this.lockDownTimer = 5000;
|
||||||
this.shape.goBottom(this.matrix);
|
this._update();
|
||||||
this.lockDownTimer = 5000;
|
}
|
||||||
this._update();
|
if(curkey == "LB") {
|
||||||
}
|
this.pushHoldStack();
|
||||||
if(curkey == "LB") {
|
this._draw();
|
||||||
this.pushHoldStack();
|
}
|
||||||
this._draw();
|
if(curkey == "DPad-Up") {
|
||||||
}
|
this.popHoldStack();
|
||||||
if(curkey == "DPad-Up") {
|
this._draw();
|
||||||
this.popHoldStack();
|
}
|
||||||
this._draw();
|
if(curkey == "Back") {
|
||||||
}
|
this._restartHandler();
|
||||||
if(curkey == "Back") {
|
return;
|
||||||
this._restartHandler();
|
}
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inputs.gamepadQueue = [];
|
||||||
}
|
}
|
||||||
|
//inputs.gamepadButtonClear();
|
||||||
inputs.gamepadQueue = [];
|
|
||||||
}
|
}
|
||||||
//inputs.gamepadButtonClear();
|
|
||||||
|
|
||||||
// Do keyboard
|
// Do keyboard
|
||||||
if(inputs.getTickCounter() > tenthOfFrame) // 120hz
|
inputs.processKeys();
|
||||||
{
|
|
||||||
inputs.processKeys();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (inputs.getTickCounter() > tenthOfFrame) { // 60hz
|
|
||||||
inputs.processKeyShift();
|
inputs.processKeyShift();
|
||||||
// Keyboard inputs
|
// Keyboard inputs
|
||||||
while((inputs.inputqueue != undefined && inputs.inputqueue.length >= 1)){
|
while((inputs.inputQueue != undefined && inputs.inputQueue.length >= 1)){
|
||||||
var curkey = inputs.inputqueue.shift();
|
var curkey = inputs.inputQueue.shift();
|
||||||
if(curkey == 37) {
|
if(curkey == 37) {
|
||||||
|
this.debugTimer = new Date();
|
||||||
this.shape.goLeft(this.matrix);
|
this.shape.goLeft(this.matrix);
|
||||||
this.resetLockdown();
|
this.resetLockdown();
|
||||||
this._draw();
|
this._draw();
|
||||||
@ -1219,6 +1238,7 @@ Tetris.prototype = {
|
|||||||
this._draw();
|
this._draw();
|
||||||
}
|
}
|
||||||
if(curkey == 40) {
|
if(curkey == 40) {
|
||||||
|
|
||||||
this.shape.goDown(this.matrix);
|
this.shape.goDown(this.matrix);
|
||||||
this._draw();
|
this._draw();
|
||||||
}
|
}
|
||||||
@ -1259,15 +1279,12 @@ Tetris.prototype = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
inputs.inputqueue = [];
|
inputs.inputQueue = [];
|
||||||
}
|
|
||||||
|
|
||||||
if(inputs.getTickCounter() >= halfFramePlus)
|
|
||||||
inputs.saveKeyboardKeys();
|
inputs.saveKeyboardKeys();
|
||||||
|
|
||||||
if(inputs.getTickCounter() >= tenthOfFrame)
|
|
||||||
inputs.saveButtons();
|
inputs.saveButtons();
|
||||||
|
|
||||||
},
|
},
|
||||||
// Refresh game canvas
|
// Refresh game canvas
|
||||||
_refresh: function() {
|
_refresh: function() {
|
||||||
@ -1293,7 +1310,7 @@ Tetris.prototype = {
|
|||||||
return;
|
return;
|
||||||
if(!this.shape.isSameSRS(this.hintMino))
|
if(!this.shape.isSameSRS(this.hintMino))
|
||||||
{
|
{
|
||||||
new Audio('./dist/Failed.ogg').play();
|
//new Audio('./dist/Failed.ogg').play();
|
||||||
this._restartHandler();
|
this._restartHandler();
|
||||||
// Restart
|
// Restart
|
||||||
return 1;
|
return 1;
|
||||||
@ -1404,7 +1421,7 @@ var shapes = require("./shapes.js");
|
|||||||
|
|
||||||
// https://harddrop.com/wiki/Opener
|
// https://harddrop.com/wiki/Opener
|
||||||
// https://four.lol/
|
// https://four.lol/
|
||||||
var OpenerGenerator = {
|
var openerGenerator = {
|
||||||
shapeQueue: [],
|
shapeQueue: [],
|
||||||
hintQueue: [],
|
hintQueue: [],
|
||||||
idx: 0,
|
idx: 0,
|
||||||
@ -1808,19 +1825,19 @@ var OpenerGenerator = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
function reset() {
|
function reset() {
|
||||||
OpenerGenerator.reset();
|
openerGenerator.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
function getNextMino(opener) {
|
function getNextMino(opener) {
|
||||||
var mino = OpenerGenerator.getNextMino(opener);
|
var mino = openerGenerator.getNextMino(opener);
|
||||||
return mino;
|
return mino;
|
||||||
}
|
}
|
||||||
function getNextHint(opener) {
|
function getNextHint(opener) {
|
||||||
var mino = OpenerGenerator.getNextHint(opener);
|
var mino = openerGenerator.getNextHint(opener);
|
||||||
return mino;
|
return mino;
|
||||||
}
|
}
|
||||||
function getLength() {
|
function getLength() {
|
||||||
return OpenerGenerator.getLength();
|
return openerGenerator.getLength();
|
||||||
}
|
}
|
||||||
module.exports.getNextMino = getNextMino;
|
module.exports.getNextMino = getNextMino;
|
||||||
module.exports.getNextHint = getNextHint;
|
module.exports.getNextHint = getNextHint;
|
||||||
|
26
index.html
26
index.html
@ -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/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/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/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>
|
<script>
|
||||||
document.getElementById("bg").width = window.innerWidth;
|
document.getElementById("bg").width = window.innerWidth;
|
||||||
document.getElementById("bg").height = window.innerHeight;
|
document.getElementById("bg").height = window.innerHeight;
|
||||||
@ -125,11 +125,11 @@ document.getElementById("divbg").removeAttribute("tabIndex");
|
|||||||
<canvas style="border: 1px solid DarkGrey;" id="hold"></canvas>
|
<canvas style="border: 1px solid DarkGrey;" id="hold"></canvas>
|
||||||
<br>
|
<br>
|
||||||
<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 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: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 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: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: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: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>
|
||||||
|
|
||||||
<div id="gameOver">
|
<div id="gameOver">
|
||||||
@ -149,14 +149,16 @@ document.getElementById("divbg").removeAttribute("tabIndex");
|
|||||||
<br>
|
<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">
|
<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>
|
<option selected="">Settings:</option>
|
||||||
|
|
||||||
</select>
|
</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: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: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: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>
|
||||||
<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>
|
<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>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@ -176,6 +178,8 @@ document.getElementById("divbg").removeAttribute("tabIndex");
|
|||||||
document.getElementById("setAlbatrossVar").addEventListener("click", function() { tetrion.setCurrentOpener(7); } );
|
document.getElementById("setAlbatrossVar").addEventListener("click", function() { tetrion.setCurrentOpener(7); } );
|
||||||
document.getElementById("setNumberOneVar").addEventListener("click", function() { tetrion.setCurrentOpener(8); } );
|
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("Timer").addEventListener("click", function() { tetrion.toggleTimer(); } );
|
||||||
|
|
||||||
document.getElementById("test").addEventListener("click", function() { tetrion.setDoTest(); } );
|
document.getElementById("test").addEventListener("click", function() { tetrion.setDoTest(); } );
|
||||||
|
49
src/input.js
49
src/input.js
@ -4,6 +4,8 @@ var utils = require('./utils.js');
|
|||||||
|
|
||||||
var UserInputs = {
|
var UserInputs = {
|
||||||
init() {
|
init() {
|
||||||
|
this.dt = 0;
|
||||||
|
this.debugTimer = new Date();
|
||||||
this.settingsMap = new Map();
|
this.settingsMap = new Map();
|
||||||
|
|
||||||
// var init = utils.getCookie("init");
|
// var init = utils.getCookie("init");
|
||||||
@ -24,12 +26,16 @@ var UserInputs = {
|
|||||||
updateGamepad() {
|
updateGamepad() {
|
||||||
this.gpButtons = gamepad.update();
|
this.gpButtons = gamepad.update();
|
||||||
},
|
},
|
||||||
|
gamepadEnabled() {
|
||||||
|
return gamepad.controller || false;
|
||||||
|
},
|
||||||
incDeciframes() {
|
incDeciframes() {
|
||||||
this.keyboardButtonsDeciframes++;
|
this.keyboardButtonsDeciframes++;
|
||||||
this.keyboardDirectionArrowsDeciframes++;
|
this.keyboardDirectionArrowsDeciframes++;
|
||||||
this.gamepadButtonsDeciFrames++;
|
this.gamepadButtonsDeciFrames++;
|
||||||
this.gamepadDirectionPadDeciFrames++;
|
this.gamepadDirectionPadDeciFrames++;
|
||||||
|
|
||||||
|
|
||||||
},
|
},
|
||||||
incTickCounter() {
|
incTickCounter() {
|
||||||
this.ticks++;
|
this.ticks++;
|
||||||
@ -141,13 +147,13 @@ var UserInputs = {
|
|||||||
var deciDAS = 50.0;
|
var deciDAS = 50.0;
|
||||||
var deciARR = 50.0;
|
var deciARR = 50.0;
|
||||||
|
|
||||||
|
|
||||||
// todo: fix this mess
|
// todo: fix this mess
|
||||||
if(this.prevKeyboardKeys[key] != this.keyboardKeys[key] && this.isKeyBoardKeyDown == true) {
|
if(this.prevKeyboardKeys[key] != this.keyboardKeys[key] && this.isKeyBoardKeyDown == true) {
|
||||||
|
|
||||||
this.isKeyboardKeyDown = false;
|
this.isKeyboardKeyDown = false;
|
||||||
if(this.keyboardKeys[key] == true)
|
if(this.keyboardKeys[key] == true)
|
||||||
this.inputqueue.push(key);
|
this.inputQueue.push(key);
|
||||||
this.keyboardKeys[key] = false;
|
//this.keyboardKeys[key] = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
var keyboardDASFrames = this.keyboardButtonsDeciframes;
|
var keyboardDASFrames = this.keyboardButtonsDeciframes;
|
||||||
@ -159,7 +165,7 @@ var UserInputs = {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (keyboardDASFrames >= deciARR && this.keyboardKeys[key] == true) {
|
if (keyboardDASFrames >= deciARR && this.keyboardKeys[key] == true) {
|
||||||
//this.inputqueue.push(key);
|
//this.inputQueue.push(key);
|
||||||
this.keyboardButtonsDeciframes = 0;
|
this.keyboardButtonsDeciframes = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -178,31 +184,27 @@ var UserInputs = {
|
|||||||
var DAS = parseInt(this.settingsMap.get("Keyboard DAS")); //65.0;
|
var DAS = parseInt(this.settingsMap.get("Keyboard DAS")); //65.0;
|
||||||
var ARR = parseInt(this.settingsMap.get("Keyboard ARR")); //20.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]) {
|
if(this.prevKeyboardKeys[key] != this.keyboardKeys[key]) {
|
||||||
this.isDirectionArrowDown = false;
|
// Not being held yet
|
||||||
|
this.isPassedDelay = false;
|
||||||
if(this.keyboardKeys[key] == true)
|
if(this.keyboardKeys[key] == true)
|
||||||
this.inputqueue.push(key);
|
this.inputQueue.push(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
var keyboardDASFrames = this.keyboardDirectionArrowsDeciframes;
|
var keyboardDASFrames = this.keyboardDirectionArrowsDeciframes;
|
||||||
|
|
||||||
if (!this.isDirectionArrowDown) {
|
if (!this.isPassedDelay) {
|
||||||
|
|
||||||
if (keyboardDASFrames >= DAS) {
|
if (keyboardDASFrames >= DAS) {
|
||||||
this.keyboardDirectionArrowsDeciframes = 0;
|
this.keyboardDirectionArrowsDeciframes = 0;
|
||||||
this.isDirectionArrowDown = true;
|
this.isPassedDelay = true;
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
if (keyboardDASFrames >= ARR && this.keyboardKeys[key] == true) {
|
else if(keyboardDASFrames >= ARR && this.keyboardKeys[key] == true) {
|
||||||
this.inputqueue.push(key);
|
this.inputQueue.push(key);
|
||||||
this.keyboardDirectionArrowsDeciframes = 0;
|
this.keyboardDirectionArrowsDeciframes = 0;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
//}
|
|
||||||
},
|
},
|
||||||
keyDown(event) {
|
keyDown(event) {
|
||||||
|
|
||||||
@ -227,10 +229,11 @@ var UserInputs = {
|
|||||||
this.prevGpButtons = this.gpButtons;
|
this.prevGpButtons = this.gpButtons;
|
||||||
},
|
},
|
||||||
saveKeyboardKeys() {
|
saveKeyboardKeys() {
|
||||||
|
//this.prevKeyboardKeys = utils.deepClone(this.keyboardKeys);
|
||||||
this.prevKeyboardKeys = {...this.keyboardKeys};
|
this.prevKeyboardKeys = {...this.keyboardKeys};
|
||||||
},
|
},
|
||||||
// button states
|
// button states
|
||||||
isDirectionArrowDown: false,
|
isPassedDelay: false,
|
||||||
isKeyboardKeyDown: false,
|
isKeyboardKeyDown: false,
|
||||||
isGamepadDown: false,
|
isGamepadDown: false,
|
||||||
isGamepadButtonDown: false,
|
isGamepadButtonDown: false,
|
||||||
@ -248,7 +251,7 @@ var UserInputs = {
|
|||||||
prevKeyboardKeys: [],
|
prevKeyboardKeys: [],
|
||||||
|
|
||||||
// button pressed containers
|
// button pressed containers
|
||||||
inputqueue: [],
|
inputQueue: [],
|
||||||
gamepadQueue: [],
|
gamepadQueue: [],
|
||||||
|
|
||||||
ticks: 0,
|
ticks: 0,
|
||||||
|
180
src/main.js
180
src/main.js
@ -149,6 +149,8 @@ Tetris.prototype = {
|
|||||||
|
|
||||||
init: function(options) {
|
init: function(options) {
|
||||||
|
|
||||||
|
// this gameStates = {"
|
||||||
|
// this.state =
|
||||||
var cfg = this.config = utils.extend(options, defaults);
|
var cfg = this.config = utils.extend(options, defaults);
|
||||||
this.interval = consts.DEFAULT_INTERVAL;
|
this.interval = consts.DEFAULT_INTERVAL;
|
||||||
|
|
||||||
@ -163,7 +165,9 @@ Tetris.prototype = {
|
|||||||
this.currentOpener = 0;
|
this.currentOpener = 0;
|
||||||
this.doTest = false;
|
this.doTest = false;
|
||||||
this.matrix = initMatrix(consts.ROW_COUNT, consts.COLUMN_COUNT);
|
this.matrix = initMatrix(consts.ROW_COUNT, consts.COLUMN_COUNT);
|
||||||
|
this.eventTimer = new Date();
|
||||||
|
this.debugTimer = new Date();
|
||||||
|
this.gamepadEnabled = false;
|
||||||
this.reset();
|
this.reset();
|
||||||
|
|
||||||
this._initEvents();
|
this._initEvents();
|
||||||
@ -173,6 +177,9 @@ Tetris.prototype = {
|
|||||||
toggleTimer: function() {
|
toggleTimer: function() {
|
||||||
document.getElementById("Timer").value = (this.isTimerOn = !this.isTimerOn) ? "Seconds:" : "Timer Off";
|
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()
|
setFreePlay: function()
|
||||||
{
|
{
|
||||||
document.getElementById("Timer").value = "Timer Off";
|
document.getElementById("Timer").value = "Timer Off";
|
||||||
@ -215,9 +222,13 @@ Tetris.prototype = {
|
|||||||
|
|
||||||
list.add(option);
|
list.add(option);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
updateSettingTextBox: function() {
|
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() {
|
setSettings: function() {
|
||||||
var newVal = document.getElementById("setting_value").value;
|
var newVal = document.getElementById("setting_value").value;
|
||||||
@ -227,6 +238,7 @@ Tetris.prototype = {
|
|||||||
},
|
},
|
||||||
//Reset game
|
//Reset game
|
||||||
reset: function() {
|
reset: function() {
|
||||||
|
this.numlefts = 0;
|
||||||
this.running = false;
|
this.running = false;
|
||||||
this.isGameOver = false;
|
this.isGameOver = false;
|
||||||
this.level = 1;
|
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() {
|
_processTick: async function() {
|
||||||
|
|
||||||
var deltaTime = 1.0; // 1 millisecond
|
|
||||||
var tenthOfFrame = 1.0 //1.6; // 1.6ms = 1 fram
|
//var deltaTime = (new Date()).getTime() - this.eventTimer.getTime();
|
||||||
var halfFrame = 5.0 //8.0;
|
//console.log("desync time: " + deltaTime);
|
||||||
var halfFramePlus = 10.0;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
inputs.incDeciframes();
|
inputs.incDeciframes();
|
||||||
inputs.incTickCounter();
|
inputs.incTickCounter();
|
||||||
|
|
||||||
|
|
||||||
if(inputs.getTickCounter() >= tenthOfFrame) {
|
if(this.isTimerOn) {
|
||||||
inputs.updateGamepad();
|
var deltaPlayTime = new Date().getTime() - this.sequencePrevTime;
|
||||||
inputs.processGamepadDPad();
|
|
||||||
inputs.processGamepadInput();
|
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.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) {
|
if(inputs.getTickCounter() >= tenthOfFrame) {
|
||||||
document.getElementById("Time").value = (deltaPlayTime/1000).toString();
|
inputs.updateGamepad();
|
||||||
|
inputs.processGamepadDPad();
|
||||||
|
inputs.processGamepadInput();
|
||||||
}
|
}
|
||||||
}
|
// drain gamepad queue
|
||||||
|
if( inputs.getTickCounter() > halfFrame) // 8 millisecons
|
||||||
// drain gamepad queue
|
{
|
||||||
if(inputs.getTickCounter() > halfFrame) // 8 millisecons
|
while((inputs.gamepadQueue != undefined && inputs.gamepadQueue.length >= 1)){
|
||||||
{
|
var curkey = inputs.gamepadQueue.shift();
|
||||||
while((inputs.gamepadQueue != undefined && inputs.gamepadQueue.length >= 1)){
|
if(curkey == "DPad-Left") {
|
||||||
var curkey = inputs.gamepadQueue.shift();
|
this.shape.goLeft(this.matrix);
|
||||||
if(curkey == "DPad-Left") {
|
this.resetLockdown();
|
||||||
this.shape.goLeft(this.matrix);
|
this._draw();
|
||||||
this.resetLockdown();
|
}
|
||||||
this._draw();
|
if(curkey == "DPad-Right") {
|
||||||
}
|
this.shape.goRight(this.matrix);
|
||||||
if(curkey == "DPad-Right") {
|
this.resetLockdown();
|
||||||
this.shape.goRight(this.matrix);
|
this._draw();
|
||||||
this.resetLockdown();
|
}
|
||||||
this._draw();
|
if(curkey == "A") {
|
||||||
}
|
this.rotationCounter++;
|
||||||
if(curkey == "A") {
|
this.shape.rotate(this.matrix);
|
||||||
this.rotationCounter++;
|
this.resetLockdown();
|
||||||
this.shape.rotate(this.matrix);
|
this._draw();
|
||||||
this.resetLockdown();
|
}
|
||||||
this._draw();
|
if(curkey == "B") {
|
||||||
}
|
this.rotationCounter++;
|
||||||
if(curkey == "B") {
|
this.shape.rotateClockwise(this.matrix);
|
||||||
this.rotationCounter++;
|
this.resetLockdown();
|
||||||
this.shape.rotateClockwise(this.matrix);
|
this._draw();
|
||||||
this.resetLockdown();
|
}
|
||||||
this._draw();
|
if(curkey == "DPad-Down") {
|
||||||
}
|
this.shape.goDown(this.matrix);
|
||||||
if(curkey == "DPad-Down") {
|
this._draw();
|
||||||
this.shape.goDown(this.matrix);
|
}
|
||||||
this._draw();
|
if(curkey == "RB") {
|
||||||
}
|
this.shape.goBottom(this.matrix);
|
||||||
if(curkey == "RB") {
|
this.lockDownTimer = 5000;
|
||||||
this.shape.goBottom(this.matrix);
|
this._update();
|
||||||
this.lockDownTimer = 5000;
|
}
|
||||||
this._update();
|
if(curkey == "LB") {
|
||||||
}
|
this.pushHoldStack();
|
||||||
if(curkey == "LB") {
|
this._draw();
|
||||||
this.pushHoldStack();
|
}
|
||||||
this._draw();
|
if(curkey == "DPad-Up") {
|
||||||
}
|
this.popHoldStack();
|
||||||
if(curkey == "DPad-Up") {
|
this._draw();
|
||||||
this.popHoldStack();
|
}
|
||||||
this._draw();
|
if(curkey == "Back") {
|
||||||
}
|
this._restartHandler();
|
||||||
if(curkey == "Back") {
|
return;
|
||||||
this._restartHandler();
|
}
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inputs.gamepadQueue = [];
|
||||||
}
|
}
|
||||||
|
//inputs.gamepadButtonClear();
|
||||||
inputs.gamepadQueue = [];
|
|
||||||
}
|
}
|
||||||
//inputs.gamepadButtonClear();
|
|
||||||
|
|
||||||
// Do keyboard
|
// Do keyboard
|
||||||
if(inputs.getTickCounter() > tenthOfFrame) // 120hz
|
inputs.processKeys();
|
||||||
{
|
|
||||||
inputs.processKeys();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (inputs.getTickCounter() > tenthOfFrame) { // 60hz
|
|
||||||
inputs.processKeyShift();
|
inputs.processKeyShift();
|
||||||
// Keyboard inputs
|
// Keyboard inputs
|
||||||
while((inputs.inputqueue != undefined && inputs.inputqueue.length >= 1)){
|
while((inputs.inputQueue != undefined && inputs.inputQueue.length >= 1)){
|
||||||
var curkey = inputs.inputqueue.shift();
|
var curkey = inputs.inputQueue.shift();
|
||||||
if(curkey == 37) {
|
if(curkey == 37) {
|
||||||
|
this.debugTimer = new Date();
|
||||||
this.shape.goLeft(this.matrix);
|
this.shape.goLeft(this.matrix);
|
||||||
this.resetLockdown();
|
this.resetLockdown();
|
||||||
this._draw();
|
this._draw();
|
||||||
@ -515,6 +531,7 @@ Tetris.prototype = {
|
|||||||
this._draw();
|
this._draw();
|
||||||
}
|
}
|
||||||
if(curkey == 40) {
|
if(curkey == 40) {
|
||||||
|
|
||||||
this.shape.goDown(this.matrix);
|
this.shape.goDown(this.matrix);
|
||||||
this._draw();
|
this._draw();
|
||||||
}
|
}
|
||||||
@ -555,15 +572,12 @@ Tetris.prototype = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
inputs.inputqueue = [];
|
inputs.inputQueue = [];
|
||||||
}
|
|
||||||
|
|
||||||
if(inputs.getTickCounter() >= halfFramePlus)
|
|
||||||
inputs.saveKeyboardKeys();
|
inputs.saveKeyboardKeys();
|
||||||
|
|
||||||
if(inputs.getTickCounter() >= tenthOfFrame)
|
|
||||||
inputs.saveButtons();
|
inputs.saveButtons();
|
||||||
|
|
||||||
},
|
},
|
||||||
// Refresh game canvas
|
// Refresh game canvas
|
||||||
_refresh: function() {
|
_refresh: function() {
|
||||||
@ -589,7 +603,7 @@ Tetris.prototype = {
|
|||||||
return;
|
return;
|
||||||
if(!this.shape.isSameSRS(this.hintMino))
|
if(!this.shape.isSameSRS(this.hintMino))
|
||||||
{
|
{
|
||||||
new Audio('./dist/Failed.ogg').play();
|
//new Audio('./dist/Failed.ogg').play();
|
||||||
this._restartHandler();
|
this._restartHandler();
|
||||||
// Restart
|
// Restart
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -3,7 +3,7 @@ var shapes = require("./shapes.js");
|
|||||||
|
|
||||||
// https://harddrop.com/wiki/Opener
|
// https://harddrop.com/wiki/Opener
|
||||||
// https://four.lol/
|
// https://four.lol/
|
||||||
var OpenerGenerator = {
|
var openerGenerator = {
|
||||||
shapeQueue: [],
|
shapeQueue: [],
|
||||||
hintQueue: [],
|
hintQueue: [],
|
||||||
idx: 0,
|
idx: 0,
|
||||||
@ -407,19 +407,19 @@ var OpenerGenerator = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
function reset() {
|
function reset() {
|
||||||
OpenerGenerator.reset();
|
openerGenerator.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
function getNextMino(opener) {
|
function getNextMino(opener) {
|
||||||
var mino = OpenerGenerator.getNextMino(opener);
|
var mino = openerGenerator.getNextMino(opener);
|
||||||
return mino;
|
return mino;
|
||||||
}
|
}
|
||||||
function getNextHint(opener) {
|
function getNextHint(opener) {
|
||||||
var mino = OpenerGenerator.getNextHint(opener);
|
var mino = openerGenerator.getNextHint(opener);
|
||||||
return mino;
|
return mino;
|
||||||
}
|
}
|
||||||
function getLength() {
|
function getLength() {
|
||||||
return OpenerGenerator.getLength();
|
return openerGenerator.getLength();
|
||||||
}
|
}
|
||||||
module.exports.getNextMino = getNextMino;
|
module.exports.getNextMino = getNextMino;
|
||||||
module.exports.getNextHint = getNextHint;
|
module.exports.getNextHint = getNextHint;
|
||||||
|
69
src/sequence.js
Normal file
69
src/sequence.js
Normal 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();
|
||||||
|
};
|
Loading…
Reference in New Issue
Block a user