     animate: animateLevel
     step: stepLevelSimulation
 
-    mode: levelMode.LIVE_EDIT
+    mode: levelMode.PLAYING
     animation_mode: levelAnimMode.READY
 
     advanceCurrentCommand: -> @current_command++


animateLevel = (t) ->

  if @mode == levelMode.STOPPED
    @show_current_command = @current_command
    @bot.showxi = @bot.xi
    @bot.showyi = @bot.yi
    @bot.showdir = @bot.dir

    return

  dt = t - @last_t

  # PLAYING or LIVE_EDIT

  if @animation_mode == levelAnimMode.READY
    @show_current_command = @current_command
    next_move_control =
      start: (t: t, x: @bot.xi, y: @bot.yi, dir: @bot.dir)
      duration: 1/bot_speed
    if not @step()

      switch @mode
        when levelMode.PLAYING
          @mode = levelMode.LIVE_EDIT
          @animation_mode = levelAnimMode.READY

        #when levelMode.LIVE_EDIT keep waiting
            
    else
      @move_control = next_move_control
      @animation_mode = levelAnimMode.MOVING


play_button =
  render: renderPlayButton
  action: playButtonAction
undo_button =
  render: renderUndoButton
  action: undoButtonAction

# level

levelMode =
  STOPPED: 1
  PLAYING: 2

levelAnimMode =
  READY: 1  # ready to run the next command
