Implement upcoming tiles and hold a tile (not yet graphical)
This commit is contained in:
@@ -13,7 +13,6 @@
|
|||||||
<feGaussianBlur in="SourceGraphic" stdDeviation="15"></feGaussianBlur>
|
<feGaussianBlur in="SourceGraphic" stdDeviation="15"></feGaussianBlur>
|
||||||
</filter>
|
</filter>
|
||||||
</defs>
|
</defs>
|
||||||
<!--<animate id="animate1" xlink:href="#f1" attributeName="stdDeviation" from="15" to="0" begin="" dur="1s" />-->
|
|
||||||
</svg>
|
</svg>
|
||||||
<div id="menu">
|
<div id="menu">
|
||||||
<div id="language-selector">
|
<div id="language-selector">
|
||||||
|
40
js/tetris.js
40
js/tetris.js
@@ -20,6 +20,12 @@ let isPaused = true;
|
|||||||
let startTime = 0;
|
let startTime = 0;
|
||||||
let prevUpdateScore = 0;
|
let prevUpdateScore = 0;
|
||||||
|
|
||||||
|
const pieces = 'IJLOSTZ';
|
||||||
|
|
||||||
|
let upcomingTiles = [];
|
||||||
|
let holdingTile = null;
|
||||||
|
let alreadyHolding = false;
|
||||||
|
|
||||||
if (typeof console === "undefined") {
|
if (typeof console === "undefined") {
|
||||||
console = {};
|
console = {};
|
||||||
}
|
}
|
||||||
@@ -28,6 +34,10 @@ let prerenders = [];
|
|||||||
const prerenderWidth = canvas.width / fieldSize.x * 4;
|
const prerenderWidth = canvas.width / fieldSize.x * 4;
|
||||||
const prerenderHeight = canvas.height / fieldSize.y * 4;
|
const prerenderHeight = canvas.height / fieldSize.y * 4;
|
||||||
|
|
||||||
|
function addTile() {
|
||||||
|
upcomingTiles.push(createPiece(pieces[pieces.length * Math.random() | 0]));
|
||||||
|
}
|
||||||
|
|
||||||
function arenaSweep() {
|
function arenaSweep() {
|
||||||
let rowCount = 1;
|
let rowCount = 1;
|
||||||
outer: for (let y = arena.length - 1; y > 0; --y) {
|
outer: for (let y = arena.length - 1; y > 0; --y) {
|
||||||
@@ -300,6 +310,18 @@ function playerDrop() {
|
|||||||
dropCounter = 0;
|
dropCounter = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function playerHold() {
|
||||||
|
if (alreadyHolding)
|
||||||
|
return;
|
||||||
|
if (holdingTile === null) {
|
||||||
|
holdingTile = player.matrix;
|
||||||
|
playerReset(true);
|
||||||
|
} else {
|
||||||
|
holdingTile = [player.matrix, player.matrix = holdingTile][0];
|
||||||
|
playerReset(true, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function playerMove(dir) {
|
function playerMove(dir) {
|
||||||
player.pos.x += dir;
|
player.pos.x += dir;
|
||||||
if (collide(arena, player)) {
|
if (collide(arena, player)) {
|
||||||
@@ -308,9 +330,14 @@ function playerMove(dir) {
|
|||||||
dropCounter *= .75;
|
dropCounter *= .75;
|
||||||
}
|
}
|
||||||
|
|
||||||
function playerReset() {
|
function playerReset(resetHold = false, newTile = true) {
|
||||||
const pieces = 'IJLOSTZ';
|
alreadyHolding = resetHold;
|
||||||
player.matrix = createPiece(pieces[pieces.length * Math.random() | 0]);
|
if (newTile) {
|
||||||
|
player.matrix = upcomingTiles[0];
|
||||||
|
upcomingTiles.splice(0, 1);
|
||||||
|
addTile();
|
||||||
|
}
|
||||||
|
|
||||||
player.pos.y = 0;
|
player.pos.y = 0;
|
||||||
player.pos.x = (arena[0].length / 2 | 0) - (player.matrix[0].length / 2 | 0);
|
player.pos.x = (arena[0].length / 2 | 0) - (player.matrix[0].length / 2 | 0);
|
||||||
|
|
||||||
@@ -470,6 +497,10 @@ const keys = {
|
|||||||
rotateRight: {
|
rotateRight: {
|
||||||
keys: [69],
|
keys: [69],
|
||||||
action: () => playerRotate(1)
|
action: () => playerRotate(1)
|
||||||
|
},
|
||||||
|
holdTile: {
|
||||||
|
keys: [38, 87],
|
||||||
|
action: () => playerHold()
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -486,6 +517,9 @@ document.addEventListener('keydown', event => {
|
|||||||
function startGame() {
|
function startGame() {
|
||||||
arena = createMatrix(fieldSize.x, fieldSize.y);
|
arena = createMatrix(fieldSize.x, fieldSize.y);
|
||||||
drawArena();
|
drawArena();
|
||||||
|
addTile();
|
||||||
|
addTile();
|
||||||
|
addTile();
|
||||||
playerReset();
|
playerReset();
|
||||||
update();
|
update();
|
||||||
updateScore();
|
updateScore();
|
||||||
|
@@ -9,7 +9,6 @@ hammertime.on('swiperight', (e) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
hammertime.on('pandown swipedown', (e) => {
|
hammertime.on('pandown swipedown', (e) => {
|
||||||
console.log(e);
|
|
||||||
keys.down.action();
|
keys.down.action();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user