git @ Cat's Eye Technologies yoob.js / rel_0_1 eg / playfield.html
rel_0_1

Tree @rel_0_1 (Download .tar.gz)

playfield.html @rel_0_1raw · history · blame

<!DOCTYPE html>
<head>
  <meta charset="utf-8">
  <title>yoob.Playfield Demo</title>
  <script src="../src/yoob/playfield.js"></script>
  <script src="../src/yoob/cursor.js"></script>
  <style>
#canvas { border: 1px solid blue; }
  </style>
</head>
<body>

<h1>yoob.Playfield Demo</h1>

<canvas id="canvas" width="400" height="400">
Your browser doesn't support displaying an HTML5 canvas.
</canvas>

<textarea id="program" rows="10" cols="40">
   #
#$ @#
    @#


     @
</textarea>

<button id="load">Load</button>
<button id="step">Step</button>

</body>
<script>
  var canvas = document.getElementById('canvas');
  var pf = new yoob.Playfield();
  var ip = new yoob.Cursor();
  var height = 20;

  var textarea = document.getElementById('program');
  document.getElementById('load').onclick = function(e) {
    pf.load(0, 0, textarea.value);
    pf.foreach(function (x, y, value) {
        if (value === '$') {
            ip.x = x;
            ip.y = y;
        }
    });
    ip.dx = 1;
    ip.dy = 0;
    pf.drawCanvas(canvas, undefined, height, [ip]);
  };

  document.getElementById('step').onclick = function(e) {
    ip.advance();
    pf.drawCanvas(canvas, undefined, height, [ip]);
  };
</script>