Skip to content

Instantly share code, notes, and snippets.

@aemkei
Forked from maettig/LICENSE.txt
Last active August 29, 2015 14:23
Show Gist options
  • Save aemkei/cbb8434989d2e18aa1c2 to your computer and use it in GitHub Desktop.
Save aemkei/cbb8434989d2e18aa1c2 to your computer and use it in GitHub Desktop.

Revisions

  1. @maettig maettig revised this gist Apr 15, 2012. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions test.html
    Original file line number Diff line number Diff line change
    @@ -86,11 +86,11 @@ <h2></h2>
    l.e |= l[l.x] & 8;
    l[l.x] = 1
    }
    // 135 bytes
    // 134 bytes
    var updateGhosts = function(a, l, g, d)
    {
    for (g in a)
    l[a[g].x] &= ~8; //restore item
    l[a[g].x] &= 7; //remove all ghosts first
    for (g in a)
    {
    g = a[g];
    @@ -100,7 +100,7 @@ <h2></h2>
    ? g.d++ //rotate ghost by 90 degree
    : l.e |= 1 & l[ //else check if hitting the player
    g.x += d]; //and walk
    l[g.x] |= 8
    l[g.x] |= 8 //place ghost
    }
    }
    var levels = [parseLevel([
  2. @maettig maettig revised this gist Apr 14, 2012. 1 changed file with 12 additions and 12 deletions.
    24 changes: 12 additions & 12 deletions test.html
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,5 @@
    <!DOCTYPE html>
    <title>Pac-Man in 140byt.es by @maettig</title>
    <pre>LOADING...</pre>
    <h2></h2>
    <span id="points">0</span> POINTS
    @@ -48,8 +49,7 @@ <h2></h2>
    l[i] & 8 && //if found a ghost then
    g.push({ //append to the array of ghosts
    x: i, //ghost position
    d: 0, //ghost walking direction (0 = north)
    b: 0 //backup item from ghost position
    d: 0 //ghost walking direction (0 = north)
    });
    if (l[i] & 1) l.x = i; //store player position
    l.c += l[i++] == 2 //count gold
    @@ -70,11 +70,12 @@ <h2></h2>
    src = t[i].replace(/.*"(.*)".*/, f)
    }
    }
    // 82 bytes
    // 88 bytes
    var renderLevel = function(l, t) //level object, optional theme object
    {
    for (var h = '', x = 0; x < l.length; x++)
    h += t && t[l[x]] ? t[l[x]] : l[x]; //use theme or original character (e.g. the newline)
    for (var c, h = '', x = 0; x < l.length; x++)
    h += t && t[c = l[x] & 8 || l[x]] //ghosts can sit on gold, render the ghost only
    ? t[c] : c; //use theme or original character (e.g. the newline)
    return h
    }
    // 129 bytes
    @@ -85,22 +86,21 @@ <h2></h2>
    l.e |= l[l.x] & 8;
    l[l.x] = 1
    }
    // 152 bytes
    // 135 bytes
    var updateGhosts = function(a, l, g, d)
    {
    for (g = a.length; g--; ) //backup is forward, restore must be reverse
    l[a[g].x] = a[g].b; //restore item
    for (g in a)
    l[a[g].x] &= ~8; //restore item
    for (g in a)
    {
    g = a[g];
    d = g.d % 4;
    d = d % 2 ? d - 2 : (d - 1) * l.w; //calculate walking direction
    l[g.x + d] & 4 //if walking into a wall
    ? g.d++ //rotate ghost by 90 degree
    : l.e |= 1 & ( //else check if hitting the player
    g.b = l[ //and backup item from ghost position
    g.x += d]); //and walk
    l[g.x] = 8
    : l.e |= 1 & l[ //else check if hitting the player
    g.x += d]; //and walk
    l[g.x] |= 8
    }
    }
    var levels = [parseLevel([
  3. @maettig maettig revised this gist Jan 16, 2012. 1 changed file with 4 additions and 3 deletions.
    7 changes: 4 additions & 3 deletions test.html
    Original file line number Diff line number Diff line change
    @@ -85,13 +85,14 @@ <h2></h2>
    l.e |= l[l.x] & 8;
    l[l.x] = 1
    }
    // 136 bytes
    // 152 bytes
    var updateGhosts = function(a, l, g, d)
    {
    for (g in a.reverse()) //backup is forward, restore must be reverse
    for (g = a.length; g--; ) //backup is forward, restore must be reverse
    l[a[g].x] = a[g].b; //restore item
    for (g in a)
    {
    g = a[g];
    l[g.x] = g.b; //restore item
    d = g.d % 4;
    d = d % 2 ? d - 2 : (d - 1) * l.w; //calculate walking direction
    l[g.x + d] & 4 //if walking into a wall
  4. @maettig maettig revised this gist Jan 2, 2012. 3 changed files with 133 additions and 47 deletions.
    2 changes: 1 addition & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    A simple variation of the Pac-Man game almost completely made with [140byt.es](http://140byt.es/) snippets. Collect all points to win the game. Avoid the ghost.
    An oldskool remake of the classic arcade game Pac-Man almost completely made with [140 bytes](http://140byt.es/) snippets. Collect all points in all six levels to win the game. Avoid the ghosts. [Click here to play the game](http://maettig.com/code/javascript/pac-man-in-140byt.es.html).

    My `getFirstElement` is based on @jed's [cssSelect](https://gist.github.com/991057). Everything else is created from scratch. Tested with Opera, Firefox and Internet Explorer 8.

    2 changes: 1 addition & 1 deletion package.json
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    {
    "name": "pacMan",

    "description": "Pac-Man made with 140byte.es snippets.",
    "description": "Pac-Man made with 140 bytes snippets.",

    "keywords": [
    "game",
    176 changes: 131 additions & 45 deletions test.html
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    <!DOCTYPE HTML>
    <!DOCTYPE html>
    <pre>LOADING...</pre>
    <h2></h2>
    <span id="points">0</span> POINTS
    @@ -9,16 +9,16 @@ <h2></h2>
    img { border: 0; font-size: 32px; height: 32px; padding: 1px; vertical-align: top; width: 32px; }
    pre { font-size: 58px; line-height: 32px; margin: 0; }
    #points { font-size: 2em; line-height: 2em; }
    .air { color: #222; text-shadow: 0 0 .2em #222; }
    .air { color: #222; text-shadow: 0 0 .2em #222; }
    .player { color: #FD0; text-shadow: 0 0 .2em #FD0; }
    .wall { color: #30F; text-shadow: 0 0 .2em #30F; }
    .ghost { color: #A0F; text-shadow: 0 0 .2em #A0F; }
    .wall { color: #30F; text-shadow: 0 0 .2em #30F; }
    .ghost { color: #A0F; text-shadow: 0 0 .2em #A0F; }
    </style>
    <script type="text/javascript">
    // 138 bytes
    var getFirstElement = function(a)
    {
    a = /([#.]?)(.*)/.exec(a||'*');
    a = /([#.]?)(.*)/.exec(a || '*');
    a = document['getElement' + (a[1] > '-' ? 'sByClassName' : a[1] ? 'ById' : 'sByTagName')](a[2]);
    return a[0] || a
    }
    @@ -27,18 +27,35 @@ <h2></h2>
    {
    return a.outerHTML || XMLSerializer().serializeToString(a)
    }
    // 131 bytes
    var parseLevel = function(l, w, c)
    // 126 bytes
    var parseLevel = function(l, w)
    {
    l = l.join ? l.join('\n') : l; //if it's an Array of rows
    l = l.join ? l[0].length > 1 //if it's an array of strings per row
    ? l.join('\n') : l.join('') : l; //then join rows else join characters
    w = l.indexOf('\n') + 1; //calculate row length
    c = l.split(2).length - 1; //count gold
    // It would be possible to calculate player position with `l.indexOf(1)` but that's 7 bytes longer.
    // It would be possible to count gold with `l.split(2).length - 1` but that's 11 bytes longer.
    l = l.split(''); //convert to character array
    l.w = w; //store width
    l.c = c; //store gold count
    l.d = l.p = l.a = 0; //initialize player walking direction, points, ghosts angle
    l.c = l.d = l.p = 0; //initialize gold count, player walking direction, points
    return l
    }
    // 110 bytes
    var initLevel = function(l)
    {
    for (var i = g = []; i < l.length; )
    {
    l[i] & 8 && //if found a ghost then
    g.push({ //append to the array of ghosts
    x: i, //ghost position
    d: 0, //ghost walking direction (0 = north)
    b: 0 //backup item from ghost position
    });
    if (l[i] & 1) l.x = i; //store player position
    l.c += l[i++] == 2 //count gold
    }
    return g
    }
    // 136 bytes
    var loadSprites = function(t, f) //theme, filename with $1 placeholder
    {
    @@ -53,15 +70,11 @@ <h2></h2>
    src = t[i].replace(/.*"(.*)".*/, f)
    }
    }
    // 115 bytes
    // 82 bytes
    var renderLevel = function(l, t) //level object, optional theme object
    {
    for (var h = '', x = 0; x < l.length; x++)
    {
    if (l[x] & 1) l.x = x; //store player position
    if (l[x] & 8) l.g = x; //store ghost position
    h += t && t[l[x]] ? t[l[x]] : l[x] //use theme or original character (e.g. the newline)
    }
    h += t && t[l[x]] ? t[l[x]] : l[x]; //use theme or original character (e.g. the newline)
    return h
    }
    // 129 bytes
    @@ -72,31 +85,95 @@ <h2></h2>
    l.e |= l[l.x] & 8;
    l[l.x] = 1
    }
    // 109 bytes
    var updateGhost = function(l, d)
    // 136 bytes
    var updateGhosts = function(a, l, g, d)
    {
    l[l.g] = l.o || 0; //remove ghost, place backup item
    d = l.a % 4;
    d = d % 2 ? d - 2 : (d - 1) * l.w; //calculate walking direction
    l[l.g + d] & 4 //if walking into a wall
    ? l.a++ //rotate ghost by 90 degree
    : l.g += d; //else walk
    l.e |= (l.o = l[l.g]) //backup item from ghost position
    & 1; //check if hitting the player
    l[l.g] = 8 //place ghost
    for (g in a.reverse()) //backup is forward, restore must be reverse
    {
    g = a[g];
    l[g.x] = g.b; //restore item
    d = g.d % 4;
    d = d % 2 ? d - 2 : (d - 1) * l.w; //calculate walking direction
    l[g.x + d] & 4 //if walking into a wall
    ? g.d++ //rotate ghost by 90 degree
    : l.e |= 1 & ( //else check if hitting the player
    g.b = l[ //and backup item from ghost position
    g.x += d]); //and walk
    l[g.x] = 8
    }
    }
    var level = parseLevel(
    '4444444444444444444\n' +
    '4222242222222422224\n' +
    '4244242444442424424\n' +
    '4242222222222222424\n' +
    '4242442440442442424\n' +
    '4222222408042222224\n' +
    '4242442444442442424\n' +
    '4242222221222222424\n' +
    '4244242444442424424\n' +
    '4222242222222422224\n' +
    '4444444444444444444');
    var levels = [parseLevel([
    '44444444444', //no ghosts
    '42222222224',
    '42444242424',
    '42412242424',
    '42444242424',
    '42222242224',
    '44444444444']),
    parseLevel([
    '4444444444444', //1 ghost
    '4222224222224',
    '4244424244424',
    '4242228222424',
    '4242424442424',
    '4242421242424',
    '4242444242424',
    '4242222222424',
    '4244424244424',
    '4222224222224',
    '4444444444444']),
    parseLevel([
    '444444444444444', //2 ghosts
    '424222222222224',
    '424244444242444',
    '422222222222224',
    '424244444242424',
    '424242212242424',
    '424242444442424',
    '422222222222224',
    '444242444442424',
    '482222222222484',
    '444444444444444']),
    parseLevel([
    '4444444444444444444', //classic with 2 ghosts
    '4222242228222422224',
    '4244242444442424424',
    '4242222222222222424',
    '4242442440442442424',
    '4222222408042222224',
    '4242442444442442424',
    '4242222221222222424',
    '4244242444442424424',
    '4222242222222422224',
    '4444444444444444444']),
    parseLevel([
    '444444444444444', //3 ghosts
    '422222282222224',
    '424444424444424',
    '424222424822424',
    '424242424242424',
    '422242212242224',
    '424242424242424',
    '424228424222424',
    '424444424444424',
    '422222222222224',
    '444444444444444']),
    parseLevel([
    '4444444444444444444', //5 ghosts
    '4222222248222222224',
    '4244444242444442444',
    '4242222282222222224',
    '4242444442444442424',
    '4242422242482222424',
    '4242424242424244424',
    '4222222222222228224',
    '4244424242424242424',
    '4242222842422242424',
    '4242444442444442424',
    '4222222222222222424',
    '4442444442424444424',
    '4222222122422222224',
    '4444444444444444444'])];
    var theme = {
    0: '<span class="air">\u2219</span>', //doesn't need to be checked
    1: '<span class="player">\u263B</span>', //can be checked with &1
    @@ -110,14 +187,23 @@ <h2></h2>
    {
    level.keyCode = (e || window.event).keyCode
    }
    renderLevel(level); //dummy call to get player and ghost positions
    var ghosts, level, number = 0;
    window.setInterval(function()
    {
    !level.e && level.p < level.c && ( //stop updating when lost or won
    updatePlayer(level, level.keyCode || 0),
    updateGhost(level));
    if (!level && levels[number])
    ghosts = initLevel(level = levels[number++]);
    if (level.p >= level.c)
    {
    if (level.p < level.c-- + 4) //wait a few moments before loading next level
    return;
    level = 0 //unload current level when won
    }
    if (!level || level.e) //stop updating when lost or won
    return;
    updatePlayer(level, level.keyCode || 0);
    updateGhosts(ghosts, level);
    getFirstElement('PRE').innerHTML = renderLevel(level, theme);
    getFirstElement('#points').innerHTML = level.p;
    getFirstElement('H2').innerHTML = level.e ? 'GAME OVER!' : level.p < level.c ? '' : 'YOU WIN!'
    }, 250)
    }, 250);
    </script>
  5. @maettig maettig revised this gist Dec 9, 2011. 1 changed file with 4 additions and 4 deletions.
    8 changes: 4 additions & 4 deletions test.html
    Original file line number Diff line number Diff line change
    @@ -1,14 +1,14 @@
    <!DOCTYPE HTML>
    <pre>LOADING...</pre>
    <h2></h2>
    <span>0</span> POINTS
    <span id="points">0</span> POINTS
    <style type="text/css">
    * { color: #FFF; font-family: Consolas, monospace; text-shadow: 0 0 .2em #FFF; }
    body { background: #000; margin: 4em; }
    h2 { font-size: 3em; margin: .2em 0; }
    img { border: 0; font-size: 32px; height: 32px; padding: 1px; vertical-align: top; width: 32px; }
    pre { font-size: 58px; line-height: 32px; margin: 0; }
    span { font-size: 2em; line-height: 2em; }
    #points { font-size: 2em; line-height: 2em; }
    .air { color: #222; text-shadow: 0 0 .2em #222; }
    .player { color: #FD0; text-shadow: 0 0 .2em #FD0; }
    .wall { color: #30F; text-shadow: 0 0 .2em #30F; }
    @@ -117,7 +117,7 @@ <h2></h2>
    updatePlayer(level, level.keyCode || 0),
    updateGhost(level));
    getFirstElement('PRE').innerHTML = renderLevel(level, theme);
    getFirstElement('SPAN').innerHTML = level.p;
    getFirstElement('H2').innerHTML = level.e ? 'GAME OVER!' : level.p < level.c ? '' : 'YOU WIN!';
    getFirstElement('#points').innerHTML = level.p;
    getFirstElement('H2').innerHTML = level.e ? 'GAME OVER!' : level.p < level.c ? '' : 'YOU WIN!'
    }, 250)
    </script>
  6. @maettig maettig revised this gist Dec 1, 2011. 1 changed file with 9 additions and 11 deletions.
    20 changes: 9 additions & 11 deletions test.html
    Original file line number Diff line number Diff line change
    @@ -14,7 +14,7 @@ <h2></h2>
    .wall { color: #30F; text-shadow: 0 0 .2em #30F; }
    .ghost { color: #A0F; text-shadow: 0 0 .2em #A0F; }
    </style>
    <script>
    <script type="text/javascript">
    // 138 bytes
    var getFirstElement = function(a)
    {
    @@ -53,14 +53,14 @@ <h2></h2>
    src = t[i].replace(/.*"(.*)".*/, f)
    }
    }
    // 112 bytes
    var renderLevel = function(l, t) //level object, theme object
    // 115 bytes
    var renderLevel = function(l, t) //level object, optional theme object
    {
    for (var h = '', x = 0; x < l.length; x++)
    {
    if (l[x] & 1) l.x = x; //store player position
    if (l[x] & 8) l.g = x; //store ghost position
    h += t[l[x]] ? t[l[x]] : l[x] //theme is optional
    h += t && t[l[x]] ? t[l[x]] : l[x] //use theme or original character (e.g. the newline)
    }
    return h
    }
    @@ -110,16 +110,14 @@ <h2></h2>
    {
    level.keyCode = (e || window.event).keyCode
    }
    renderLevel(level); //dummy call to get player and ghost positions
    window.setInterval(function()
    {
    !level.e && level.p < level.c && ( //stop updating when lost or won
    updatePlayer(level, level.keyCode || 0),
    updateGhost(level));
    getFirstElement('PRE').innerHTML = renderLevel(level, theme);
    getFirstElement('SPAN').innerHTML = level.p;
    if (level.e || level.p == level.c)
    {
    getFirstElement('H2').innerHTML = level.e ? 'GAME OVER!' : 'YOU WIN!';
    return;
    }
    updatePlayer(level, level.keyCode || 0);
    updateGhost(level)
    getFirstElement('H2').innerHTML = level.e ? 'GAME OVER!' : level.p < level.c ? '' : 'YOU WIN!';
    }, 250)
    </script>
  7. @maettig maettig revised this gist Nov 30, 2011. 2 changed files with 12 additions and 10 deletions.
    6 changes: 4 additions & 2 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,5 @@
    A simple variation of the Pac-Man game almost completely made with [140byt.es](http://140byt.es/) snippets.
    A simple variation of the Pac-Man game almost completely made with [140byt.es](http://140byt.es/) snippets. Collect all points to win the game. Avoid the ghost.

    My `getFirstElement` is based on @jed's [cssSelect](https://gist.github.com/991057). Everything else is created from scratch. Tested with Opera, Firefox and Internet Explorer 8.
    My `getFirstElement` is based on @jed's [cssSelect](https://gist.github.com/991057). Everything else is created from scratch. Tested with Opera, Firefox and Internet Explorer 8.

    Optional graphics are supported and [can be downloaded here](http://maettig.com/code/javascript/pac-man-in-140byt.es.zip).
    16 changes: 8 additions & 8 deletions test.html
    Original file line number Diff line number Diff line change
    @@ -1,18 +1,18 @@
    <!DOCTYPE HTML>
    <pre>LOADING...</pre>
    <h2 id="end"></h2>
    <span id="points">0</span> POINTS
    <h2></h2>
    <span>0</span> POINTS
    <style type="text/css">
    * { color: #FFF; font-family: Consolas, monospace; text-shadow: 0 0 .2em #FFF; }
    body { background: #000; margin: 4em; }
    pre { font-size: 58px; line-height: 32px; margin: 0; }
    img { border: 0; font-size: 32px; height: 32px; padding: 1px; vertical-align: top; width: 32px; }
    h2 { font-size: 3em; margin: .2em 0; }
    img { border: 0; font-size: 32px; height: 32px; padding: 1px; vertical-align: top; width: 32px; }
    pre { font-size: 58px; line-height: 32px; margin: 0; }
    span { font-size: 2em; line-height: 2em; }
    .air { color: #222; text-shadow: 0 0 .2em #222; }
    .player { color: #FD0; text-shadow: 0 0 .2em #FD0; }
    .wall { color: #30F; text-shadow: 0 0 .2em #30F; }
    .ghost { color: #A0F; text-shadow: 0 0 .2em #A0F; }
    .player { color: #FD0; text-shadow: 0 0 .2em #FD0; }
    #points { font-size: 2em; line-height: 2em; }
    </style>
    <script>
    // 138 bytes
    @@ -113,10 +113,10 @@ <h2 id="end"></h2>
    window.setInterval(function()
    {
    getFirstElement('PRE').innerHTML = renderLevel(level, theme);
    getFirstElement('#points').innerHTML = level.p;
    getFirstElement('SPAN').innerHTML = level.p;
    if (level.e || level.p == level.c)
    {
    getFirstElement('#end').innerHTML = level.e ? 'GAME OVER!' : 'YOU WIN!';
    getFirstElement('H2').innerHTML = level.e ? 'GAME OVER!' : 'YOU WIN!';
    return;
    }
    updatePlayer(level, level.keyCode || 0);
  8. @maettig maettig revised this gist Nov 30, 2011. 4 changed files with 115 additions and 65 deletions.
    2 changes: 1 addition & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,3 @@
    A simple variation of the Pac-Man game almost completely made with [140byt.es](http://140byt.es/) snippets.

    My `getFirstElement` is based on @jed's [cssSelect](https://gist.github.com/991057). Everything else is created from scratch. Tested with Opera and Firefox. Does not work in Internet Explorer.
    My `getFirstElement` is based on @jed's [cssSelect](https://gist.github.com/991057). Everything else is created from scratch. Tested with Opera, Firefox and Internet Explorer 8.
    35 changes: 19 additions & 16 deletions annotated.js
    Original file line number Diff line number Diff line change
    @@ -1,18 +1,21 @@
    function(l, k) //level object, keyCode
    function(l, k) //level object, keyCode
    {
    l[l.x] = ' '; //remove player from level
    l.d = k - 37 >> 2 || //if no cursor key was pressed or
    l[l.x + ( //check new position
    k = k % 2 //calculate new walking direction
    ? k - 38 //-1 is left, +1 is right
    : (k - 39) * l.w //-width is up, +width is down
    )] == '#' //if it's not possible to use new direction
    ? l[l.x + l.d //then check old direction
    ] == '#' //if it's a wall
    ? 0 //stop
    : l.d //else use old direction
    : k; //else use new direction
    l.p += l[l.x += l.d //walk
    ] == '.'; //and increase points
    l[l.x] = 'P' //place player in level
    l[l.x] = 0; //remove player from level
    l.p += l[ //increase points
    l.x += //walk
    l.d = //calculate walking direction
    k - 37 >> 2 || //if no cursor key was pressed or
    l[l.x + ( //check new position
    k = k % 2 //calculate new walking direction
    ? k - 38 //-1 is left, +1 is right
    : (k - 39) * l.w //-width is up, +width is down
    )] & 4 //if it's not possible to use new direction
    ? l[l.x + l.d //then check old direction
    ] & 4 //if it's a wall
    ? 0 //stop
    : l.d //else use old direction
    : k //else use new direction
    ] == 2; //if walking into some gold
    l.e |= l[l.x] & 8;
    l[l.x] = 1 //place player in level
    }
    2 changes: 1 addition & 1 deletion index.js
    Original file line number Diff line number Diff line change
    @@ -1 +1 @@
    function(l,k){l[l.x]=' ';l.d=k-37>>2||l[l.x+(k=k%2?k-38:(k-39)*l.w)]=='#'?l[l.x+l.d]=='#'?0:l.d:k;l.p+=l[l.x+=l.d]=='.';l[l.x]='P'}
    function(l,k){l[l.x]=0;l.p+=l[l.x+=l.d=k-37>>2||l[l.x+(k=k%2?k-38:(k-39)*l.w)]&4?l[l.x+l.d]&4?0:l.d:k]==2;l.e|=l[l.x]&8;l[l.x]=1}
    141 changes: 94 additions & 47 deletions test.html
    Original file line number Diff line number Diff line change
    @@ -1,12 +1,17 @@
    <!DOCTYPE HTML>
    <pre>Loading...</pre>
    <span id="points">0</span> points
    <pre>LOADING...</pre>
    <h2 id="end"></h2>
    <span id="points">0</span> POINTS
    <style type="text/css">
    body { background: #000; color: #FFF; font-family: Consolas, monospace; margin: 4em; text-shadow: 0 0 0.2em #FFF; }
    pre { font-size: 4em; line-height: 0.55em; margin: 0; }
    .air { color: #222; text-shadow: 0 0 0.2em #222; }
    .wall { color: #30F; text-shadow: 0 0 0.2em #30F; }
    .player { color: #FE0; text-shadow: 0 0 0.2em #FE0; }
    * { color: #FFF; font-family: Consolas, monospace; text-shadow: 0 0 .2em #FFF; }
    body { background: #000; margin: 4em; }
    pre { font-size: 58px; line-height: 32px; margin: 0; }
    img { border: 0; font-size: 32px; height: 32px; padding: 1px; vertical-align: top; width: 32px; }
    h2 { font-size: 3em; margin: .2em 0; }
    .air { color: #222; text-shadow: 0 0 .2em #222; }
    .wall { color: #30F; text-shadow: 0 0 .2em #30F; }
    .ghost { color: #A0F; text-shadow: 0 0 .2em #A0F; }
    .player { color: #FD0; text-shadow: 0 0 .2em #FD0; }
    #points { font-size: 2em; line-height: 2em; }
    </style>
    <script>
    @@ -17,62 +22,104 @@
    a = document['getElement' + (a[1] > '-' ? 'sByClassName' : a[1] ? 'ById' : 'sByTagName')](a[2]);
    return a[0] || a
    }
    // 97 bytes, maybe use the remaining 43 bytes to make this more flexible?
    var parseLevel = function(l, w)
    // 69 bytes
    var getOuterHTML = function(a)
    {
    l = l.join ? l.join('\n') : l; //if it's an Array of rows
    w = l.indexOf('\n') + 1; //calculate row length
    l = l.split(''); //convert to character array
    l.w = w; //width
    l.d = l.p = 0; //walking direction and points
    return a.outerHTML || XMLSerializer().serializeToString(a)
    }
    // 131 bytes
    var parseLevel = function(l, w, c)
    {
    l = l.join ? l.join('\n') : l; //if it's an Array of rows
    w = l.indexOf('\n') + 1; //calculate row length
    c = l.split(2).length - 1; //count gold
    l = l.split(''); //convert to character array
    l.w = w; //store width
    l.c = c; //store gold count
    l.d = l.p = l.a = 0; //initialize player walking direction, points, ghosts angle
    return l
    }
    // 138 bytes
    var renderLevel = function(l, t) //level and theme objects
    // 136 bytes
    var loadSprites = function(t, f) //theme, filename with $1 placeholder
    {
    for (var h = '', g = x = 0; x < l.length; x++)
    for (var i in t)
    with (new Image()) //new is required in IE
    {
    alt = i;
    onload = function()
    {
    t[this.alt] = getOuterHTML(this)
    }
    src = t[i].replace(/.*"(.*)".*/, f)
    }
    }
    // 112 bytes
    var renderLevel = function(l, t) //level object, theme object
    {
    for (var h = '', x = 0; x < l.length; x++)
    {
    g += l[x] == '.'; //count gold
    if (l[x] == 'P') l.x = x; //store player position
    h += t[l[x]] ? t[l[x]] : l[x] //theme is optional
    if (l[x] & 1) l.x = x; //store player position
    if (l[x] & 8) l.g = x; //store ghost position
    h += t[l[x]] ? t[l[x]] : l[x] //theme is optional
    }
    if (!g) h += '\n\nYou win!';
    return h
    }
    // 131 bytes
    var updateLevel = function(l, k)
    // 129 bytes
    var updatePlayer = function(l, k)
    {
    l[l.x] = ' ';
    l.d = k - 37 >> 2 || l[l.x + (k = k % 2 ? k - 38 : (k - 39) * l.w)] == '#' ? l[l.x + l.d] == '#' ? 0 : l.d : k;
    l.p += l[l.x += l.d] == '.';
    l[l.x] = 'P'
    l[l.x] = 0;
    l.p += l[l.x += l.d = k - 37 >> 2 || l[l.x + (k = k % 2 ? k - 38 : (k - 39) * l.w)] & 4 ? l[l.x + l.d] & 4 ? 0 : l.d : k] == 2;
    l.e |= l[l.x] & 8;
    l[l.x] = 1
    }
    // 109 bytes
    var updateGhost = function(l, d)
    {
    l[l.g] = l.o || 0; //remove ghost, place backup item
    d = l.a % 4;
    d = d % 2 ? d - 2 : (d - 1) * l.w; //calculate walking direction
    l[l.g + d] & 4 //if walking into a wall
    ? l.a++ //rotate ghost by 90 degree
    : l.g += d; //else walk
    l.e |= (l.o = l[l.g]) //backup item from ghost position
    & 1; //check if hitting the player
    l[l.g] = 8 //place ghost
    }
    var theme = {
    ' ': '<span class="air">\u2219</span>',
    '.': '<span class="gold">\u2219</span>',
    '#': '<span class="wall">\u25A1</span>',
    'P': '<span class="player">\u263B</span>'
    };
    var level = parseLevel(
    '###################\n' +
    '#....#.......#....#\n' +
    '#.##.#.#####.#.##.#\n' +
    '#.#.............#.#\n' +
    '#.#.##.##.##.##.#.#\n' +
    '#......#...#......#\n' +
    '#.#.##.#####.##.#.#\n' +
    '#.#......P......#.#\n' +
    '#.##.#.#####.#.##.#\n' +
    '#....#.......#....#\n' +
    '###################');
    window.onkeydown = function(e)
    '4444444444444444444\n' +
    '4222242222222422224\n' +
    '4244242444442424424\n' +
    '4242222222222222424\n' +
    '4242442440442442424\n' +
    '4222222408042222224\n' +
    '4242442444442442424\n' +
    '4242222221222222424\n' +
    '4244242444442424424\n' +
    '4222242222222422224\n' +
    '4444444444444444444');
    var theme = {
    0: '<span class="air">\u2219</span>', //doesn't need to be checked
    1: '<span class="player">\u263B</span>', //can be checked with &1
    2: '<span class="gold">\u2219</span>', //can be checked with &2
    4: '<span class="wall">\u25A1</span>', //can be checked with &4
    8: '<span class="ghost">\u00A4</span>', //can be checked with &8 or >7
    '\n': '<br>' //required for IE
    }
    loadSprites(theme, 'sprite-$1.gif'); //load optional GIF files from the same directory
    document.onkeydown = function(e)
    {
    level.keyCode = (e || window.event).keyCode;
    level.keyCode = (e || window.event).keyCode
    }
    window.setInterval(function()
    {
    getFirstElement('PRE').innerHTML = renderLevel(level, theme);
    getFirstElement('#points').innerHTML = level.p;
    updateLevel(level, level.keyCode || 0);
    if (level.e || level.p == level.c)
    {
    getFirstElement('#end').innerHTML = level.e ? 'GAME OVER!' : 'YOU WIN!';
    return;
    }
    updatePlayer(level, level.keyCode || 0);
    updateGhost(level)
    }, 250)
    </script>
  9. @maettig maettig revised this gist Nov 23, 2011. 4 changed files with 17 additions and 17 deletions.
    2 changes: 1 addition & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,3 @@
    A simple variation of the Pac-Man game (almost) made with [140byt.es](http://140byt.es/) snippets.
    A simple variation of the Pac-Man game almost completely made with [140byt.es](http://140byt.es/) snippets.

    My `getFirstElement` is based on @jed's [cssSelect](https://gist.github.com/991057). Everything else is created from scratch. Tested with Opera and Firefox. Does not work in Internet Explorer.
    19 changes: 11 additions & 8 deletions annotated.js
    Original file line number Diff line number Diff line change
    @@ -1,14 +1,17 @@
    function(l, k) //level object, keyCode
    {
    l[l.x] = ' '; //remove player from level
    if (l[l.x + l.d] == '#') //check if previous walking direction is possible
    l.d = 0; //stop
    if (k > 36 && k < 41 && //check if a cursor key was pressed
    l[l.x + (k = k % 2 //calculate walking direction
    ? k - 38 //-1 is left, +1 is right
    : (k - 39) * l.w //-width is up, +width is down
    )] != '#') //check if not walking into a wall
    l.d = k; //set new walking direction
    l.d = k - 37 >> 2 || //if no cursor key was pressed or
    l[l.x + ( //check new position
    k = k % 2 //calculate new walking direction
    ? k - 38 //-1 is left, +1 is right
    : (k - 39) * l.w //-width is up, +width is down
    )] == '#' //if it's not possible to use new direction
    ? l[l.x + l.d //then check old direction
    ] == '#' //if it's a wall
    ? 0 //stop
    : l.d //else use old direction
    : k; //else use new direction
    l.p += l[l.x += l.d //walk
    ] == '.'; //and increase points
    l[l.x] = 'P' //place player in level
    2 changes: 1 addition & 1 deletion index.js
    Original file line number Diff line number Diff line change
    @@ -1 +1 @@
    function(l,k){l[l.x]=' ';if(l[l.x+l.d]=='#')l.d=0;if(k>36&&k<41&&l[l.x+(k=k%2?k-38:(k-39)*l.w)]!='#')l.d=k;l.p+=l[l.x+=l.d]=='.';l[l.x]='P'}
    function(l,k){l[l.x]=' ';l.d=k-37>>2||l[l.x+(k=k%2?k-38:(k-39)*l.w)]=='#'?l[l.x+l.d]=='#'?0:l.d:k;l.p+=l[l.x+=l.d]=='.';l[l.x]='P'}
    11 changes: 4 additions & 7 deletions test.html
    Original file line number Diff line number Diff line change
    @@ -13,7 +13,7 @@
    // 138 bytes
    var getFirstElement = function(a)
    {
    a = /([#.]?)(.*)/.exec(a || '*');
    a = /([#.]?)(.*)/.exec(a||'*');
    a = document['getElement' + (a[1] > '-' ? 'sByClassName' : a[1] ? 'ById' : 'sByTagName')](a[2]);
    return a[0] || a
    }
    @@ -39,14 +39,11 @@
    if (!g) h += '\n\nYou win!';
    return h
    }
    // 140 bytes
    // 131 bytes
    var updateLevel = function(l, k)
    {
    l[l.x] = ' ';
    if (l[l.x + l.d] == '#')
    l.d = 0;
    if (k > 36 && k < 41 && l[l.x + (k = k % 2 ? k - 38 : (k - 39) * l.w)] != '#')
    l.d = k;
    l.d = k - 37 >> 2 || l[l.x + (k = k % 2 ? k - 38 : (k - 39) * l.w)] == '#' ? l[l.x + l.d] == '#' ? 0 : l.d : k;
    l.p += l[l.x += l.d] == '.';
    l[l.x] = 'P'
    }
    @@ -76,6 +73,6 @@
    {
    getFirstElement('PRE').innerHTML = renderLevel(level, theme);
    getFirstElement('#points').innerHTML = level.p;
    updateLevel(level, level.keyCode);
    updateLevel(level, level.keyCode || 0);
    }, 250)
    </script>
  10. @maettig maettig revised this gist Nov 23, 2011. 1 changed file with 14 additions and 15 deletions.
    29 changes: 14 additions & 15 deletions test.html
    Original file line number Diff line number Diff line change
    @@ -6,36 +6,35 @@
    pre { font-size: 4em; line-height: 0.55em; margin: 0; }
    .air { color: #222; text-shadow: 0 0 0.2em #222; }
    .wall { color: #30F; text-shadow: 0 0 0.2em #30F; }
    .player { color: #FF0; text-shadow: 0 0 0.2em #FF0; }
    .player { color: #FE0; text-shadow: 0 0 0.2em #FE0; }
    #points { font-size: 2em; line-height: 2em; }
    </style>
    <script>
    // 144 bytes, any idea how to save 4 bytes?
    // 138 bytes
    var getFirstElement = function(a)
    {
    a = /(\W?)(.*)/.exec(a);
    return a[1] == '#'
    ? document.getElementById(a[2])
    : document['getElementsBy' + (a[1] ? 'Class' : 'Tag') + 'Name'](a[2])[0]
    a = /([#.]?)(.*)/.exec(a || '*');
    a = document['getElement' + (a[1] > '-' ? 'sByClassName' : a[1] ? 'ById' : 'sByTagName')](a[2]);
    return a[0] || a
    }
    // 97 bytes, maybe use the remaining 43 bytes to make this more flexible?
    var parseLevel = function(l, w)
    {
    l = l.join ? l.join('\n') : l;
    w = l.indexOf('\n') + 1;
    l = l.split('');
    l.w = w;
    l.d = l.p = 0;
    l = l.join ? l.join('\n') : l; //if it's an Array of rows
    w = l.indexOf('\n') + 1; //calculate row length
    l = l.split(''); //convert to character array
    l.w = w; //width
    l.d = l.p = 0; //walking direction and points
    return l
    }
    // 138 bytes
    var renderLevel = function(l, t)
    var renderLevel = function(l, t) //level and theme objects
    {
    for (var h = '', g = x = 0; x < l.length; x++)
    {
    g += l[x] == '.';
    if (l[x] == 'P') l.x = x;
    h += t[l[x]] ? t[l[x]] : l[x]
    g += l[x] == '.'; //count gold
    if (l[x] == 'P') l.x = x; //store player position
    h += t[l[x]] ? t[l[x]] : l[x] //theme is optional
    }
    if (!g) h += '\n\nYou win!';
    return h
  11. @maettig maettig revised this gist Nov 22, 2011. 4 changed files with 16 additions and 15 deletions.
    2 changes: 1 addition & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,3 @@
    A simple variation of the Pac-Man game (almost) made with [140byt.es](http://140byt.es/) snippets.

    My `setInnerHTML` uses tricks learned from @jed's [cssSelect](https://gist.github.com/991057). Everything else is created from scratch. Tested with Opera and Firefox. Does not work in Internet Explorer 8.
    My `getFirstElement` is based on @jed's [cssSelect](https://gist.github.com/991057). Everything else is created from scratch. Tested with Opera and Firefox. Does not work in Internet Explorer.
    4 changes: 2 additions & 2 deletions annotated.js
    Original file line number Diff line number Diff line change
    @@ -1,12 +1,12 @@
    function(l, k, w) //level, keyCode, level width
    function(l, k) //level object, keyCode
    {
    l[l.x] = ' '; //remove player from level
    if (l[l.x + l.d] == '#') //check if previous walking direction is possible
    l.d = 0; //stop
    if (k > 36 && k < 41 && //check if a cursor key was pressed
    l[l.x + (k = k % 2 //calculate walking direction
    ? k - 38 //-1 is left, +1 is right
    : (k - 39) * w //-width is up, +width is down
    : (k - 39) * l.w //-width is up, +width is down
    )] != '#') //check if not walking into a wall
    l.d = k; //set new walking direction
    l.p += l[l.x += l.d //walk
    2 changes: 1 addition & 1 deletion index.js
    Original file line number Diff line number Diff line change
    @@ -1 +1 @@
    function(l,k,w){l[l.x]=' ';if(l[l.x+l.d]=='#')l.d=0;if(k>36&&k<41&&l[l.x+(k=k%2?k-38:(k-39)*w)]!='#')l.d=k;l.p+=l[l.x+=l.d]=='.';l[l.x]='P'}
    function(l,k){l[l.x]=' ';if(l[l.x+l.d]=='#')l.d=0;if(k>36&&k<41&&l[l.x+(k=k%2?k-38:(k-39)*l.w)]!='#')l.d=k;l.p+=l[l.x+=l.d]=='.';l[l.x]='P'}
    23 changes: 12 additions & 11 deletions test.html
    Original file line number Diff line number Diff line change
    @@ -10,14 +10,13 @@
    #points { font-size: 2em; line-height: 2em; }
    </style>
    <script>
    // 153 bytes, any idea how to save 13 bytes?
    var setInnerHTML = function(a, h)
    // 144 bytes, any idea how to save 4 bytes?
    var getFirstElement = function(a)
    {
    a = /(\W?)(.*)/.exec(a);
    (a[1] == '#'
    return a[1] == '#'
    ? document.getElementById(a[2])
    : document['getElementsBy' + (a[1] ? 'Class' : 'Tag') + 'Name'](a[2])[0]
    ).innerHTML = h
    }
    // 97 bytes, maybe use the remaining 43 bytes to make this more flexible?
    var parseLevel = function(l, w)
    @@ -29,23 +28,25 @@
    l.d = l.p = 0;
    return l
    }
    // 99 bytes, should be enough to add a "you won" screen.
    // 138 bytes
    var renderLevel = function(l, t)
    {
    for (var h = '', x = 0; x < l.length; x++)
    for (var h = '', g = x = 0; x < l.length; x++)
    {
    g += l[x] == '.';
    if (l[x] == 'P') l.x = x;
    h += t[l[x]] ? t[l[x]] : l[x]
    }
    if (!g) h += '\n\nYou win!';
    return h
    }
    // 140 bytes
    var updateLevel = function(l, k, w)
    var updateLevel = function(l, k)
    {
    l[l.x] = ' ';
    if (l[l.x + l.d] == '#')
    l.d = 0;
    if (k > 36 && k < 41 && l[l.x + (k = k % 2 ? k - 38 : (k - 39) * w)] != '#')
    if (k > 36 && k < 41 && l[l.x + (k = k % 2 ? k - 38 : (k - 39) * l.w)] != '#')
    l.d = k;
    l.p += l[l.x += l.d] == '.';
    l[l.x] = 'P'
    @@ -74,8 +75,8 @@
    }
    window.setInterval(function()
    {
    setInnerHTML('PRE', renderLevel(level, theme));
    setInnerHTML('#points', level.p);
    updateLevel(level, level.keyCode, level.w);
    getFirstElement('PRE').innerHTML = renderLevel(level, theme);
    getFirstElement('#points').innerHTML = level.p;
    updateLevel(level, level.keyCode);
    }, 250)
    </script>
  12. @maettig maettig revised this gist Nov 21, 2011. 6 changed files with 101 additions and 59 deletions.
    2 changes: 1 addition & 1 deletion LICENSE.txt
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
    Version 2, December 2004

    Copyright (C) 2011 YOUR_NAME_HERE <YOUR_URL_HERE>
    Copyright (C) 2011 Thiemo Mättig <http://maettig.com/>

    Everyone is permitted to copy and distribute verbatim or modified
    copies of this license document, and changing it is allowed as long
    33 changes: 2 additions & 31 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -1,32 +1,3 @@
    140byt.es
    =========
    A simple variation of the Pac-Man game (almost) made with [140byt.es](http://140byt.es/) snippets.

    A tweet-sized, fork-to-play, community-curated collection of JavaScript.

    How to play
    -----------

    1. Click the ![Fork](https://d3nwyuy0nl342s.cloudfront.net/images/gist/buttons/fork_button.png) button above to fork this gist.
    2. Modify all the files to according to the rules below.
    3. Save your entry and tweet it up!

    Keep in mind that thanks to the awesome sensibilities of the GitHub team, gists are just repos. So feel free to clone yours and work locally for a more comfortable environment, and to allow commit messages.

    Rules
    -----
    All entries must exist in an `index.js` file, whose contents are

    1. an assignable, valid Javascript expression that
    2. contains no more than 140 bytes, and
    3. does not leak to the global scope.

    All entries must also be licensed under the [WTFPL](http://sam.zoy.org/wtfpl/) or equally permissive license.

    For more information
    --------------------

    See the [140byt.es](http://140byt.es) site for a showcase of entries (built itself using 140-byte entries!), and follow [@140bytes](http://twitter.com/140bytes) on Twitter.

    To learn about byte-saving hacks for your own code, or to contribute what you've learned, head to [the wiki](https://github.com/jed/140bytes/wiki/Byte-saving-techniques).

    140byt.es is brought to you by [Jed Schmidt](http://jed.is), with help from Alex Kloss. It was inspired by work from [Thomas Fuchs](http://mir.aculo.us) and [Dustin Diaz](http://www.dustindiaz.com/).
    My `setInnerHTML` uses tricks learned from @jed's [cssSelect](https://gist.github.com/991057). Everything else is created from scratch. Tested with Opera and Firefox. Does not work in Internet Explorer 8.
    23 changes: 14 additions & 9 deletions annotated.js
    Original file line number Diff line number Diff line change
    @@ -1,10 +1,15 @@
    function(){
    // make sure
    // to annotate
    // your code
    // so everyone
    // can learn
    // from it!
    // see jed's entries
    // for examples.
    function(l, k, w) //level, keyCode, level width
    {
    l[l.x] = ' '; //remove player from level
    if (l[l.x + l.d] == '#') //check if previous walking direction is possible
    l.d = 0; //stop
    if (k > 36 && k < 41 && //check if a cursor key was pressed
    l[l.x + (k = k % 2 //calculate walking direction
    ? k - 38 //-1 is left, +1 is right
    : (k - 39) * w //-width is up, +width is down
    )] != '#') //check if not walking into a wall
    l.d = k; //set new walking direction
    l.p += l[l.x += l.d //walk
    ] == '.'; //and increase points
    l[l.x] = 'P' //place player in level
    }
    2 changes: 1 addition & 1 deletion index.js
    Original file line number Diff line number Diff line change
    @@ -1 +1 @@
    function(){/* Your entry, a useful, unique, and valid JavaScript expression that packs as much functionality into 140 bytes as possible. */}
    function(l,k,w){l[l.x]=' ';if(l[l.x+l.d]=='#')l.d=0;if(k>36&&k<41&&l[l.x+(k=k%2?k-38:(k-39)*w)]!='#')l.d=k;l.p+=l[l.x+=l.d]=='.';l[l.x]='P'}
    11 changes: 4 additions & 7 deletions package.json
    Original file line number Diff line number Diff line change
    @@ -1,13 +1,10 @@
    {
    "name": "theNameOfYourLibWhichMustBeAValidCamelCasedJavaScriptIdentifier",
    "name": "pacMan",

    "description": "This should be a short description of your entry.",
    "description": "Pac-Man made with 140byte.es snippets.",

    "keywords": [
    "five",
    "descriptive",
    "keywords",
    "or",
    "fewer"
    "game",
    "pacman"
    ]
    }
    89 changes: 79 additions & 10 deletions test.html
    Original file line number Diff line number Diff line change
    @@ -1,12 +1,81 @@
    <!DOCTYPE html>
    <title>Foo</title>
    <div>Expected value: <b>undefined</b></div>
    <div>Actual value: <b id="ret"></b></div>
    <!DOCTYPE HTML>
    <pre>Loading...</pre>
    <span id="points">0</span> points
    <style type="text/css">
    body { background: #000; color: #FFF; font-family: Consolas, monospace; margin: 4em; text-shadow: 0 0 0.2em #FFF; }
    pre { font-size: 4em; line-height: 0.55em; margin: 0; }
    .air { color: #222; text-shadow: 0 0 0.2em #222; }
    .wall { color: #30F; text-shadow: 0 0 0.2em #30F; }
    .player { color: #FF0; text-shadow: 0 0 0.2em #FF0; }
    #points { font-size: 2em; line-height: 2em; }
    </style>
    <script>
    // write a small example that shows off the API for your example
    // and tests it in one fell swoop.

    var myFunction = function(){ /* the code here should be identical to the entry. */ }

    document.getElementById( "ret" ).innerHTML = myFunction()
    // 153 bytes, any idea how to save 13 bytes?
    var setInnerHTML = function(a, h)
    {
    a = /(\W?)(.*)/.exec(a);
    (a[1] == '#'
    ? document.getElementById(a[2])
    : document['getElementsBy' + (a[1] ? 'Class' : 'Tag') + 'Name'](a[2])[0]
    ).innerHTML = h
    }
    // 97 bytes, maybe use the remaining 43 bytes to make this more flexible?
    var parseLevel = function(l, w)
    {
    l = l.join ? l.join('\n') : l;
    w = l.indexOf('\n') + 1;
    l = l.split('');
    l.w = w;
    l.d = l.p = 0;
    return l
    }
    // 99 bytes, should be enough to add a "you won" screen.
    var renderLevel = function(l, t)
    {
    for (var h = '', x = 0; x < l.length; x++)
    {
    if (l[x] == 'P') l.x = x;
    h += t[l[x]] ? t[l[x]] : l[x]
    }
    return h
    }
    // 140 bytes
    var updateLevel = function(l, k, w)
    {
    l[l.x] = ' ';
    if (l[l.x + l.d] == '#')
    l.d = 0;
    if (k > 36 && k < 41 && l[l.x + (k = k % 2 ? k - 38 : (k - 39) * w)] != '#')
    l.d = k;
    l.p += l[l.x += l.d] == '.';
    l[l.x] = 'P'
    }
    var theme = {
    ' ': '<span class="air">\u2219</span>',
    '.': '<span class="gold">\u2219</span>',
    '#': '<span class="wall">\u25A1</span>',
    'P': '<span class="player">\u263B</span>'
    };
    var level = parseLevel(
    '###################\n' +
    '#....#.......#....#\n' +
    '#.##.#.#####.#.##.#\n' +
    '#.#.............#.#\n' +
    '#.#.##.##.##.##.#.#\n' +
    '#......#...#......#\n' +
    '#.#.##.#####.##.#.#\n' +
    '#.#......P......#.#\n' +
    '#.##.#.#####.#.##.#\n' +
    '#....#.......#....#\n' +
    '###################');
    window.onkeydown = function(e)
    {
    level.keyCode = (e || window.event).keyCode;
    }
    window.setInterval(function()
    {
    setInnerHTML('PRE', renderLevel(level, theme));
    setInnerHTML('#points', level.p);
    updateLevel(level, level.keyCode, level.w);
    }, 250)
    </script>
  13. @140bytes 140bytes revised this gist Jul 28, 2011. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -25,7 +25,7 @@ All entries must also be licensed under the [WTFPL](http://sam.zoy.org/wtfpl/) o
    For more information
    --------------------

    See the [140byt.es](http://140byt.es) for a showcase of entries built itself using 140-byte entries, and follow [@140bytes](http://twitter.com/140bytes) on Twitter.
    See the [140byt.es](http://140byt.es) site for a showcase of entries (built itself using 140-byte entries!), and follow [@140bytes](http://twitter.com/140bytes) on Twitter.

    To learn about byte-saving hacks for your own code, or to contribute what you've learned, head to [the wiki](https://github.com/jed/140bytes/wiki/Byte-saving-techniques).

  14. @140bytes 140bytes revised this gist Jul 28, 2011. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -25,8 +25,8 @@ All entries must also be licensed under the [WTFPL](http://sam.zoy.org/wtfpl/) o
    For more information
    --------------------

    The [140byt.es](http://140byt.es) site hasn't launched yet, but for now follow [@140bytes](http://twitter.com/140bytes) on Twitter.
    See the [140byt.es](http://140byt.es) for a showcase of entries built itself using 140-byte entries, and follow [@140bytes](http://twitter.com/140bytes) on Twitter.

    To learn about byte-saving hacks for your own code, or to contribute what you've learned, head to [the wiki](https://github.com/jed/140bytes/wiki/Byte-saving-techniques).

    140byt.es is brought to you by [Jed Schmidt](http://jed.is). It was inspired by work from [Thomas Fuchs](http://mir.aculo.us) and [Dustin Diaz](http://www.dustindiaz.com/).
    140byt.es is brought to you by [Jed Schmidt](http://jed.is), with help from Alex Kloss. It was inspired by work from [Thomas Fuchs](http://mir.aculo.us) and [Dustin Diaz](http://www.dustindiaz.com/).
  15. @140bytes 140bytes revised this gist Jun 1, 2011. 1 changed file with 5 additions and 7 deletions.
    12 changes: 5 additions & 7 deletions test.html
    Original file line number Diff line number Diff line change
    @@ -1,14 +1,12 @@
    <!DOCTYPE html>
    <body>
    <div>Expected value: <b>undefined</b></div>
    <div>Actual value: <b id="ret"></b></div>
    </body>
    <!DOCTYPE html>
    <title>Foo</title>
    <div>Expected value: <b>undefined</b></div>
    <div>Actual value: <b id="ret"></b></div>
    <script>
    // write a small example that shows off the API for your example
    // and tests it in one fell swoop.

    var myFunction = function(){ /* the code here should be identical to the entry. */ }
    var ret = myFunction()

    document.getElementById( "ret" ).innerHTML = ret
    document.getElementById( "ret" ).innerHTML = myFunction()
    </script>
  16. @140bytes 140bytes revised this gist Jun 1, 2011. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions test.html
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,4 @@
    <!DOCTYPE html>
    <body>
    <div>Expected value: <b>undefined</b></div>
    <div>Actual value: <b id="ret"></b></div>
  17. @140bytes 140bytes revised this gist May 31, 2011. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion test.html
    Original file line number Diff line number Diff line change
    @@ -9,5 +9,5 @@
    var myFunction = function(){ /* the code here should be identical to the entry. */ }
    var ret = myFunction()

    document.getElementById( "ret" ) = ret
    document.getElementById( "ret" ).innerHTML = ret
    </script>
  18. @140bytes 140bytes revised this gist May 31, 2011. 1 changed file with 13 additions and 0 deletions.
    13 changes: 13 additions & 0 deletions test.html
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,13 @@
    <body>
    <div>Expected value: <b>undefined</b></div>
    <div>Actual value: <b id="ret"></b></div>
    </body>
    <script>
    // write a small example that shows off the API for your example
    // and tests it in one fell swoop.

    var myFunction = function(){ /* the code here should be identical to the entry. */ }
    var ret = myFunction()

    document.getElementById( "ret" ) = ret
    </script>
  19. @140bytes 140bytes revised this gist May 31, 2011. 3 changed files with 17 additions and 19 deletions.
    17 changes: 9 additions & 8 deletions annotated.js
    Original file line number Diff line number Diff line change
    @@ -1,9 +1,10 @@
    function(){
    /* Rules:
    (1) anonymous function or IIFE // make sure
    (2) may execute immediately // to annotate
    (3) <=140 bytes // your code
    (4) no globals // so everyone
    (5) permissive license // can learn
    (6) have a good time! // from it!
    */}
    // make sure
    // to annotate
    // your code
    // so everyone
    // can learn
    // from it!
    // see jed's entries
    // for examples.
    }
    2 changes: 1 addition & 1 deletion index.js
    Original file line number Diff line number Diff line change
    @@ -1 +1 @@
    function(){/******************************************************************************************************************************/}
    function(){/* Your entry, a useful, unique, and valid JavaScript expression that packs as much functionality into 140 bytes as possible. */}
    17 changes: 7 additions & 10 deletions package.json
    Original file line number Diff line number Diff line change
    @@ -1,16 +1,13 @@
    {
    // [REQUIRED] A name for your library.
    // This must match /^[a-z_]\w*$/i
    "name": "140bytes",
    "name": "theNameOfYourLibWhichMustBeAValidCamelCasedJavaScriptIdentifier",

    // [OPTIONAL] A description of your library, phrased as a verb predicate.
    // The gist description is used by default.
    "description": "Explain the 140byt.es rules.",
    "description": "This should be a short description of your entry.",

    // [OPTIONAL] Up to 5 keywords used for indexing.
    "keywords": [
    "140bytes",
    "master",
    "rules"
    "five",
    "descriptive",
    "keywords",
    "or",
    "fewer"
    ]
    }
  20. @140bytes 140bytes revised this gist May 26, 2011. 1 changed file with 6 additions and 6 deletions.
    12 changes: 6 additions & 6 deletions annotated.js
    Original file line number Diff line number Diff line change
    @@ -1,9 +1,9 @@
    function(){
    /* Rules:
    (1) anonymous function // make sure
    (2) may execute immediately // to annotate
    (3) <=140 bytes // your code
    (4) no globals // so everyone
    (5) permissive license // can learn
    (6) have a good time! // from it!
    (1) anonymous function or IIFE // make sure
    (2) may execute immediately // to annotate
    (3) <=140 bytes // your code
    (4) no globals // so everyone
    (5) permissive license // can learn
    (6) have a good time! // from it!
    */}
  21. @140bytes 140bytes revised this gist May 25, 2011. 3 changed files with 8 additions and 8 deletions.
    2 changes: 1 addition & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -16,7 +16,7 @@ Rules
    -----
    All entries must exist in an `index.js` file, whose contents are

    1. an assignable, valid Javascript expression, that
    1. an assignable, valid Javascript expression that
    2. contains no more than 140 bytes, and
    3. does not leak to the global scope.

    12 changes: 6 additions & 6 deletions annotated.js
    Original file line number Diff line number Diff line change
    @@ -1,9 +1,9 @@
    function(){
    /* Rules:
    (1) anonymous function // make sure
    (2) may be self-executing // to annotate
    (3) <=140 bytes // your code
    (4) no globals // so everyone
    (5) MIT license // can learn
    (6) have a good time! // from it!
    (1) anonymous function // make sure
    (2) may execute immediately // to annotate
    (3) <=140 bytes // your code
    (4) no globals // so everyone
    (5) permissive license // can learn
    (6) have a good time! // from it!
    */}
    2 changes: 1 addition & 1 deletion index.js
    Original file line number Diff line number Diff line change
    @@ -1 +1 @@
    function(){/*Rules: (1) anonymous function (2) may be self-executing (3) <=140 bytes (4) no globals (5) MIT license (6) have a good time!*/}
    function(){/******************************************************************************************************************************/}
  22. @140bytes 140bytes revised this gist May 23, 2011. 2 changed files with 14 additions and 21 deletions.
    33 changes: 13 additions & 20 deletions LICENSE.txt
    Original file line number Diff line number Diff line change
    @@ -1,20 +1,13 @@
    Copyright (c) 2011 YOUR_NAME_HERE, YOUR_URL_HERE

    Permission is hereby granted, free of charge, to any person obtaining
    a copy of this software and associated documentation files (the
    "Software"), to deal in the Software without restriction, including
    without limitation the rights to use, copy, modify, merge, publish,
    distribute, sublicense, and/or sell copies of the Software, and to
    permit persons to whom the Software is furnished to do so, subject to
    the following conditions:

    The above copyright notice and this permission notice shall be
    included in all copies or substantial portions of the Software.

    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
    EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
    NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
    LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
    OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
    WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
    DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
    Version 2, December 2004

    Copyright (C) 2011 YOUR_NAME_HERE <YOUR_URL_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.
    2 changes: 1 addition & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -20,7 +20,7 @@ All entries must exist in an `index.js` file, whose contents are
    2. contains no more than 140 bytes, and
    3. does not leak to the global scope.

    All entries must also be licensed under a license as or more permitting than the MIT license.
    All entries must also be licensed under the [WTFPL](http://sam.zoy.org/wtfpl/) or equally permissive license.

    For more information
    --------------------
  23. @140bytes 140bytes revised this gist May 23, 2011. 1 changed file with 3 additions and 4 deletions.
    7 changes: 3 additions & 4 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -16,12 +16,11 @@ Rules
    -----
    All entries must exist in an `index.js` file, whose contents are

    1. a valid Javascript function expression, that
    2. optionally self-executes,
    1. an assignable, valid Javascript expression, that
    2. contains no more than 140 bytes, and
    3. does not pollute global scope.
    3. does not leak to the global scope.

    All entries must also be licensed under the MIT license.
    All entries must also be licensed under a license as or more permitting than the MIT license.

    For more information
    --------------------
  24. @140bytes 140bytes revised this gist May 22, 2011. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -10,6 +10,8 @@ How to play
    2. Modify all the files to according to the rules below.
    3. Save your entry and tweet it up!

    Keep in mind that thanks to the awesome sensibilities of the GitHub team, gists are just repos. So feel free to clone yours and work locally for a more comfortable environment, and to allow commit messages.

    Rules
    -----
    All entries must exist in an `index.js` file, whose contents are
  25. @140bytes 140bytes revised this gist May 21, 2011. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -26,4 +26,6 @@ For more information

    The [140byt.es](http://140byt.es) site hasn't launched yet, but for now follow [@140bytes](http://twitter.com/140bytes) on Twitter.

    To learn about byte-saving hacks for your own code, or to contribute what you've learned, head to [the wiki](https://github.com/jed/140bytes/wiki/Byte-saving-techniques).

    140byt.es is brought to you by [Jed Schmidt](http://jed.is). It was inspired by work from [Thomas Fuchs](http://mir.aculo.us) and [Dustin Diaz](http://www.dustindiaz.com/).
  26. @140bytes 140bytes revised this gist May 18, 2011. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion package.json
    Original file line number Diff line number Diff line change
    @@ -5,7 +5,7 @@

    // [OPTIONAL] A description of your library, phrased as a verb predicate.
    // The gist description is used by default.
    "description": "Explain the 140byt.es rules."
    "description": "Explain the 140byt.es rules.",

    // [OPTIONAL] Up to 5 keywords used for indexing.
    "keywords": [
  27. @140bytes 140bytes revised this gist May 18, 2011. 1 changed file with 13 additions and 1 deletion.
    14 changes: 13 additions & 1 deletion package.json
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,16 @@
    {
    // [REQUIRED] A name for your library.
    // This must match /^[a-z_]\w*$/i
    "name": "140bytes",
    "keywords": [ "140bytes", "master", "rules" ]

    // [OPTIONAL] A description of your library, phrased as a verb predicate.
    // The gist description is used by default.
    "description": "Explain the 140byt.es rules."

    // [OPTIONAL] Up to 5 keywords used for indexing.
    "keywords": [
    "140bytes",
    "master",
    "rules"
    ]
    }
  28. @140bytes 140bytes revised this gist May 18, 2011. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -24,4 +24,6 @@ All entries must also be licensed under the MIT license.
    For more information
    --------------------

    The [140byt.es](http://140byt.es) site hasn't launched yet, but for now follow [@140bytes](http://twitter.com/140bytes) on Twitter.
    The [140byt.es](http://140byt.es) site hasn't launched yet, but for now follow [@140bytes](http://twitter.com/140bytes) on Twitter.

    140byt.es is brought to you by [Jed Schmidt](http://jed.is). It was inspired by work from [Thomas Fuchs](http://mir.aculo.us) and [Dustin Diaz](http://www.dustindiaz.com/).
  29. @140bytes 140bytes revised this gist May 18, 2011. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -14,8 +14,8 @@ Rules
    -----
    All entries must exist in an `index.js` file, whose contents are

    1. a valid Javascript function expression, that is
    2. is optionally self-executing,
    1. a valid Javascript function expression, that
    2. optionally self-executes,
    2. contains no more than 140 bytes, and
    3. does not pollute global scope.

  30. @140bytes 140bytes revised this gist May 18, 2011. 1 changed file with 12 additions and 1 deletion.
    13 changes: 12 additions & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -7,9 +7,20 @@ How to play
    -----------

    1. Click the ![Fork](https://d3nwyuy0nl342s.cloudfront.net/images/gist/buttons/fork_button.png) button above to fork this gist.
    2. Modify all the files to according to the rules and style guide below.
    2. Modify all the files to according to the rules below.
    3. Save your entry and tweet it up!

    Rules
    -----
    All entries must exist in an `index.js` file, whose contents are

    1. a valid Javascript function expression, that is
    2. is optionally self-executing,
    2. contains no more than 140 bytes, and
    3. does not pollute global scope.

    All entries must also be licensed under the MIT license.

    For more information
    --------------------