   'phaser'
 ], (Phaser) ->
 
-  Action =
-    None: 0
-    Stop: 1
-    Start: 2
-
   Direction =
     Left: -1
     Right: 1
 
-  State =
-    Still: 0
-    Running: 1
-
   class Player
-
-    @Action: Action
-    @Direction: Direction
-    @State: State
 
     constructor: (origin, game) ->
       @sprite = game.add.sprite origin.x, origin.y, 'player', 17

      w = @sprite.width
      @_yOffset = h / 4
      @physics.setSize (w / 2), (h / 2), @_xOffset(), @_yOffset

    _run: (direction) ->
      factor = 200
      if @inMidAir()
        # TODO
      else if @state isnt State.Running
        @state = State.Running
      @animations.play 'run' unless @animation?.isPlaying
      @acceleration.x = factor * direction

    _turn: (direction) -> # TODO: Replace with animation.
      return if direction is @direction
      shouldStop = @velocity.x isnt 0 and @nextAction isnt Action.Stop and @direction isnt direction
      if shouldStop
        @nextAction = Action.Stop
        @animation = @animations.play 'stop' unless @inMidAir()
      else if not @animation?.isPlaying
        @nextAction = Action.Start
        @animation = @animations.play 'start' unless @inMidAir()
      @direction = direction
      @sprite.scale.x = direction
      @physics.offset = new Phaser.Point @_xOffset(direction), @_yOffset

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

  Player

        @_turn Direction.Right
        @_run Direction.Right

      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
