# seanhandley / LICENSE.txt Created January 28, 2012 — forked from aemkei/LICENSE.txt

### SSH clone URL

You can clone with HTTPS or SSH.

Binary Tetris - 140byt.es

 1 2 3 4 5 6 7 8 9 10 11 12 13 ``` DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE Version 2, December 2004   Copyright (C) 2011 YOUR_NAME_HERE   Everyone is permitted to copy and distribute verbatim or modified copies of this license document, and changing it is allowed as long as the name is changed.   DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION   0. You just DO WHAT THE FUCK YOU WANT TO. ```

# TETRIS Clone - 140byt.es

A simplified variant of to the classic tetris game done in less that 140 bytes of JavaScript.

### Example Layout

``````.....
.....
...##
.....
##...
###..
``````

Play the demo at http://jsbin.com/egiqul/48 and feel free to edit the source!

The main logic to move blocks, detect collision, assign new blocks, remove full lines and render the layout are included. Excluded are keyboard controls and the final rendering.

This version is heavy based on binary numbers and bit shift operators. I had to limit the board size to 5x6 (30 bits), because JavaScript converts numbers to 32-bit integers when using bitwise operators. The two left bits are later uses to add the correct padding when dealing with numbers that start with "0".

### Basic Concept

The Board

``````                  00000         .....
798               11000   =>    ##...
11110         ####.
``````

The Block

``````3                 00011  =>     ...##
``````

Checking for Collision

``````                  00000         .....
798&3 = 2         00000  =>     .....
00010         ...X.
``````

Moving the Block at X Axis

``````3 << 1 = 6        00110   =>    ..##.
``````

Moving the Block at Y Axis

``````                  00011         ...##
3<<10 = 3072      00000   =>    .....
00000         .....
``````

Combining Block and Board

``````                  00011         ...##
798|3072 = 3870   11000   =>    ##...
11110         ####.
``````

Find full line (using base 32)

``````                  00011         3
3999              11100   =>    s
11111         v
``````

See the 140byt.es site for a showcase of entries (built itself using 140-byte entries!), and follow @140bytes on Twitter.

To learn about byte-saving hacks for your own code, or to contribute what you've learned, head to the wiki.

140byt.es is brought to you by Jed Schmidt, with help from Alex Kloss. It was inspired by work from Thomas Fuchs and Dustin Diaz.

 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 ```function ( a, // current board b, // current block c, // current position d, // new block offset for position e // placeholder: the layout to return ){ return d += c, // add offset to position e = a | b << d, // render layout based on board and moved block d < 0 | a & b< 1) 3 // double "##" (3 => 111) ), [ // the final return a, // new board b, // new block d, // new position e // final layout to render ] } ```
 1 2 3 4 5 6 7 8 9 10 11 12 13 ```{ "name": "theNameOfYourLibWhichMustBeAValidCamelCasedJavaScriptIdentifier",   "description": "This should be a short description of your entry.",   "keywords": [ "five", "descriptive", "keywords", "or", "fewer" ] } ```
 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 ```