 hero = null
 #- constants
 for direction in ['NORTH','SOUTH','EAST','WEST']
-  @["#{direction}"] = direction
-  dir = @["DIR_#{direction}"] = do ->
-    {}
-  dir[direction] = true
-  dir.dirname = direction
-  dir.movement = false
-  dir.marked_for_deletion = false
-
-  dir.delete = ->
-    @marked_for_deletion = true
-
+  @["#{direction}"] = {NORTH: 1, SOUTH: 2, EAST: 4, WEST: 8}[direction]
+  @["DIR_#{direction}"] = new ->
+    @[direction] = true
+    @.dirname = window[direction]
+    @.movement = false
+    @.marked_for_deletion = false
+    @.delete = ->
+      @marked_for_deletion = true
+    @
 
 #- helper methods
 rgba = (r,g,b,a) ->

      width: 32
      height: 32
      image_src: 'images/link.png'
      dir: {}
      moving: false
    options.reverse_merge(option_defaults)
    @.reverse_merge(options)

    options.reverse_merge(option_defaults)

  check_moving: ->
    if @moving
      console.log 'moving'
      moving_states = {}
      moving_states[NORTH] = {x: 0, y: -1}
      moving_states[SOUTH] = {x: 0, y: 1}
      moving_states[EAST] = {x: 1, y: 0}
      moving_states[WEST] = {x: -1, y: 0}
      xo = yo = 0
      for dir in Object.keys(moving_states)
        if @dir & dir
          xo += moving_states[dir].x
          yo += moving_states[dir].y
      @move_to @x + xo, @y + yo

  heading: (dir) ->
    @dir & dir.dirname

  start_moving: (dir) ->
    @dir = switch dir.dirname | @dir
      when 3,12 then dir
      else dir.dirname | @dir
    @moving = true

  stop_moving: (dir)->
    if (dir.EAST? and @heading(WEST)) or (dir.WEST? and @heading(EAST)) or (dir.NORTH? and @heading(SOUTH)) or (dir.SOUTH? and @heading(NORTH))
      @dir = dir.dirname
      return
    @dir = switch pending_dir = @dir ^ dir.dirname
      when 0
        console.log 'stopped'
        @moving = false
        dir.dirname
      else pending_dir

#- map
map_data = [1, 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,1,
