(function() {
  "use strict";

  VAGABOND.namespace("VAGABOND.CONTROLLER");

  VAGABOND.CONTROLLER = (function(module) {

    var Controller = {};

    Controller.init = function(controls) {
      this.controls = controls;

      return this;
    };

    Controller.processInput = function(screen, milo, map, level) {
      if (this.controls.eventStack.length > 0) {

        var event = this.controls.eventStack.pop();

        var things = {
          screenUp: {dx: 0, dy: -1, entity: screen, useTurn: false},
          screenDown: {dx: 0, dy: 1, entity: screen, useTurn: false},
          screenLeft: {dx: -1, dy: 0, entity: screen, useTurn: false},
          screenRight: {dx: 1, dy: 0, entity: screen, useTurn: false},
          charUp: {dx: 0, dy: -1, entity: milo, useTurn: true},
          charDown: {dx: 0, dy: 1, entity: milo, useTurn: true},
          charLeft: {dx: -1, dy: 0, entity: milo, useTurn: true},
          charRight: {dx: 1, dy: 0, entity: milo, useTurn: true}
        };

        var move = things[event];

        if (move && move.entity.isValidMove(move.dx, move.dy, map)) {
          move.entity.move(move.dx, move.dy);
        }

        if (move && move.useTurn) {
          level.takeTurn();
        }

        if (event === "normalize") {
          VAGABOND.ALGORITHMS.cellularAutomata(map, 1);
        }

        level.renderTo(screen);
        screen.renderToElement(document.body);
      }
    };

    module.Controller = Controller;

    return module;

  })(VAGABOND.CONTROLLER);
})();

@@ -291,20 +291,22 @@
 screen, 
-milo
+avatar
 , map, l
@@ -428,21 +428,20 @@
     var 
-thing
+move
 s = %7B%0A  
@@ -753,36 +753,38 @@
 dy: -1, entity: 
-milo
+avatar
 , useTurn: true%7D
@@ -820,36 +820,38 @@
  dy: 1, entity: 
-milo
+avatar
 , useTurn: true%7D
@@ -888,36 +888,38 @@
  dy: 0, entity: 
-milo
+avatar
 , useTurn: true%7D
@@ -968,12 +968,14 @@
 ty: 
-milo
+avatar
 , us
@@ -1022,13 +1022,12 @@
 e = 
-thing
+move
 s%5Bev

Refactor code