 map = null
 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
-
+for direction in ['NORTH','SOUTH','EAST','WEST', 'NORTH_EAST', 'NORTH_WEST', 'SOUTH_EAST','SOUTH_WEST']
+  @["#{direction}"] = {NORTH: 1, SOUTH: 2, EAST: 4, WEST: 8, NORTH_EAST: 5, NORTH_WEST: 9, SOUTH_EAST: 6, SOUTH_WEST: 10}[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) ->

  key.released()

KeyBoard.A_pressed = ->
  hero.start_moving DIR_WEST
KeyBoard.A_released = ->
  hero.stop_moving DIR_WEST

KeyBoard.D_pressed = ->
  hero.start_moving DIR_EAST
KeyBoard.D_released = ->
  hero.stop_moving DIR_EAST

KeyBoard.W_pressed = ->
  hero.start_moving DIR_NORTH
KeyBoard.W_released = ->
  hero.stop_moving DIR_NORTH

KeyBoard.S_pressed = ->
  hero.start_moving DIR_SOUTH
KeyBoard.S_released = ->
  hero.stop_moving DIR_SOUTH

window.KeyBoard = KeyBoard
window.onload= ->

    options.reverse_merge(option_defaults)

  check_moving: ->
    if @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

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

  stop_moving: (dir)->
    @moving = switch @dir
      when NORTH_EAST,NORTH_WEST,SOUTH_EAST,SOUTH_WEST then true
      else false
    @dir = switch (pending_dir = @dir ^ dir)
      when 0, (NORTH|SOUTH),(EAST|WEST) then dir
      else pending_dir

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