Skip to content

Commit

Permalink
rotation system reimplemented, with ARS C2RS SRS 180rot support.
Browse files Browse the repository at this point in the history
a bit tuning on score.
a big one.

Signed-off-by: farteryhr <[email protected]>
  • Loading branch information
farteryhr committed Oct 7, 2015
1 parent c55940b commit 62da843
Show file tree
Hide file tree
Showing 8 changed files with 216 additions and 120 deletions.
9 changes: 5 additions & 4 deletions hold.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ function Hold() {
}
Hold.prototype.draw = function() {
clear(holdCtx);
var initInfo = RotSys[settings.RotSys].initinfo[this.piece];
if (this.piece === 0 || this.piece === 3) {
draw(pieces[this.piece].tetro, pieces[this.piece].x - 3,
2 + pieces[this.piece].y, holdCtx);
draw(pieces[this.piece].tetro[initInfo[2]], pieces[this.piece].x - 3,
2 + pieces[this.piece].y + initInfo[1], holdCtx);
} else {
draw(pieces[this.piece].tetro, pieces[this.piece].x - 2.5,
2 + pieces[this.piece].y, holdCtx);
draw(pieces[this.piece].tetro[initInfo[2]], pieces[this.piece].x - 2.5,
2 + pieces[this.piece].y + initInfo[1], holdCtx);
}
}
var hold = new Hold();
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ <h3>Hold</h3>
</div>

<nav class='menu on'>
<h1>Tetr.js - Dig v0.4</h1>
<h1>Tetr.js - Dig v0.5</h1>
<p>forked from: <span onclick="window.location='http://simon.lc/tetr.js/'"><u>&gt;&gt;simonlc</u></span><br/>
farter's Dig Mod</p>
<ul>
Expand Down
7 changes: 6 additions & 1 deletion menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,12 @@ function loadLocalData() {
localStorage.removeItem('binds');
}
if (localStorage['settings']) {
mySettings = JSON.parse(localStorage.getItem('settings'));
var storedSettings = JSON.parse(localStorage.getItem('settings'));
for (var i in mySettings) {
if (i in storedSettings) {
mySettings[i] = storedSettings[i];
}
}
}
}

Expand Down
93 changes: 55 additions & 38 deletions piece.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function Piece() {
*/
Piece.prototype.new = function(index) {
// TODO if no arguments, get next grabbag piece
this.pos = 0;
this.pos = RotSys[settings.RotSys].initinfo[index][2];
this.tetro = [];
this.held = false;
this.finesse = 0;
Expand All @@ -33,10 +33,10 @@ 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.tetro = pieces[index].tetro[this.pos];
this.kickData = pieces[index].kickData;
this.x = pieces[index].x;
this.y = pieces[index].y;
this.x = pieces[index].x + RotSys[settings.RotSys].initinfo[index][0];
this.y = pieces[index].y + RotSys[settings.RotSys].initinfo[index][1];
this.index = index;

// TODO ---------------- snip
Expand Down Expand Up @@ -75,48 +75,62 @@ Piece.prototype.new = function(index) {

piece.checkFall(); //real 20G !
}
Piece.prototype.rotate = function(direction) {

// Rotates tetromino.
var rotated = [];
if (direction === -1) {
for (var i = this.tetro.length - 1; i >= 0; i--) {
rotated[i] = [];
for (var row = 0; row < this.tetro.length; row++) {
rotated[i][this.tetro.length - 1 - row] = this.tetro[row][i];
}
}
} else {
for (var i = 0; i < this.tetro.length; i++) {
rotated[i] = [];
for (var row = this.tetro.length - 1; row >= 0; row--) {
rotated[i][row] = this.tetro[row][this.tetro.length - 1 - i];
}
Piece.prototype.tryKickList = function(kickList, rotated, newPos, offsetX, offsetY) {
for (var k = 0, len = kickList.length; k < len; k++) {
if (this.moveValid(
offsetX + kickList[k][0],
offsetY + kickList[k][1],
rotated
)) {
this.x += offsetX + kickList[k][0];
this.y += offsetY + kickList[k][1];
this.tetro = rotated;
this.pos = newPos;
this.finesse++;
break;
}
}
}
Piece.prototype.rotate = function(direction) {

// Goes thorugh kick data until it finds a valid move.
var curPos = this.pos.mod(4);
var newPos = (this.pos + direction).mod(4);

for (var x = 0, len = this.kickData[0].length; x < len; x++) {
if (this.moveValid(
this.kickData[curPos][x][0] - this.kickData[newPos][x][0],
this.kickData[curPos][x][1] - this.kickData[newPos][x][1],
rotated
)) {
this.x += this.kickData[curPos][x][0] -
this.kickData[newPos][x][0];
this.y += this.kickData[curPos][x][1] -
this.kickData[newPos][x][1];
this.tetro = rotated;
this.pos = newPos;
// TODO make 180 rotate count as one or just update finess 180s
//this.finesse++;
break;
// Rotates tetromino.
var rotated = pieces[this.index].tetro[newPos];
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];
if (settings.RotSys === 2) { //ARS
var kickList = [];
if (this.index === PieceI.index) {
if(curPos === 1 || curPos === 3)
kickList = [[ 0, 0],[+1, 0],[-1, 0],[+2, 0]];
else
kickList = [[ 0, 0],[ 0,-1],[ 0,-2]];
} else {
if (newPos === 0 ||
((this.index === PieceS.index || this.index === PieceZ.index) && newPos === 2)
)
kickList = [[ 0, 0],[+1, 0],[-1, 0],[ 0,-1]];
else
kickList = [[ 0, 0],[+1, 0],[-1, 0]];
}
this.tryKickList(kickList, rotated, newPos, offsetX, offsetY);
} else {
var kickIndex = [ 1, -1 ,2].indexOf(direction); // kickDataDirectionIndex
var kickList;
if (settings.RotSys === 1)
kickList = WKTableCultris;
else
kickList = WKTableSRS[this.index][kickIndex][curPos];
this.tryKickList(kickList, rotated, newPos, offsetX, offsetY);
}
}

Piece.prototype.checkShift = function() {
// Shift key pressed event.
if (keysDown & flags.moveLeft && !(lastKeys & flags.moveLeft)) {
Expand Down Expand Up @@ -223,7 +237,10 @@ Piece.prototype.shiftDown = function() {
}
}
Piece.prototype.hardDrop = function() {
this.y += this.getDrop(2147483647); /* farter */
var distance = this.getDrop(2147483647);
this.y += distance;
score = score.add(bigInt(distance + this.lockDelayLimit - this.lockDelay));
statisticsStack();
this.lockDelay = this.lockDelayLimit;
}
Piece.prototype.getDrop = function(distance) {
Expand Down
9 changes: 5 additions & 4 deletions preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,13 @@ Preview.prototype.gen = function() {
Preview.prototype.draw = function() {
clear(previewCtx);
for (var i = 0; i < 6; i++) {
var initInfo = RotSys[settings.RotSys].initinfo[this.grabBag[i]];
if (this.grabBag[i] === 0 || this.grabBag[i] === 3) {
draw(pieces[this.grabBag[i]].tetro, pieces[this.grabBag[i]].x - 3,
pieces[this.grabBag[i]].y + 2 + i * 3, previewCtx);
draw(pieces[this.grabBag[i]].tetro[initInfo[2]], pieces[this.grabBag[i]].x - 3,
pieces[this.grabBag[i]].y + 2 + initInfo[1] + i * 3, previewCtx);
} else {
draw(pieces[this.grabBag[i]].tetro, pieces[this.grabBag[i]].x - 2.5,
pieces[this.grabBag[i]].y + 2 + i * 3, previewCtx);
draw(pieces[this.grabBag[i]].tetro[initInfo[2]], pieces[this.grabBag[i]].x - 2.5,
pieces[this.grabBag[i]].y + 2 + initInfo[1] + i * 3, previewCtx);
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions stack.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ Stack.prototype.addPiece = function(tetro) {

var scoreAdd = bigInt(level + 1);
if (lineClear !== 0) {
console.log("C"+combo+" B"+b2b)
//console.log("C"+combo+" B"+b2b)
if (isSpin) {
scoreAdd = scoreAdd.mul(
bigInt([800,1200,1600,2000][lineClear - 1])
Expand Down Expand Up @@ -121,8 +121,8 @@ Stack.prototype.addPiece = function(tetro) {
if (gametype === 1)
level = ~~(lines / 10);
score = score.add(scoreAdd);
if (scoreAdd.cmp(0) > 0)
console.log(scoreAdd.toString());
//if (scoreAdd.cmp(0) > 0)
//console.log(scoreAdd.toString());

statsFinesse += piece.finesse - finesse[piece.index][piece.pos][column];
piecesSet++; // NOTE Stats
Expand Down
2 changes: 1 addition & 1 deletion style.css
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ nav a {
#score {
text-align: center;
font-weight: 900;
font-size: 1em;
font-size: 0.9em;
display: block;
}

Expand Down
Loading

0 comments on commit 62da843

Please sign in to comment.