Skip to content

Commit

Permalink
fixed double framerate issue.
Browse files Browse the repository at this point in the history
fixed framerate jittering.
volume 50% by default following drocelot.
added classic-fast mode.
many detailed changes.

Signed-off-by: farteryhr <[email protected]>
  • Loading branch information
farteryhr committed May 17, 2019
1 parent 06781fd commit 6c51575
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 40 deletions.
6 changes: 4 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ <h3>Hold</h3>
</div>

<nav class="menu on">
<h1>Tetr.js - Dig v0.58</h1>
<h1>Tetr.js - Dig v0.59</h1>

<p>forked from: <a class="link" href="http://simon.lc/tetr.js/">&gt;&gt;simonlc</a><br/>
farter's Dig Mod</p>
Expand Down Expand Up @@ -187,8 +187,10 @@ <h2>Replay 回放数据</h2>

<nav class="menu">
<h1>Tetr.js - Dig</h1>
<p>deep♂dark♂fantasy</p>
<p>deep♂dark♂fantasy<br />
when shit happens, hit Ctrl+F5.</p>
<div class="btn-container">
<a class="btn" onclick="init(1,{marathonType:1})">Classic-Fast 高速经典</a>
<a class="btn" onclick="init(3,{digOffset:500})"><i class="material-icons">&#xE3A8;</i> Dig - 500+</a>
<a class="btn" onclick="init(3,{digOffset:1000})"><i class="material-icons">&#xE3A7;</i> Dig - 1000+</a>
<a class="btn" onclick="init(3,{digOffset:1500})"><i class="material-icons">&#xE3A6;</i> Dig - 1500+</a>
Expand Down
30 changes: 20 additions & 10 deletions piece.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,20 @@ Piece.prototype.new = function(index) {
} else if (settings.Gravity !== 0) {
this.gravity = gravityArr[settings.Gravity - 1];
} else if (gametype === 1) { //Marathon
if (level < 20) {
this.gravity = [
1/60, 1/30, 1/25, 1/20, 1/15, 1/12, 1/10, 1/8, 1/6, 1/6,
1/4, 1/4, 1/3, 1/3, 1/3, 1/2, 1, 1, 2, 3
]
[level];
if (gameparams.marathonType === 1) {
this.gravity = (level * 2 + 10) / 60;
this.lockDelayLimit = 8;
} else {
this.gravity = 20;
this.lockDelayLimit = ~~(30 * Math.pow(0.93, (Math.pow(level-20, 0.8)))); // magic!
if (level < 20) {
this.gravity = [
1/60, 1/30, 1/25, 1/20, 1/15, 1/12, 1/10, 1/8, 1/6, 1/6,
1/4, 1/4, 1/3, 1/3, 1/3, 1/2, 1, 1, 2, 3
]
[level];
} else {
this.gravity = 20;
this.lockDelayLimit = ~~(30 * Math.pow(0.93, (Math.pow(level-20, 0.8)))); // magic!
}
}
} else {
this.gravity = gravityUnit;
Expand Down Expand Up @@ -322,15 +327,18 @@ Piece.prototype.hardDrop = function() {
this.lockDelay = this.lockDelayLimit;
}
Piece.prototype.getDrop = function(distance) {
if (!this.moveValid(0, 0, this.tetro))
return 0;
if (!this.moveValid(0, 0, this.tetro))
return 0;
for (var i = 1; i <= distance; i++) {
if (!this.moveValid(0, i, this.tetro))
return i - 1;
}
return i - 1;
}
Piece.prototype.hold = function() {
if (gametype === 1 && gameparams.marathonType === 1){
return
}
var temp = hold.piece;
if (!this.held) {
if (hold.piece !== void 0) {
Expand Down Expand Up @@ -406,6 +414,8 @@ Piece.prototype.checkLock = function() {
this.lockDelayLimit = 11;
this.areLimit = 6;
}
} else if (gametype === 1 && gameparams.marathonType === 1) {
this.areLimit = 11;
} else {
this.areLimit = 0;
}
Expand Down
2 changes: 1 addition & 1 deletion ranking.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ function handlereplay(xmlhttp)
}

var hostaddr=
"http://farter.tk:8888";
"http://farter.cn:8888";
//"http://localhost:8888";

function submitscore(obj)
Expand Down
2 changes: 1 addition & 1 deletion stack.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ Stack.prototype.addPiece = function(tetro) {
garbage += 10;
}

if(gameparams&&gameparams.backFire){
if(gameparams.backFire){
if(gameparams.backFire === 1){
garbage = [0, 0,1,2,4][lineClear];
}else if(gameparams.backFire === 3){
Expand Down
74 changes: 48 additions & 26 deletions tetris.js
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ var mySettings = {
Next: 6,
Size: 0,
Sound: 0,
Volume: 100,
Volume: 50,
Block: 2,
Ghost: 1,
Grid: 1,
Expand Down Expand Up @@ -962,7 +962,7 @@ function init(gt, params) {
throw "wtf";
if(params === "" || params.slice(0,1) !=="{")
throw "please paste replay data, correctly..."
replay = JSON.parse(params);
replay = JSON.parse(params.replace(/\n/g,""));
if(typeof replay !== "object")
throw "json parse fail";
if((replay.gametype === void 0)
Expand All @@ -981,7 +981,7 @@ function init(gt, params) {
}
}
gametype = replay.gametype;
gameparams = replay.gameparams;
gameparams = replay.gameparams || {};
settings = replay.settings; // by reference
rng.seed = replay.seed;
} else {
Expand Down Expand Up @@ -1057,7 +1057,7 @@ function init(gt, params) {
// Dig Race
// make ten random numbers, make sure next isn't the same as last? t=rnd()*(size-1);t>=arr[i-1]?t++:; /* farter */
//TODO make into function or own file.
if (gameparams["digraceType"] === void 0 || gameparams["digraceType"] === "checker") {
if (gameparams.digraceType === void 0 || gameparams.digraceType === "checker") {
// harder digrace: checkerboard
digLines = range(stack.height - 10, stack.height);
$setText(statsLines,10);
Expand All @@ -1067,7 +1067,7 @@ function init(gt, params) {
stack.grid[x][y] = 8;
}
}
} else if(gameparams["digraceType"] === "easy") {
} else if(gameparams.digraceType === "easy") {
var begin = ~~(rng.next()*stack.width);
var dire = (~~(rng.next()*2))*2-1;
digLines = range(stack.height - 10, stack.height);
Expand All @@ -1085,13 +1085,26 @@ function init(gt, params) {
lastPiecesSet = 0;
digZenBuffer = 0;
}
if (gametype === 1 && gameparams.marathonType === 1){
if (settings.ARR < 1){
settings.ARR = 1;
}
if (settings["Soft Drop"] > 6){
settings["Soft Drop"] = 6;
}
if (settings.Next > 1){
settings.Next = 1;
}
}

menu();

// Only start a loop if one is not running already.
// don't keep looping when not played
console.log(paused,gameState);
if (paused || gameState === 3) {
// in the 0~16ms after the last frame, inloop==true and gameState==3
// retry is instant event, so double RAF here...
console.log(paused,gameState,inloop);
if (/*paused || gameState === 3*/ !inloop) {
console.log("start inloop",inloop);
inloop=true;
requestAnimFrame(gameLoop);
Expand Down Expand Up @@ -1203,7 +1216,7 @@ function statistics() {

timeCtx.clearRect(0, 0, timeCanvas.width, timeCanvas.height);
timeCtx.fillText(displayTime, timeCanvas.width/2, timeCanvas.height/2);
timeCtx.fillRect(skipL,timeCanvas.height-0.2,skipR,timeCanvas.height);
timeCtx.fillRect(skipL,timeCanvas.height-0.4,skipR,timeCanvas.height);
}

/**
Expand All @@ -1220,8 +1233,8 @@ function statisticsStack() {
$setText(statsLines, lines);
$setText(statsLevel, "Lv. " + level);
}else if (gametype === 3){
if (gameparams["digOffset"] || gameparams["digOffset"] !== 0){
$setText(statsLevel, gameparams["digOffset"] + "+");
if (gameparams.digOffset || gameparams.digOffset !== 0){
$setText(statsLevel, gameparams.digOffset + "+");
}else{
$setText(statsLevel, "");
}
Expand Down Expand Up @@ -1548,7 +1561,7 @@ function update() {
var arrRow = [8,8,8,8,8,8,8,8,8,8];
var curStage = 0, objCurStage;

while(curStage<arrStages.length && arrStages[curStage].begin <= lines + (gameparams["digOffset"] || 0)) {
while(curStage<arrStages.length && arrStages[curStage].begin <= lines + (gameparams.digOffset || 0)) {
curStage++;
}
curStage--;
Expand Down Expand Up @@ -1617,11 +1630,17 @@ function gameLoop() {
if (!paused && gameState !== 3) {
requestAnimFrame(gameLoop);

var repeat = ~~((Date.now() - startTime - pauseTime)/1000*fps) - frame;
if (repeat>1) {
frameSkipped += repeat-1;
} else if (repeat<=0) {
// anti turbulance
// requestanimationframe is not perfectly 60fps, also with turbulance
var repeat = (Date.now() - startTime - pauseTime)/1000*fps - frame;
if (repeat>=2) {
repeat = Math.floor(repeat);
frameSkipped += repeat-1;
} else if (repeat <= 0) {
repeat = Math.ceil(repeat);
frameSkipped += (repeat-1+60);
} else {
repeat = 1;
}

for (var repf=0;repf<repeat;repf++) {
Expand Down Expand Up @@ -1657,19 +1676,22 @@ function gameLoop() {
if (flags.rotLeft & keysDown && !(lastKeys & flags.rotLeft)) {
piece.irsDir = -1;
piece.finesse++;
console.log("IRS");
//console.log("IRS");
} else if (flags.rotRight & keysDown && !(lastKeys & flags.rotRight)) {
piece.irsDir = 1;
piece.finesse++;
console.log("IRS");
//console.log("IRS");
} else if (flags.rot180 & keysDown && !(lastKeys & flags.rot180)) {
piece.irsDir = 2;
piece.finesse++;
console.log("IRS");
//console.log("IRS");
}
if (!(lastKeys & flags.holdPiece) && flags.holdPiece & keysDown) {
piece.ihs = true;
console.log("IHS");
if (gametype === 1 && gameparams.marathonType === 1){
} else {
piece.ihs = true;
//console.log("IHS");
}
}
if (lastKeys !== keysDown) {
lastKeys = keysDown;
Expand Down Expand Up @@ -1769,7 +1791,7 @@ function checkWin(){
if (gametype === 0) { // 40L
if (lines >= lineLimit) {
gameState = 1;
if (gameparams && gameparams.backFire){
if (gameparams.backFire){
msg.innerHTML = "GREAT!";
} else {
var rank = null;
Expand Down Expand Up @@ -1838,14 +1860,14 @@ function trysubmitscore() {

if(gametype===0) // 40L
obj.mode="sprint" +
(gameparams&&gameparams.pieceSet?["","noi","alli"][gameparams.pieceSet]:"") +
(gameparams&&gameparams.backFire?["","bf1","bf2","bf3"][gameparams.backFire]:"");
(gameparams.pieceSet?["","noi","alli"][gameparams.pieceSet]:"") +
(gameparams.backFire?["","bf1","bf2","bf3"][gameparams.backFire]:"");
else if(gametype===3) // dig
obj.mode="dig" + (gameparams&&gameparams.digOffset?gameparams.digOffset:"");
obj.mode="dig" + (gameparams.digOffset?gameparams.digOffset:"");
else if(gametype===4) // dig race
obj.mode="digrace" + (gameparams&&gameparams.digraceType?gameparams.digraceType:"checker");
obj.mode="digrace" + (gameparams.digraceType?gameparams.digraceType:"checker");
else if(gametype===1) // marathon
obj.mode="marathon";
obj.mode="marathon" + (gameparams.marathonType?["","cls"][gameparams.marathonType]:"");
else if(gametype===5) // score attack
obj.mode="score";
else if(gametype===6) // 20g
Expand Down

0 comments on commit 6c51575

Please sign in to comment.