Skip to content

Commit

Permalink
many fixes.
Browse files Browse the repository at this point in the history
time is now shown on canvas to prevent dom invalidate.
touch button layout tweaked.
auto frameskip.
ARE, IRS, IHS, 20G mode.

Signed-off-by: farteryhr <[email protected]>
  • Loading branch information
farteryhr committed May 16, 2016
1 parent 5a5291b commit c2a216b
Show file tree
Hide file tree
Showing 5 changed files with 303 additions and 171 deletions.
5 changes: 3 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ <h3>Hold</h3>
<th>Piece 块</th>
</tr>
<tr>
<th id="time">00:00.00</th>
<th id="time"><canvas></canvas></th>
</tr>
</table>
</div>
Expand All @@ -66,7 +66,7 @@ <h3>Hold</h3>
</div>

<nav class="menu on">
<h1>Tetr.js - Dig v0.52</h1>
<h1>Tetr.js - Dig v0.53</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 @@ -197,6 +197,7 @@ <h1>Tetr.js - Dig</h1>
<a class="btn" onclick="init(3,{digOffset:1500})"><i class="material-icons">&#xE3A6;</i> Dig - 1500+</a>
<a class="btn" onclick="init(3,{digOffset:2000})"><i class="material-icons">&#xE3E4;</i> NUKE 核能</a>
<a class="btn" onclick="init(4,{digraceType:'checker'})"><i class="material-icons">&#xE540;</i> Dig Hard 疯狂挖掘</a>
<a class="btn" onclick="init(6)"><i class="material-icons">&#xE01F;</i> 20G 瞬降模式(测试) </a>
<a class="btn" onclick="menu(void 0,-1)">Back 返回</a>
</div>
</nav>
Expand Down
85 changes: 68 additions & 17 deletions piece.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ function Piece() {
this.gravity = gravityUnit;
this.lockDelay = 0;
this.lockDelayLimit = 30;
this.are = 0;
this.areLimit = 0;
this.irsDir = 0;
this.ihs = false;
this.shiftDelay = 0;
this.shiftDir;
this.shiftReleased;
Expand All @@ -21,9 +25,14 @@ function Piece() {
*/
Piece.prototype.new = function(index) {
// TODO if no arguments, get next grabbag piece
console.log("new irs"+this.irsDir+", ihs"+this.ihs);
this.pos = RotSys[settings.RotSys].initinfo[index][2];
this.x = ~~((stack.width - 4) / 2) + RotSys[settings.RotSys].initinfo[index][0];
this.y = stack.hiddenHeight - 2 + RotSys[settings.RotSys].initinfo[index][1];
this.index = index;
this.tetro = [];
this.held = false;
this.ihs = false;
this.finesse = 0;
this.dirty = true;
this.dead = false;
Expand All @@ -32,11 +41,28 @@ Piece.prototype.new = function(index) {

// TODO Do this better. Make clone object func maybe.
//for property in pieces, this.prop = piece.prop
this.tetro = pieces[index].tetro[this.pos];
this.x = ~~((stack.width - 4) / 2) + RotSys[settings.RotSys].initinfo[index][0];
this.y = stack.hiddenHeight - 2 + RotSys[settings.RotSys].initinfo[index][1];
this.index = index;

if (this.irsDir !== 0) {
var curPos = this.pos;
var newPos = (this.pos+this.irsDir).mod(4);
var offsetX =
RotSys[settings.RotSys].offset[this.index][newPos][0] -
RotSys[settings.RotSys].offset[this.index][curPos][0];
var offsetY =
RotSys[settings.RotSys].offset[this.index][newPos][1] -
RotSys[settings.RotSys].offset[this.index][curPos][1];
this.tetro = pieces[index].tetro[newPos];
if (!this.moveValid(offsetX, offsetY, this.tetro)) {
this.tetro = pieces[index].tetro[curPos];
} else {
this.x += offsetX;
this.y += offsetY;
this.pos = newPos;
}
this.irsDir = 0;
} else {
this.tetro = pieces[index].tetro[this.pos];
}

// TODO ---------------- snip

//TODO Do this better. (make grabbag object)
Expand All @@ -46,8 +72,10 @@ Piece.prototype.new = function(index) {

this.lockDelayLimit = setting['Lock Delay'][settings['Lock Delay']];
if (settings.Gravity !== 0) {
this.areLimit = 0;
this.gravity = gravityArr[settings.Gravity - 1];
} else if (gametype === 1) { //Marathon
this.areLimit = 0;
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,
Expand All @@ -58,13 +86,29 @@ Piece.prototype.new = function(index) {
this.gravity = 20;
this.lockDelayLimit = ~~(30 * Math.pow(0.93, (Math.pow(level-20, 0.8)))); // magic!
}
} else if (gametype === 6) { //Death
this.gravity = 20;
if (level < 20) {
this.lockDelayLimit = [
30, 25, 22, 20, 20, 18, 17, 17, 15, 15,
13, 13, 13, 13, 13, 12, 12, 12, 11, 11
][level];
this.areLimit = [
18, 18, 18, 15, 15, 12, 12, 12, 12, 12,
12, 12, 10, 10, 10, 8, 8, 8, 8, 8
][level];
} else {
this.lockDelayLimit = 11;
this.areLimit = 6;
}
} else {
this.areLimit = 0;
this.gravity = gravityUnit;
}

// Check for blockout.
if (!this.moveValid(0, 0, this.tetro)) {
this.dead = true;
//this.dead = true; //show it?
gameState = 9;
msg.innerHTML = 'BLOCK OUT!';
menu(3);
Expand Down Expand Up @@ -332,15 +376,24 @@ Piece.prototype.update = function() {
stack.addPiece(this.tetro);
sound.playse("lock");
this.dead = true;
this.new(preview.next()); // consider move to main update
this.dirty = true;
this.held = false;
if (this.areLimit === 0) {
this.new(preview.next()); // consider move to main update
} else {
gameState = 4;
this.are = 0;
}
/* farter */
} else {
this.lockDelay++;
}
}
}
Piece.prototype.draw = function() {
clear(activeCtx);
if (!this.dead) {
this.drawGhost();
if (settings.Ghost !== 3) {
var a = void 0;
if (landed) {
Expand All @@ -352,17 +405,15 @@ Piece.prototype.draw = function() {
}
}
Piece.prototype.drawGhost = function() {
if (!this.dead) {
activeCtx.globalAlpha = 0.4;
if (settings.Ghost === 0 && !landed) {
draw(this.tetro, this.x,
Math.floor(this.y + this.getDrop(2147483647)) - stack.hiddenHeight, activeCtx, 0);
} else if (settings.Ghost === 1 && !landed) {
draw(this.tetro, this.x,
Math.floor(this.y + this.getDrop(2147483647)) - stack.hiddenHeight, activeCtx);
}
activeCtx.globalAlpha = 1;
activeCtx.globalAlpha = 0.4;
if (settings.Ghost === 0 && !landed) {
draw(this.tetro, this.x,
Math.floor(this.y + this.getDrop(2147483647)) - stack.hiddenHeight, activeCtx, 0);
} else if (settings.Ghost === 1 && !landed) {
draw(this.tetro, this.x,
Math.floor(this.y + this.getDrop(2147483647)) - stack.hiddenHeight, activeCtx);
}
activeCtx.globalAlpha = 1;
}

var piece = new Piece();
2 changes: 1 addition & 1 deletion stack.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ Stack.prototype.addPiece = function(tetro) {
combo = 0;
}
lines += lineClear;
if (gametype === 1)
if (gametype === 1 || gametype === 6)
level = ~~(lines / 10);
score = score.add(scoreAdd.mul(bigInt(16).pow(allclear)));

Expand Down
8 changes: 5 additions & 3 deletions style.css
Original file line number Diff line number Diff line change
Expand Up @@ -148,14 +148,14 @@ nav li {
#stats {
display: block;
position: absolute;
padding: 0;
}
#stats tbody {
display: block;
}
#stats tr {
display: block;
width: 100%;
padding: 0 0.5rem;
}
#stats th {
text-transform: uppercase;
Expand All @@ -173,10 +173,12 @@ nav li {
}
#time {
text-align: center;
font-weight: 900;
font-size: 1.125em;
display: block;
}
#time > canvas {
width: 100%;
height: 1.125em;
}
#score {
text-align: center;
font-weight: 900;
Expand Down
Loading

0 comments on commit c2a216b

Please sign in to comment.