         @_turn Direction.Right
         @_run Direction.Right
 
-      else if not @inMidAir()
-        @nextAction = if @velocity.x is 0 then Action.Start else Action.Stop
-        if @velocity.x is 0
-          @state = State.Still
-          @animations.frame = 17
+      else unless @isInMidAir()
+        if @velocity.x isnt 0 then @nextAction = 'stop'
+        else @nextState = 'still'
+
+      @_updateAnimations()
+      @_changeState @nextState
 
     _initAnimations: ->
       @animations.add 'run', [0..11], 24, on


      @cursors = game.input.keyboard.createCursorKeys()

      @animation = null
      @state = State.Still
      @nextAction = Action.None

    inMidAir: -> no

    update: ->
      # Horizontal

      @nextAction = Action.None
      @acceleration.x = 0

      ###
      - Basically handle switching direction, and running or being still

      w = @sprite.width
      @_yOffset = h / 4
      @physics.setSize (w / 2), (h / 2), @_xOffset(), @_yOffset
      @_justTurned = no # Because velocity won't be 0 when just turning.

    _changeAnimation: (nameOrFrame, interrupt = yes) ->
      return if interrupt is no and @animation?.isPlaying

      if _.isNumber(nameOrFrame)
        frame = nameOrFrame
        return if @animations.frame is frame
        @animations.frame = frame
        @animation = null

      else
        name = nameOrFrame
        return if @animation?.name is name
        animation = @animations.play name
        @animation = animation

      @debug 'animation', nameOrFrame

    _changeState: (state) ->
      return if state is @state

      @state = state
      @debug 'state', state

    _run: (direction) ->
      @nextAction = 'start' if @velocity.x is 0

      factor = 200
      if @isInMidAir()
        # TODO
      else @nextState = 'running'
      @acceleration.x = factor * direction

    _turn: (direction) ->
      return if @isRunning(direction)

      if @_justTurned
        @nextAction = 'start'
        @_justTurned = no
      else if @velocity.x isnt 0 and @nextAction isnt 'stop'
        @nextAction = 'stop'
        @_justTurned = yes

      @direction = direction
      @sprite.scale.x = direction
      @physics.offset = new Phaser.Point @_xOffset(direction), @_yOffset

    _updateAnimations: ->
      unless @isInMidAir() or @nextAction is 'none'
        @_changeAnimation @nextAction
        return

      switch @nextState
        when 'running' then @_changeAnimation 'run', no
        when 'still' then @_changeAnimation 17, no

    _xOffset: (direction = @direction) -> direction * 10

  Player
