 # TODO: these should handle the passage of time? or maybe that is up to
 # stepLevelSimulation?
 moveCommand = (level) ->
-  level.bot.xi += @dir.dx
-  level.bot.yi += @dir.dy
-  level.bot.dir = @dir.theta
+  switch level.mode
+    when levelMode.PLAYING, levelMode.FULLPLAYING
+      level.bot.xi += @dir.dx
+      level.bot.yi += @dir.dy
+      level.bot.dir = @dir.theta
+    when levelMode.REVPLAYING
+      dir = reverseDir(@dir)
+      level.bot.xi += dir.dx
+      level.bot.yi += dir.dy
+      level.bot.dir = dir.theta
 
 noActionCommand = (level) ->
   return
 
 arrowCommandRender = (ctx) ->
   renderArrow(ctx, @dir.theta, inner_command_size)
+
+reverseCommandRender = (ctx) ->
+  ics  = inner_command_size
+
+  ctx.beginPath()
+  ctx.moveTo(-ics*.2, -ics*.3)
+  ctx.lineTo(0, -ics*.3)
+  ctx.arc(0,0,ics*.3, -Math.PI/2, Math.PI/2, false)
+
+  ctx.lineTo(-ics*.2, ics*.3)
+  ctx.lineTo(-ics*.1, ics*.15)
+  ctx.moveTo(-ics*.2, ics*.3)
+  ctx.lineTo(-ics*.1, ics*.45)
+
+  ctx.stroke()
+
+  return
 
 up_arrow_cmd =
   render: arrowCommandRender


# buttons

addCommandButtonAction = (level) ->
  switch level.mode
    when levelMode.STOPPED
      level.commands[level.current_command] = @cmd
      level.advanceCurrentCommand()
    when levelMode.PLAYING
      level.commands[level.commands.length] = @cmd

  return

playButtonAction = (level) ->
  level.resetAndRun()
  return

undoButtonAction = (level) ->

LEFT = (theta: Math.PI, dx: -1, dy: 0)
RIGHT = (theta: 0, dx: 1, dy: 0)
DOWN = (theta: -Math.PI/2, dx: 0, dy: 1)

reverseDir = (dir) ->
  switch dir
    when UP
      return DOWN
    when DOWN
      return UP
    when LEFT
      return RIGHT
    when RIGHT
      return LEFT

renderArrow  = (ctx, dir, size) ->
  as = size*.75  # arrow size
