veu / mini-tetris
- воскресенье, 15 октября 2017 г. в 03:16:35
Tetris in 512b
A JavaScript Tetris clone in 512b.
Note that some tricks may have been replaced in the most recent version.
1023
, ie. 1111111111
in binary)....
is used to cheaply copy the playing field.
Thanks to the copy adding the piece to the field (for drawing, updating the field, and checking for overlaps)
is one operation without having to remove the piece afterwards.Array.map
body
the mapping function M
is called as a template literal tag function
with the body as an argument which is then passed to eval()
.|=
store the original value of the assigned variable before evaluating the right side. This way the variable S
can be used to keep the score and build the UI at the same time. After the UI has been created, the right side of S|=…
evaluates to 0
resetting S
to the score.onkeyup
is shorter than onkeydown
though less responsive.KeyboardEvent.which
is shorter than KeyboardEvent.keyCode
.k
and can thus be used outside of the event handler.setTimeout()
returns a random identifier which can be used for clearTimeout()
or as random value to select tetrominos.<body>
tag doubles as cheap way to execute the code (via onload
) and element to insert the UI.Node.innerText
line breaks can be done with \n
instead of <br>
when using Element.innerHTML
.A&&B
is used in favor of if(A)B
but A?B:0
is used when B is an assignment to avoid wrapping it in parentheses.If you want to join us or see other golfing projects we’ve made, see this list.