Revision: 5263
Author:   [email protected]
Date:     Mon Feb  4 14:38:37 2013
Log:      Formatting, allow vertical scrolling in the gadget areas.


http://code.google.com/p/google-caja/source/detail?r=5263

Modified:
 /trunk/src/com/google/caja/demos/capman/css/capman.css
 /trunk/src/com/google/caja/demos/capman/js/pacman.js

=======================================
--- /trunk/src/com/google/caja/demos/capman/css/capman.css Thu Jan 31 16:18:57 2013 +++ /trunk/src/com/google/caja/demos/capman/css/capman.css Mon Feb 4 14:38:37 2013
@@ -30,7 +30,7 @@
   border: 1px solid black;
   height: 6em;
   margin-bottom: 1em;
-  overflow: hidden;
+  overflow: auto;
   background: #5e5e5e;
   color: #00ca00;
 }
=======================================
--- /trunk/src/com/google/caja/demos/capman/js/pacman.js Mon Feb 4 12:09:56 2013 +++ /trunk/src/com/google/caja/demos/capman/js/pacman.js Mon Feb 4 14:38:37 2013
@@ -101,125 +101,123 @@
     });

     function getNewCoord(dir, current) {
-
-        var speed  = isVulnerable() ? 1 : isHidden() ? 1 : 2,
- xSpeed = (dir === LEFT && -speed || dir === RIGHT && speed || 0),
-            ySpeed = (dir === DOWN && speed || dir === UP && -speed || 0);
-
-        return {
-            "x": addBounded(current.x, xSpeed),
-            "y": addBounded(current.y, ySpeed)
-        };
+      var speed  = isVulnerable() ? 1 : isHidden() ? 1 : 2,
+          xSpeed = (dir === LEFT && -speed || dir === RIGHT && speed || 0),
+          ySpeed = (dir === DOWN && speed || dir === UP && -speed || 0);
+
+      return {
+        "x": addBounded(current.x, xSpeed),
+        "y": addBounded(current.y, ySpeed)
+      };
     };

     /* Collision detection(walls) is done when a ghost lands on an
      * exact block, make sure they dont skip over it
      */
     function addBounded(x1, x2) {
-        var rem    = x1 % 10,
-            result = rem + x2;
-        if (rem !== 0 && result > 10) {
-            return x1 + (10 - rem);
-        } else if(rem > 0 && result < 0) {
-            return x1 - rem;
-        }
-        return x1 + x2;
+      var rem    = x1 % 10,
+          result = rem + x2;
+      if (rem !== 0 && result > 10) {
+        return x1 + (10 - rem);
+      } else if(rem > 0 && result < 0) {
+        return x1 - rem;
+      }
+      return x1 + x2;
     };
-
+
     function isVulnerable() {
-        return eatable !== null;
+      return eatable !== null;
     };

     function isDangerous() {
-        return eaten === null;
+      return eaten === null;
     };

     function isHidden() {
-        return eatable === null && eaten !== null;
+      return eatable === null && eaten !== null;
     };

     function getRandomDirection() {
-        var moves = (direction === LEFT || direction === RIGHT)
+      var moves = (direction === LEFT || direction === RIGHT)
             ? [UP, DOWN] : [LEFT, RIGHT];
-        return moves[Math.floor(Math.random() * 2)];
+      return moves[Math.floor(Math.random() * 2)];
     };

-    function look(dir) {
-    }
-
+    function look(dir) {}
+
     function reset() {
-        eaten = null;
-        eatable = null;
-        game.setAllGhostsEatable(false);
-        position = {"x": 90, "y": 80};
-        var div = getStatusEl();
-        div.innerHTML = "";
-        caja.load(div, caja.policy.net.NO_NETWORK,
+      eaten = null;
+      eatable = null;
+      game.setAllGhostsEatable(false);
+      position = {"x": 90, "y": 80};
+      var div = getStatusEl();
+      div.innerHTML = "";
+      caja.load(div, caja.policy.net.NO_NETWORK,
           function(frame) {
- frame.code('http://fake.url/', 'text/html', ghostEditor.getValue())
-                  .api(caja.tame(api))
-                 .run();
+ frame.code('http://fake.url/', 'text/html', ghostEditor.getValue())
+                 .api(caja.tame(api))
+                 .run();
           });
-        direction = getRandomDirection();
-        due = getRandomDirection();
+      direction = getRandomDirection();
+      due = getRandomDirection();
     };
-
+
     function onWholeSquare(x) {
-        return x % 10 === 0;
+      return x % 10 === 0;
     };
-
+
     function oppositeDirection(dir) {
-        return dir === LEFT && RIGHT ||
-            dir === RIGHT && LEFT ||
-            dir === UP && DOWN || UP;
+      return dir === LEFT && RIGHT ||
+          dir === RIGHT && LEFT ||
+          dir === UP && DOWN || UP;
     };

     function makeEatable() {
-        //direction = oppositeDirection(direction);
-        eatable = game.getTick();
-        game.setAllGhostsEatable(true);
+      //direction = oppositeDirection(direction);
+      eatable = game.getTick();
+      game.setAllGhostsEatable(true);
     };

     function eat() {
-        eatable = null;
-        game.setAllGhostsEatable(false);
-        eaten = game.getTick();
+      eatable = null;
+      game.setAllGhostsEatable(false);
+      eaten = game.getTick();
     };

     function pointToCoord(x) {
-        return Math.round(x / 10);
+      return Math.round(x / 10);
     };

     function nextSquare(x, dir) {
-        var rem = x % 10;
-        if (rem === 0) {
-            return x;
-        } else if (dir === RIGHT || dir === DOWN) {
-            return x + (10 - rem);
-        } else {
-            return x - rem;
-        }
+      var rem = x % 10;
+      if (rem === 0) {
+        return x;
+      } else if (dir === RIGHT || dir === DOWN) {
+        return x + (10 - rem);
+      } else {
+        return x - rem;
+      }
     };

     function onGridSquare(pos) {
-        return onWholeSquare(pos.y) && onWholeSquare(pos.x);
+      return onWholeSquare(pos.y) && onWholeSquare(pos.x);
     };

     function secondsAgo(tick) {
-        return (game.getTick() - tick) / Pacman.FPS;
+      return (game.getTick() - tick) / Pacman.FPS;
     };

     function getColour() {
-        if (eatable) {
-            if (secondsAgo(eatable) > 5) {
-                return game.getTick() % 20 > 10 ? "#FFFFFF" : "#0000BB";
-            } else {
-                return "#0000BB";
-            }
-        } else if(eaten) {
-            return "#222";
-        }
-        return ghostDetail.color;
+      if (eatable) {
+        if (secondsAgo(eatable) > 5) {
+          return game.getTick() % 20 > 10 ? "#FFFFFF" : "#0000BB";
+        } else {
+          return "#0000BB";
+        }
+      } else if(eaten) {
+        return "#222";
+      }
+      return ghostDetail.color;
     };

     function getStatusEl() {
@@ -227,160 +225,153 @@
     }

     function draw(ctx) {
-
-        var s    = map.blockSize,
-            top  = (position.y/10) * s,
-            left = (position.x/10) * s;
-
-        if (eatable && secondsAgo(eatable) > 8) {
-            eatable = null;
-            game.setAllGhostsEatable(false);
-        }
-
-        if (eaten && secondsAgo(eaten) > 3) {
-            eaten = null;
-        }
-
-        var tl = left + s;
-        var base = top + s - 3;
-        var inc = s / 10;
+      var s    = map.blockSize,
+          top  = (position.y/10) * s,
+          left = (position.x/10) * s;

-        var high = game.getTick() % 10 > 5 ? 3  : -3;
-        var low  = game.getTick() % 10 > 5 ? -3 : 3;
+      if (eatable && secondsAgo(eatable) > 8) {
+        eatable = null;
+        game.setAllGhostsEatable(false);
+      }
+
+      if (eaten && secondsAgo(eaten) > 3) {
+        eaten = null;
+      }
+
+      var tl = left + s;
+      var base = top + s - 3;
+      var inc = s / 10;

-        ctx.fillStyle = getColour();
-        ctx.beginPath();
+      var high = game.getTick() % 10 > 5 ? 3  : -3;
+      var low  = game.getTick() % 10 > 5 ? -3 : 3;

-        ctx.moveTo(left, base);
+      ctx.fillStyle = getColour();
+      ctx.beginPath();

-        ctx.quadraticCurveTo(left, top, left + (s/2),  top);
-        ctx.quadraticCurveTo(left + s, top, left+s,  base);
-
-        // Wavy things at the bottom
-        ctx.quadraticCurveTo(tl-(inc*1), base+high, tl - (inc * 2),  base);
-        ctx.quadraticCurveTo(tl-(inc*3), base+low, tl - (inc * 4),  base);
-        ctx.quadraticCurveTo(tl-(inc*5), base+high, tl - (inc * 6),  base);
-        ctx.quadraticCurveTo(tl-(inc*7), base+low, tl - (inc * 8),  base);
-        ctx.quadraticCurveTo(tl-(inc*9), base+high, tl - (inc * 10), base);
+      ctx.moveTo(left, base);

-        ctx.closePath();
-        ctx.fill();
+      ctx.quadraticCurveTo(left, top, left + (s/2),  top);
+      ctx.quadraticCurveTo(left + s, top, left+s,  base);
+
+      // Wavy things at the bottom
+      ctx.quadraticCurveTo(tl-(inc*1), base+high, tl - (inc * 2),  base);
+      ctx.quadraticCurveTo(tl-(inc*3), base+low, tl - (inc * 4),  base);
+      ctx.quadraticCurveTo(tl-(inc*5), base+high, tl - (inc * 6),  base);
+      ctx.quadraticCurveTo(tl-(inc*7), base+low, tl - (inc * 8),  base);
+      ctx.quadraticCurveTo(tl-(inc*9), base+high, tl - (inc * 10), base);

-        ctx.beginPath();
-        ctx.fillStyle = "#FFF";
-        ctx.arc(left + 6,top + 6, s / 6, 0, 300, false);
-        ctx.arc((left + s) - 6,top + 6, s / 6, 0, 300, false);
-        ctx.closePath();
-        ctx.fill();
+      ctx.closePath();
+      ctx.fill();

-        var f = s / 12;
-        var off = {};
-        off[RIGHT] = [f, 0];
-        off[LEFT]  = [-f, 0];
-        off[UP]    = [0, -f];
+      ctx.beginPath();
+      ctx.fillStyle = "#FFF";
+      ctx.arc(left + 6,top + 6, s / 6, 0, 300, false);
+      ctx.arc((left + s) - 6,top + 6, s / 6, 0, 300, false);
+      ctx.closePath();
+      ctx.fill();

-        off[DOWN]  = [0, f];
+      var f = s / 12;
+      var off = {};
+      off[RIGHT] = [f, 0];
+      off[LEFT]  = [-f, 0];
+      off[UP]    = [0, -f];

-        ctx.beginPath();
-        ctx.fillStyle = "#000";
-        ctx.arc(left+6+off[direction][0], top+6+off[direction][1],
-                s / 15, 0, 300, false);
-        ctx.arc((left+s)-6+off[direction][0], top+6+off[direction][1],
-                s / 15, 0, 300, false);
-        ctx.closePath();
-        ctx.fill();
+      off[DOWN]  = [0, f];

+      ctx.beginPath();
+      ctx.fillStyle = "#000";
+      ctx.arc(left+6+off[direction][0], top+6+off[direction][1],
+              s / 15, 0, 300, false);
+      ctx.arc((left+s)-6+off[direction][0], top+6+off[direction][1],
+              s / 15, 0, 300, false);
+      ctx.closePath();
+      ctx.fill();
     };

     function pane(pos) {
+      if (pos.y === 100 && pos.x >= 190 && direction === RIGHT) {
+        return {"y": 100, "x": -10};
+      }
+
+      if (pos.y === 100 && pos.x <= -10 && direction === LEFT) {
+        return position = {"y": 100, "x": 190};
+      }

-        if (pos.y === 100 && pos.x >= 190 && direction === RIGHT) {
-            return {"y": 100, "x": -10};
-        }
-
-        if (pos.y === 100 && pos.x <= -10 && direction === LEFT) {
-            return position = {"y": 100, "x": 190};
-        }
+      return false;
+    };

-        return false;
-    };
-
     function move(ctx) {
-
-        var oldPos = position,
-            onGrid = onGridSquare(position),
-            npos   = null;
-
-        if (due !== direction) {
-
-            npos = getNewCoord(due, position);
-
-            if (onGrid &&
-                map.isFloorSpace({
-                    "y":pointToCoord(nextSquare(npos.y, due)),
-                    "x":pointToCoord(nextSquare(npos.x, due))})) {
-                direction = due;
-            } else {
-                npos = null;
-            }
-        }
-
-        if (npos === null) {
-            npos = getNewCoord(direction, position);
-        }
-
-        if (onGrid &&
-            map.isWallSpace({
-                "y" : pointToCoord(nextSquare(npos.y, direction)),
-                "x" : pointToCoord(nextSquare(npos.x, direction))
-            })) {
-
-            due = getRandomDirection();
-            return move(ctx);
-        }
+      var oldPos = position,
+          onGrid = onGridSquare(position),
+          npos   = null;
+
+      if (due !== direction) {
+          npos = getNewCoord(due, position);
+          if (onGrid &&
+            map.isFloorSpace({
+                "y":pointToCoord(nextSquare(npos.y, due)),
+                "x":pointToCoord(nextSquare(npos.x, due))})) {
+            direction = due;
+          } else {
+            npos = null;
+          }
+      }
+
+      if (npos === null) {
+        npos = getNewCoord(direction, position);
+      }
+
+      if (onGrid &&
+          map.isWallSpace({
+              "y" : pointToCoord(nextSquare(npos.y, direction)),
+              "x" : pointToCoord(nextSquare(npos.x, direction))
+          })) {
+        due = getRandomDirection();
+        return move(ctx);
+      }
+
+      position = npos;
+
+      var tmp = pane(position);
+      if (tmp) {
+        position = tmp;
+      }
+
+      try {
+        due = ghostCallback();
+      } catch (e) {
+        makeEatable();
+        console.log("Ghost " + ghostDetail.name +
+            " behaving badly and has made themselves vulnerable!");
+        console.log("Threw exception: " + e.toString());
+      }

-        position = npos;
-
-        var tmp = pane(position);
-        if (tmp) {
-            position = tmp;
-        }
-
-        try {
-          due = ghostCallback();
-        } catch (e) {
-            makeEatable();
- console.log("Ghost " + ghostDetail.name + " behaving badly and has made themselves vulnerable!");
-            console.log("Threw exception: " + e.toString());
-        }
-
-        return {
-            "new" : position,
-            "old" : oldPos
-        };
+      return {
+        "new" : position,
+        "old" : oldPos
+      };
     };

     function getPosition() {
-        return {
-            "y" : pointToCoord(position.y),
-            "x" : pointToCoord(position.x)
-        };
+      return {
+        "y" : pointToCoord(position.y),
+        "x" : pointToCoord(position.x)
+      };
     }

     return {
-        "getPosition" : getPosition,
-        "eat"         : eat,
-        "isVulnerable" : isVulnerable,
-        "isDangerous" : isDangerous,
-        "makeEatable" : makeEatable,
-        "reset"       : reset,
-        "move"        : move,
-        "draw"        : draw
+      "getPosition" : getPosition,
+      "eat"         : eat,
+      "isVulnerable" : isVulnerable,
+      "isDangerous" : isDangerous,
+      "makeEatable" : makeEatable,
+      "reset"       : reset,
+      "move"        : move,
+      "draw"        : draw
     };
 };

 Pacman.User = function (game, map, pacmanEditor, pacmanDetail) {
-
     var position  = null,
         direction = null,
         eaten     = null,
@@ -409,228 +400,226 @@
     keyMap[KEY.ARROW_DOWN]  = DOWN;

     function getRandomDirection() {
-        var moves = (direction === LEFT || direction === RIGHT)
-            ? [UP, DOWN] : [LEFT, RIGHT];
-        return moves[Math.floor(Math.random() * 2)];
+      var moves = (direction === LEFT || direction === RIGHT)
+          ? [UP, DOWN] : [LEFT, RIGHT];
+      return moves[Math.floor(Math.random() * 2)];
     };

     function addScore(nScore) {
-        score += nScore;
-        if (score >= 10000 && score - nScore < 10000) {
-            lives += 1;
-        }
+      score += nScore;
+      if (score >= 10000 && score - nScore < 10000) {
+        lives += 1;
+      }
     };

     function theScore() {
-        return score;
+      return score;
     };

     function loseLife() {
-        lives -= 1;
+      lives -= 1;
     };

     function getLives() {
-        return lives;
+      return lives;
     };

     function initUser() {
-        score = 0;
-        lives = 3;
-        newLevel();
+      score = 0;
+      lives = 3;
+      newLevel();
     }
-
+
     function newLevel() {
-        resetPosition();
-        eaten = 0;
+      resetPosition();
+      eaten = 0;
     };
-
+
     function resetPosition() {
-        position = {"x": 90, "y": 120};
-        direction = LEFT;
-        due = LEFT;
+      position = {"x": 90, "y": 120};
+      direction = LEFT;
+      due = LEFT;
     };
-
+
     function reset() {
-        initUser();
-        resetPosition();
+      initUser();
+      resetPosition();

-        var div = getStatusEl();
-        div.innerHTML = "";
-        caja.load(div, caja.policy.net.NO_NETWORK,
+      var div = getStatusEl();
+      div.innerHTML = "";
+      caja.load(div, caja.policy.net.NO_NETWORK,
           function(frame) {
- frame.code('http://fake.url/', 'text/html', pacmanEditor.getValue())
-                  .api(caja.tame(pacmanApi))
-                 .run();
+ frame.code('http://fake.url/', 'text/html', pacmanEditor.getValue())
+                 .api(caja.tame(pacmanApi))
+                 .run();
           });
-    };
-
+    };
+
     function keyDown(e) {
-        // Pacman is now under script control.
-        return true;
-        if (typeof keyMap[e.keyCode] !== "undefined") {
-            due = keyMap[e.keyCode];
-           //            e.preventDefault();
-           //            e.stopPropagation();
-            return false;
-        }
-        return true;
-       };
+      // Pacman is now under script control.
+      return true;
+      if (typeof keyMap[e.keyCode] !== "undefined") {
+        due = keyMap[e.keyCode];
+        // e.preventDefault();
+        // e.stopPropagation();
+        return false;
+      }
+      return true;
+    };

     function getNewCoord(dir, current) {
         return {
- "x": current.x + (dir === LEFT && -2 || dir === RIGHT && 2 || 0), - "y": current.y + (dir === DOWN && 2 || dir === UP && -2 || 0)
+          "x": current.x + (dir === LEFT && -2 || dir === RIGHT && 2 || 0),
+          "y": current.y + (dir === DOWN && 2 || dir === UP    && -2 || 0)
         };
     };

     function onWholeSquare(x) {
-        return x % 10 === 0;
+      return x % 10 === 0;
     };

     function pointToCoord(x) {
-        return Math.round(x/10);
+      return Math.round(x/10);
     };
-
+
     function nextSquare(x, dir) {
-        var rem = x % 10;
-        if (rem === 0) {
-            return x;
-        } else if (dir === RIGHT || dir === DOWN) {
-            return x + (10 - rem);
-        } else {
-            return x - rem;
-        }
+      var rem = x % 10;
+      if (rem === 0) {
+        return x;
+      } else if (dir === RIGHT || dir === DOWN) {
+        return x + (10 - rem);
+      } else {
+        return x - rem;
+      }
     };

     function next(pos, dir) {
-        return {
-            "y" : pointToCoord(nextSquare(pos.y, dir)),
-            "x" : pointToCoord(nextSquare(pos.x, dir)),
-        };
+      return {
+        "y" : pointToCoord(nextSquare(pos.y, dir)),
+        "x" : pointToCoord(nextSquare(pos.x, dir)),
+      };
     };

     function onGridSquare(pos) {
-        return onWholeSquare(pos.y) && onWholeSquare(pos.x);
+      return onWholeSquare(pos.y) && onWholeSquare(pos.x);
     };

     function isOnSamePlane(due, dir) {
-        return ((due === LEFT || due === RIGHT) &&
-                (dir === LEFT || dir === RIGHT)) ||
-            ((due === UP || due === DOWN) &&
-             (dir === UP || dir === DOWN));
+      return ((due === LEFT || due === RIGHT) &&
+              (dir === LEFT || dir === RIGHT)) ||
+          ((due === UP || due === DOWN) &&
+           (dir === UP || dir === DOWN));
     };

     function move(ctx) {
-
         var npos        = null,
             nextWhole   = null,
             oldPosition = position,
             block       = null;

-        try {
-          due = pacmanCallback();
-        } catch (e) {
-          // TODO(ihab.awad): Make Pacman vulnerable -- how?
- console.log("Pacman behaving badly and has made themselves vulnerable!");
-          console.log("Threw exception: " + e.toString());
-        }
+      try {
+        due = pacmanCallback();
+      } catch (e) {
+        // TODO(ihab.awad): Make Pacman vulnerable -- how?
+ console.log("Pacman behaving badly and has made themselves vulnerable!");
+        console.log("Threw exception: " + e.toString());
+      }

-        if (due !== direction) {
-            npos = getNewCoord(due, position);
-
-            if (isOnSamePlane(due, direction) ||
-                (onGridSquare(position) &&
-                 map.isFloorSpace(next(npos, due)))) {
-                direction = due;
-            } else {
-                npos = null;
-            }
-        }
-
-        if (npos === null) {
-            npos = getNewCoord(direction, position);
-        }
+      if (due !== direction) {
+        npos = getNewCoord(due, position);

- if (onGridSquare(position) && map.isWallSpace(next(npos, direction))) {
-            direction = NONE;
+        if (isOnSamePlane(due, direction) ||
+            (onGridSquare(position) &&
+             map.isFloorSpace(next(npos, due)))) {
+          direction = due;
+        } else {
+          npos = null;
         }
+      }

-        if (direction === NONE) {
-            return {"new" : position, "old" : position};
-        }
+      if (npos === null) {
+        npos = getNewCoord(direction, position);
+      }
+
+ if (onGridSquare(position) && map.isWallSpace(next(npos, direction))) {
+        direction = NONE;
+      }
+
+      if (direction === NONE) {
+        return {"new" : position, "old" : position};
+      }
+
+      if (npos.y === 100 && npos.x >= 190 && direction === RIGHT) {
+        npos = {"y": 100, "x": -10};
+      }
+
+      if (npos.y === 100 && npos.x <= -12 && direction === LEFT) {
+        npos = {"y": 100, "x": 190};
+      }
+
+      position = npos;
+      nextWhole = next(position, direction);
+
+      block = map.block(nextWhole);
+
+      if ((isMidSquare(position.y) || isMidSquare(position.x)) &&
+        block === Pacman.BISCUIT || block === Pacman.PILL) {

-        if (npos.y === 100 && npos.x >= 190 && direction === RIGHT) {
-            npos = {"y": 100, "x": -10};
-        }
+        map.setBlock(nextWhole, Pacman.EMPTY);
+        addScore((block === Pacman.BISCUIT) ? 10 : 50);
+        eaten += 1;

-        if (npos.y === 100 && npos.x <= -12 && direction === LEFT) {
-            npos = {"y": 100, "x": 190};
+        if (eaten === 182) {
+          game.completedLevel();
         }

-        position = npos;
-        nextWhole = next(position, direction);
-
-        block = map.block(nextWhole);
-
-        if ((isMidSquare(position.y) || isMidSquare(position.x)) &&
-            block === Pacman.BISCUIT || block === Pacman.PILL) {
-
-            map.setBlock(nextWhole, Pacman.EMPTY);
-            addScore((block === Pacman.BISCUIT) ? 10 : 50);
-            eaten += 1;
-
-            if (eaten === 182) {
-                game.completedLevel();
-            }
-
-            if (block === Pacman.PILL) {
-                game.eatenPill();
-            }
+        if (block === Pacman.PILL) {
+          game.eatenPill();
         }
+      }

-        return {
-            "new" : position,
-            "old" : oldPosition
-        };
+      return {
+        "new" : position,
+        "old" : oldPosition
+      };
     };

     function isMidSquare(x) {
-        var rem = x % 10;
-        return rem > 3 || rem < 7;
+      var rem = x % 10;
+      return rem > 3 || rem < 7;
     };

     function calcAngle(dir, pos) {
-        if (dir == RIGHT && (pos.x % 10 < 5)) {
-            return {"start":0.25, "end":1.75, "direction": false};
-        } else if (dir === DOWN && (pos.y % 10 < 5)) {
-            return {"start":0.75, "end":2.25, "direction": false};
-        } else if (dir === UP && (pos.y % 10 < 5)) {
-            return {"start":1.25, "end":1.75, "direction": true};
-        } else if (dir === LEFT && (pos.x % 10 < 5)) {
-            return {"start":0.75, "end":1.25, "direction": true};
-        }
-        return {"start":0, "end":2, "direction": false};
+      if (dir == RIGHT && (pos.x % 10 < 5)) {
+        return {"start":0.25, "end":1.75, "direction": false};
+      } else if (dir === DOWN && (pos.y % 10 < 5)) {
+        return {"start":0.75, "end":2.25, "direction": false};
+      } else if (dir === UP && (pos.y % 10 < 5)) {
+        return {"start":1.25, "end":1.75, "direction": true};
+      } else if (dir === LEFT && (pos.x % 10 < 5)) {
+        return {"start":0.75, "end":1.25, "direction": true};
+      }
+      return {"start":0, "end":2, "direction": false};
     };

     function drawDead(ctx, amount) {
+      var size = map.blockSize,
+          half = size / 2;

-        var size = map.blockSize,
-            half = size / 2;
+      if (amount >= 1) {
+        return;
+      }

-        if (amount >= 1) {
-            return;
-        }
-
-        ctx.fillStyle = "#FFFF00";
-        ctx.beginPath();
-        ctx.moveTo(((position.x/10) * size) + half,
-                   ((position.y/10) * size) + half);
-
-        ctx.arc(((position.x/10) * size) + half,
-                ((position.y/10) * size) + half,
-                half, 0, Math.PI * 2 * amount, true);
-
-        ctx.fill();
+      ctx.fillStyle = "#FFFF00";
+      ctx.beginPath();
+      ctx.moveTo(((position.x/10) * size) + half,
+                 ((position.y/10) * size) + half);
+
+      ctx.arc(((position.x/10) * size) + half,
+              ((position.y/10) * size) + half,
+              half, 0, Math.PI * 2 * amount, true);
+
+      ctx.fill();
     };

     function getStatusEl() {
@@ -638,778 +627,763 @@
     }

     function draw(ctx) {
+      var s     = map.blockSize,
+          angle = calcAngle(direction, position);

-        var s     = map.blockSize,
-            angle = calcAngle(direction, position);
+      ctx.fillStyle = "#FFFF00";

-        ctx.fillStyle = "#FFFF00";
+      ctx.beginPath();

-        ctx.beginPath();
+      ctx.moveTo(((position.x/10) * s) + s / 2,
+                 ((position.y/10) * s) + s / 2);
+
+      ctx.arc(((position.x/10) * s) + s / 2,
+              ((position.y/10) * s) + s / 2,
+              s / 2, Math.PI * angle.start,
+              Math.PI * angle.end, angle.direction);
+
+      ctx.fill();
+    };

-        ctx.moveTo(((position.x/10) * s) + s / 2,
-                   ((position.y/10) * s) + s / 2);
-
-        ctx.arc(((position.x/10) * s) + s / 2,
-                ((position.y/10) * s) + s / 2,
-                s / 2, Math.PI * angle.start,
-                Math.PI * angle.end, angle.direction);
-
-        ctx.fill();
-    };
-
     function getPosition() {
-        return {
-            "y" : pointToCoord(position.y),
-            "x" : pointToCoord(position.x)
-        };
+      return {
+        "y" : pointToCoord(position.y),
+        "x" : pointToCoord(position.x)
+      };
     }

     initUser();

     return {
-        "draw"          : draw,
-        "drawDead"      : drawDead,
-        "loseLife"      : loseLife,
-        "getLives"      : getLives,
-        "score"         : score,
-        "addScore"      : addScore,
-        "theScore"      : theScore,
-        "keyDown"       : keyDown,
-        "move"          : move,
-        "getPosition"   : getPosition,
-        "newLevel"      : newLevel,
-        "reset"         : reset,
-        "resetPosition" : resetPosition
+      "draw"          : draw,
+      "drawDead"      : drawDead,
+      "loseLife"      : loseLife,
+      "getLives"      : getLives,
+      "score"         : score,
+      "addScore"      : addScore,
+      "theScore"      : theScore,
+      "keyDown"       : keyDown,
+      "move"          : move,
+      "getPosition"   : getPosition,
+      "newLevel"      : newLevel,
+      "reset"         : reset,
+      "resetPosition" : resetPosition
     };
 };

 Pacman.Map = function (size) {
-
-    var height    = null,
-        width     = null,
-        blockSize = size,
-        pillSize  = 0,
-        map       = null;
-
-    function withinBounds(y, x) {
-        return y >= 0 && y < height && x >= 0 && x < width;
+  var height    = null,
+      width     = null,
+      blockSize = size,
+      pillSize  = 0,
+      map       = null;
+
+  function withinBounds(y, x) {
+    return y >= 0 && y < height && x >= 0 && x < width;
+  }
+
+  function isWall(pos) {
+    return withinBounds(pos.y, pos.x) && map[pos.y][pos.x] === Pacman.WALL;
+  }
+
+  function isFloorSpace(pos) {
+    if (!withinBounds(pos.y, pos.x)) {
+      return false;
     }
-
-    function isWall(pos) {
- return withinBounds(pos.y, pos.x) && map[pos.y][pos.x] === Pacman.WALL;
-    }
-
-    function isFloorSpace(pos) {
-        if (!withinBounds(pos.y, pos.x)) {
-            return false;
-        }
-        var peice = map[pos.y][pos.x];
-        return peice === Pacman.EMPTY ||
-            peice === Pacman.BISCUIT ||
-            peice === Pacman.PILL;
-    }
+    var piece = map[pos.y][pos.x];
+    return piece === Pacman.EMPTY ||
+        piece === Pacman.BISCUIT ||
+        piece === Pacman.PILL;
+  }
+
+  function drawWall(ctx) {
+    var i, j, p, line;
+
+    ctx.strokeStyle = "#0000FF";
+    ctx.lineWidth   = 5;
+    ctx.lineCap     = "round";

-    function drawWall(ctx) {
-
-        var i, j, p, line;
-
-        ctx.strokeStyle = "#0000FF";
-        ctx.lineWidth   = 5;
-        ctx.lineCap     = "round";
-
-        for (i = 0; i < Pacman.WALLS.length; i += 1) {
-            line = Pacman.WALLS[i];
-            ctx.beginPath();
+    for (i = 0; i < Pacman.WALLS.length; i += 1) {
+      line = Pacman.WALLS[i];
+      ctx.beginPath();
***The diff for this file has been truncated for email.***

--

--- You received this message because you are subscribed to the Google Groups "Google Caja Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to