             else @direction
         else @direction
 
+
+
     setTimeout(@move, 25)  
 
   render: =>

  move: =>
    step = 0.25
    diagStep = step / Math.sqrt(2)
    switch @direction
      when Dir.N then @camera.position.z = Math.max(@camera.position.z - step, -@worldSize)
      when Dir.NW

      when Dir.NE
        @camera.position.x = Math.min(@camera.position.x + diagStep, @worldSize)
        @camera.position.z = Math.max(@camera.position.z - diagStep, -@worldSize)

    # If jumping, move up a little and decrement frames.
    if @jumping
      @camera.position.y += jumpStep
      @jumpFramesLeft--
      @jumping = (@jumpFramesLeft > 0)

    # If not jumping, check for gravity
    unless @jumping
      loc = @currentLocation()
      loc.y = Math.max(loc.y - 2, -@worldSize)
      unless @isSolid(loc)
        @camera.position.y -= jumpStep

    setTimeout(@move, 25)

  currentLocation: ->
    x =
      if @camera.position.x > 0
        Math.ceil(@camera.position.x)
      else
        Math.floor(@camera.position.x)
    y =
      if @camera.position.y > 0
        Math.ceil(@camera.position.y)
      else
        Math.floor(@camera.position.y)
    z =
      if @camera.position.z > 0
        Math.ceil(@camera.position.z)
      else
        Math.floor(@camera.position.z)
    {
      x: x
      y: y
      z: z
    }

  isSolid: (loc) ->
    @cubes[loc.x] != undefined && @cubes[loc.x][loc.y] != undefined && 
    @cubes[loc.x][loc.y][loc.z] != undefined && @cubes[loc.x][loc.y][loc.z].solid

# Directions Enum for movement
Dir =
