Skip to content

Commit

Permalink
many updates..
Browse files Browse the repository at this point in the history
Signed-off-by: farteryhr <[email protected]>
  • Loading branch information
farteryhr committed Sep 11, 2017
1 parent 36f1787 commit e9153f9
Show file tree
Hide file tree
Showing 11 changed files with 543 additions and 271 deletions.
5 changes: 3 additions & 2 deletions hold.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
function Hold() {
this.piece;
this.piece=0;
}
Hold.prototype.draw = function() {
clear(holdCtx);
Expand All @@ -12,7 +12,8 @@ Hold.prototype.draw = function() {
-rect[initInfo[2]][1] +
(3 - rect[initInfo[2]][3] + rect[initInfo[2]][1]) / 2
,
holdCtx
holdCtx,
RotSys[settings.RotSys].color[p]
);
}
var hold = new Hold();
31 changes: 16 additions & 15 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
content="initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no, width=device-width"/>
<title>Tetr.js</title>
<link rel="stylesheet" href="style.css">
<link rel="stylesheet" href="ui.css">
<script type="text/javascript" src="//s7.addthis.com/js/300/addthis_widget.js#pubid=ra-554c83a8661bf358"
async="async"></script>
<!--<script type="text/javascript" src="//s7.addthis.com/js/300/addthis_widget.js#pubid=ra-554c83a8661bf358" async="async"></script>-->
</head>
<body>
<!--<canvas id="bg"></canvas>-->
Expand Down Expand Up @@ -43,7 +41,7 @@ <h3>Hold</h3>
<th>Score 分</th>
</tr>
<tr>
<td id="line">0</td>
<td id="levelline"><div id="level"></div><div id="line">0</div></td>
<th>Line 行</th>
</tr>
<tr>
Expand All @@ -57,16 +55,16 @@ <h3>Hold</h3>
</div>

<div id="b">
<canvas id="bgStack"></canvas>
<canvas id="stack"></canvas>
<canvas id="bgStack">请使用最新版的网页浏览器方可正常进行游戏。</canvas>
<canvas id="stack">You need an up-to-date web browser to play this game.</canvas>
<canvas id="active"></canvas>

<div id="msgdiv">
<span id="msg"></span>
</div>

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

<p>forked from: <a class="link" href="http://simon.lc/tetr.js/">&gt;&gt;simonlc</a><br/>
farter's Dig Mod</p>
Expand All @@ -75,11 +73,11 @@ <h1>Tetr.js - Dig v0.54</h1>
<a class="btn" onclick="init(0)"><i class="material-icons">&#xE3E7;</i> Sprint 40行竞速</a>
<a class="btn" onclick="init(1)"><i class="material-icons">&#xE153;</i> Marathon 马拉松</a>
<!-- <a class="btn" onclick="init(2)">Play Ultra</a> -->
<a class="btn" onclick="init(3,{digOffset:0})"><i class="material-icons">&#xE002;</i> Dig! 挖掘机</a>
<a class="btn" onclick="init(3,{digOffset:0})"><i class="material-icons">&#xE800;</i> Dig! 挖掘机</a>
<a class="btn" onclick="init(4,{digraceType:'easy'})"><i class="material-icons">&#xE91D;</i> Dig Race 挖掘练习</a>
<a class="btn" onclick="init(5)"><i class="material-icons">&#xE905;</i> Zen 修仙模式</a>
<a class="btn" onclick="init(5)"><i class="material-icons">&#xE2C3;</i> Zen 修仙模式</a>

<a class="btn" onclick="menu(6,1)"><i class="material-icons">&#xE04A;</i> Replay 回放 (α)</a>
<a class="btn" onclick="menu(6,1)"><i class="material-icons">&#xE04A;</i> Replay 录像回放</a>
<a class="btn" onclick="menu(2)" id="btnbinds"><i class="material-icons">&#xE021;</i> Controls 调整按键</a>
<a class="btn" onclick="menu(1)"><i class="material-icons">&#xE869;</i> Settings 调整设定</a>
<a class="btn highlight" onclick="menu(7,1);this.classList.remove('highlight')"><i class="material-icons">&#xE8E5;</i> Harder 更厉害的</a>
Expand Down Expand Up @@ -155,8 +153,7 @@ <h2>Controls 调整按键</h2>
<nav id="go" class="menu">
<div class="btn-container btn-container-bottom">
<a class="btn" onclick="init(gametype,gameparams)">Retry 再来</a>
<a class="btn btn-inline" onclick="init('replay')" style="width: 46%;">Replay 回放 </a>
<a class="btn btn-inline" onclick="showreplaydata()" style="width: 7%;"><i class="material-icons">grade</i></a>
<a class="btn btn-inline" onclick="init('replay')" style="width: 50%;">Replay 回放 </a><a class="btn btn-inline" onclick="showreplaydata()" style="width: calc(25% - .7rem); margin-left: .7rem"><i class="material-icons">&#xE161;</i></a>
<a class="btn highlight" onclick="menu(5,1);this.classList.remove('highlight')">Rankings 排行</a>
<a class="btn" onclick="menu(0)">Back 回菜单</a>
</div>
Expand Down Expand Up @@ -187,7 +184,7 @@ <h2>Replay 回放数据</h2>
<li><a class="btn" onclick="menu(void 0,-1)">Back 返回</a></li>
</ul>
</nav>

<nav class="menu">
<h1>Tetr.js - Dig</h1>
<p>deep♂dark♂fantasy</p>
Expand All @@ -197,8 +194,12 @@ <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="init(7)"><i class="material-icons"></i> Dig Zen 沉思挖掘(测试)</a>
<a class="btn" onclick="init(6)"><i class="material-icons">&#xE01F;</i> 20G 瞬降模式</a>
<a class="btn" onclick="init(7)"><i class="material-icons">&#xE034;</i> Dig Zen 沉思挖掘</a>
<a class="btn" onclick="init(0,{pieceSet:1})"><i class="material-icons"></i> Sprnt 困难40行</a>
<a class="btn" onclick="init(0,{pieceSet:2})"><i class="material-icons"></i> i 简单40行</a>


<a class="btn" onclick="menu(void 0,-1)">Back 返回</a>
</div>
</nav>
Expand Down
25 changes: 13 additions & 12 deletions menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,10 @@ for (var i = 0, len = controlCells.length; i < len; i++) {
// TODO DRY
// Make this into a function and call it when we press Esc.
binds[currCell.id] = tempKey;
currCell.innerHTML = key[tempKey] || tempKey;
$setText(currCell, key[tempKey] || tempKey);
}
tempKey = binds[this.id];
this.innerHTML = 'Press key';
$setText(this, 'Press key');
currCell = this;
}
}
Expand All @@ -169,14 +169,14 @@ addEventListener('keyup', function (e) {
if(newKey){
for (var i in binds) {
if (newKey === binds[i]) {
binds[i] = void 0;
document.getElementById(i).innerHTML = key[binds[i]];
binds[i] = void 0;
$setText($$(i), key[void 0]);
}
}
}
// Binds the key and saves the data.
binds[currCell.id] = newKey;
currCell.innerHTML = key[newKey] || newKey;
$setText(currCell, key[newKey] || newKey);
localStorage.setItem('binds', JSON.stringify(binds));
currCell = 0;
}
Expand Down Expand Up @@ -245,7 +245,7 @@ function saveSetting(s) {
}
localStorage['version'] = version;

document.getElementById(s).getElementsByTagName('span')[0].innerHTML = setting[s][mySettings[s]];
$setText($$(s).getElementsByTagName('span')[0], setting[s][mySettings[s]]);

localStorage['settings'] = JSON.stringify(mySettings);
}
Expand All @@ -256,10 +256,11 @@ function loadLocalData() {
if (localStorage['binds']) {
binds = JSON.parse(localStorage.getItem('binds'));
for (var i = 0, len = controlCells.length; i < len; i++) {
controlCells[i].innerHTML = key[binds[controlCells[i].id]] || binds[controlCells[i].id];
var keycode=binds[controlCells[i].id];
$setText(controlCells[i], key[keycode] || keycode);
}
}else{
document.getElementById("btnbinds").classList.add("highlight");
$$("btnbinds").classList.add("highlight");
}
// TODO When new version just update with new stuff, rest stays unchanged.
if (localStorage['version'] !== version) {
Expand Down Expand Up @@ -287,12 +288,12 @@ for (var s in mySettings) {
var iRight = document.createElement('i');

div.id = s;
sname.innerHTML = settingName[s];
span.innerHTML = setting[s][mySettings[s]];
$setText(sname, settingName[s]);
$setText(span, setting[s][mySettings[s]]);
iLeft.className = 'material-icons left';
iRight.className = 'material-icons right';
iLeft.innerHTML = "&#xE314;";
iRight.innerHTML = "&#xE315;";
$setText(iLeft, "\uE314");
$setText(iRight, "\uE315");
iLeft.onmousedown = left;
iLeft.ontouchstart = left;
iRight.onmousedown = right;
Expand Down
65 changes: 38 additions & 27 deletions piece.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,22 +70,7 @@ Piece.prototype.new = function(index) {
//preview.next();

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,
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 if (gametype === 6) { //Death
if (gametype === 6) { //Death
this.gravity = 20;
if (level < 20) {
this.lockDelayLimit = [
Expand All @@ -100,16 +85,36 @@ Piece.prototype.new = function(index) {
this.lockDelayLimit = 11;
this.areLimit = 6;
}
} else 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,
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.areLimit = 0;
this.gravity = gravityUnit;
}
if (gametype === 0){
if(this.lockDelayLimit < 8) {
this.lockDelayLimit = 8;
}
}

// Check for blockout.
if (!this.moveValid(0, 0, this.tetro)) {
//this.dead = true; //show it?
gameState = 9;
msg.innerHTML = 'BLOCK OUT!';
$setText(msg,'BLOCK OUT!');
menu(3);
sound.playse("gameover");
return;
Expand Down Expand Up @@ -318,10 +323,12 @@ Piece.prototype.hardDrop = function() {
var distance = this.getDrop(2147483647);
this.y += distance;
score = score.add(bigInt(distance + this.lockDelayLimit - this.lockDelay));
statisticsStack();
//statisticsStack();
this.lockDelay = this.lockDelayLimit;
}
Piece.prototype.getDrop = function(distance) {
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;
Expand Down Expand Up @@ -385,13 +392,17 @@ Piece.prototype.checkLock = function() {
sound.playse("lock");
this.dead = true;
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;
}
if(gameState === 9){ // lockout! don't spawn next piece
return;
}else{
this.held = false;
if (this.areLimit === 0) {
this.new(preview.next()); // consider move to main update
} else {
gameState = 4;
this.are = 0;
}
}
/* farter */
}
}
Expand All @@ -418,7 +429,7 @@ Piece.prototype.draw = function() {
a = 0;
a = Math.pow(a,2)*0.5;
}
draw(this.tetro, this.x, Math.floor(this.y) - stack.hiddenHeight, activeCtx, void 0, a);
draw(this.tetro, this.x, Math.floor(this.y) - stack.hiddenHeight, activeCtx, RotSys[settings.RotSys].color[this.index], a);
}
}
}
Expand All @@ -429,7 +440,7 @@ Piece.prototype.drawGhost = function() {
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);
Math.floor(this.y + this.getDrop(2147483647)) - stack.hiddenHeight, activeCtx, RotSys[settings.RotSys].color[this.index]);
}
activeCtx.globalAlpha = 1;
}
Expand Down
23 changes: 17 additions & 6 deletions preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ Preview.prototype.init = function() {
break;
//if ([3,4,6].indexOf(this.grabBag[0]) === -1) break;
}
this.grabBag.push.apply(this.grabBag, this.gen());
if (this.grabBag.length <= 7) {
this.grabBag.push.apply(this.grabBag, this.gen());
}
this.draw();
}
Preview.prototype.next = function() {
var next;
next = this.grabBag.shift();
if (this.grabBag.length === 7) {
if (this.grabBag.length <= 7) {
this.grabBag.push.apply(this.grabBag, this.gen());
}
this.draw();
Expand All @@ -25,13 +27,21 @@ Preview.prototype.next = function() {
* Creates a "grab bag" of the 7 tetrominos.
*/
Preview.prototype.gen = function() {
var pieceList = [0, 1, 2, 3, 4, 5, 6];
var pieceList = void 0;
if(gameparams && gameparams.pieceSet){
switch(gameparams.pieceSet){
case 1: pieceList=[1,2,3,4,5,6];break;
case 2: pieceList=[0,0,0,0,0,0,0];break;
}
}else{
pieceList= [0, 1, 2, 3, 4, 5, 6];
}
//return pieceList.sort(function() {return 0.5 - rng.next()});
/* farter */ // proven random shuffle algorithm
for (var i=0;i<7-1;i++)
for (var i=0;i<pieceList.length-1;i++)
{
var temp=pieceList[i];
var rand=~~((7-i)*rng.next())+i;
var rand=~~((pieceList.length-i)*rng.next())+i;
pieceList[i]=pieceList[rand];
pieceList[rand]=temp;
}
Expand All @@ -53,7 +63,8 @@ Preview.prototype.draw = function() {
-rect[initInfo[2]][1] +
(3 - rect[initInfo[2]][3] + rect[initInfo[2]][1]) / 2 +
i*3,
previewCtx
previewCtx,
RotSys[settings.RotSys].color[p]
);
}
}
Expand Down
Loading

0 comments on commit e9153f9

Please sign in to comment.