Conversation
invzfnc
left a comment
There was a problem hiding this comment.
Overall great work, just some things need tweaking. Details are in comments.
| //Get Random tetromino | ||
| let tArray = ["I","J","L","O","S","T","Z"]; | ||
| let random = Math.floor(Math.random()*tArray.length); | ||
| let randtetromino = getTetrominoByName(tArray[random]); |
There was a problem hiding this comment.
Take a look at this: https://tetris.wiki/Random_Generator
Apparently you can't just randomly pick one from the seven tetrominos every single time you generate a tetromino. Instead you generate a sequence of 7 and pop out one at a time till the sequence is empty.
There was a problem hiding this comment.
Yep, noticed that. I was testing whether each block is able to function properly within the game boundaries. Will change it!
| } | ||
|
|
||
| //Get Random tetromino | ||
| let tArray = ["I","J","L","O","S","T","Z"]; |
There was a problem hiding this comment.
Rather than redefining write Object.keys(tetrominos) instead.
| let previousTimeStamp; // to compare with timeStamp | ||
| let y = 0; // position of falling tetromino | ||
| let x = 0; | ||
| let playfieldArray = Array.from({ length: gridRows }, () => Array(gridColumns).fill(0)); // converts playfield into 2D array |
There was a problem hiding this comment.
Personally I think it would be better if we keep the naming consistent. Maybe better if we use playfieldMatrix like in getTetrominoByName. How you think?
There was a problem hiding this comment.
Yep I agree. Will make changes!
| if (e.keyCode == 40){ | ||
| if (isMoveValid(randtetromino, x, y) && y < 18) // <- some reason the tetromino overshoots, had to put another temp limiter here | ||
| y++; | ||
| } | ||
| if (e.keyCode == 37){ | ||
| if (isMoveValid(randtetromino, x - 1, y)) | ||
| x--; | ||
| } | ||
| if (e.keyCode == 39){ | ||
| if (isMoveValid(randtetromino, x + 1, y)) | ||
| x++; | ||
| } |
There was a problem hiding this comment.
https://stackoverflow.com/a/43418287
Use event.key == "ArrowDown" (etc) instead
This link might be useful https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key
And event instead of e is just my preference for clarity, it's up to you to choose which one.
There was a problem hiding this comment.
Noted, will clarify it
| if (previousTimeStamp == undefined) { // first time calling | ||
| //Main gameloop | ||
| function gameloop(timeStamp) { | ||
| if (!previousTimeStamp) { // first time calling |
c283943 to
7fa30b4
Compare
No description provided.