I'm working on a Tetris Game with a friend. How can we turn around the blocks?
We know how to calculate the position of the blocks but we don't know how to add it to the code :
i' = a * i + b * j
j' = c * i + d * j
newJ = -i;
newI = j;
What we were thinking of is adding Arrays but as I said we are not sure.. how to start it
This is our code so far:
function stylingSquares() {
var i;
var j;
for (i = 1; i > -2; i--) {
for (j = -1; j < 2; j++) {
var myDiv = document.createElement("div");
myDiv.style.width = "100px";
myDiv.style.height = "100px";
myDiv.style.backgroundColor = "black";
myDiv.setAttribute("class", "quad");
document.getElementById("game").appendChild(myDiv);
if ((i === 0 && j === 0) ||
(i === 1 && j === -1) ||
(i === 0 && j === -1) ||
(i === 0 && j === 1) ||
(i === 0 && j === 0)) {
myDiv.style.backgroundColor = "red";
} else {
}
}
}
setInterval(function() {
document.body.onkeyup = function(e) {
if (e.keyCode == 32) {
}
}
}, 300);
}
stylingSquares();
.quad {
float: left;
margin: 1 1 1 1;
}
#game {
position: relative;
width: 308px;
height: 308px;
background-color: black;
}
<div id="game"></div>