var robot;
var now;
var deltaTime;
var last = timestamp();
var frameId;


$(function () {
    attachClickHandlers();
    createPlayer();
});

function createPlayer() {
    robot = $('<img src="robot.png" class="player">');
    robot.css('top', 6);
    robot.css('left', 6);
    $('.field').append(robot);
}

function attachClickHandlers() {
    $('input').on('click', function() {
        frameId = requestAnimationFrame(frame);
    });
}

function timestamp() {
    return window.performance && window.performance.now ?
        window.performance.now() :
        new Date().getTime();
}

function nextDirection() {
    if (!nextDirection.prototype.stepArray) {
        var script = $('textarea').val();
        var lines = script.split('\n');
        nextDirection.prototype.stepArray = [];

        lines.forEach(function (line) {
            nextDirection.prototype.stepArray.push(line);
        });
    }

    return nextDirection.prototype.stepArray.shift();
}

function update(deltaTime) {
    var position = robot.position();
    var speed = 2;

    if ((position.left - 6) % 68 === 0 && (position.top - 6) % 68 === 0) {
        switch (nextDirection()) {
            case 'right':
                robot['dx'] = 1;
                robot['dy'] = 0;
                break;
            case 'left':
                robot['dx'] = -1;
                robot['dy'] = 0;
                break;
            case 'down':
                robot['dx'] = 0;
                robot['dy'] = 1;
                break;
            case 'up':
                robot['dx'] = 0;
                robot['dy'] = -1;
                break;
            default:
                robot['dx'] = 0;
                robot['dy'] = 0;
        }
    }

    robot.css('left', position.left + robot.dx * speed);
    robot.css('top', position.top + robot.dy * speed);
}

function frame() {
    now = timestamp();
    // duration in seconds, maximum 1 sec
    deltaTime = Math.min(1, (now - last) / 1000);
    update(deltaTime);
    //render(deltaTime);
    last = now;

    requestAnimationFrame(frame);
}

@@ -1117,24 +1117,69 @@
 68 === 0) %7B%0A
+        robot.dx = 0;%0A        robot.dy = 0;%0A%0A
         swit
@@ -1252,53 +1252,17 @@
 obot
-%5B'dx'%5D
+.dx
  = 1;%0A
-                robot%5B'dy'%5D = 0;%0A
     
@@ -1330,54 +1330,18 @@
 obot
-%5B'dx'%5D
+.dx
  = -1;%0A
-                robot%5B'dy'%5D = 0;%0A
     
@@ -1409,47 +1409,11 @@
 obot
-%5B'dx'%5D = 0;%0A                robot%5B'dy'%5D
+.dy
  = 1
@@ -1485,47 +1485,11 @@
 obot
-%5B'dx'%5D = 0;%0A                robot%5B'dy'%5D
+.dy
  = -
@@ -1539,74 +1539,8 @@
 lt:%0A
-                robot%5B'dx'%5D = 0;%0A                robot%5B'dy'%5D = 0;%0A
     

Refactor update() function