loop :: App -> IO App
loop app = do
  (_, h) <- prepareLoop app
  if not $ null $ handleKeys h
    then do
      isNotPlayingMusic <- fmap not SDLm.playingMusic
      if isNotPlayingMusic
        then SDLm.playMusic (music $ appConfig app) (-1)
        else do
            pausedMusic <- SDLm.pausedMusic
            if pausedMusic
                then SDLm.resumeMusic
                else SDLm.pauseMusic
      loop app
     else
      if handleQuit h then return app
                      else loop app
  {-(cTime, handle) <- prepareLoop app
  let timeForSaver = time - cTime + dtim
    in
      if timeForSaver > 0
        then let
         nApp = app {appLevels = (lvl {levelLength = timeForSaver}):lvls, appHandle = handle}
            in
              if handleQuit handle then return nApp else loop nApp
        else let
          nPlayer = player {beastPosition = levelStartPos $ head lvls}
          nApp = app {appLevels = lvls, appPlayer = nPlayer, appHandle = handle}
            in
              if handleQuit handle then return nApp else loop nApp-}
loop :: App -> IO App
loop app = do
  (_, h) <- prepareLoop app
  if not $ null $ handleKeys h
    then do
      isNotPlayingMusic <- fmap not SDLm.playingMusic
      if isNotPlayingMusic
        then SDLm.playMusic (music $ appConfig app) (-1)
        else do
            pausedMusic <- SDLm.pausedMusic
            if pausedMusic
                then SDLm.resumeMusic
                else SDLm.pauseMusic
      loop app
     else
      if handleQuit h then return app
                      else loop app
  {-(cTime, handle) <- prepareLoop app
  let timeForSaver = time - cTime + dtim
    in
      if timeForSaver > 0
        then let
         nApp = app {appLevels = (lvl {levelLength = timeForSaver}):lvls, appHandle = handle}
            in
              if handleQuit handle then return nApp else loop nApp
        else let
          nPlayer = player {beastPosition = levelStartPos $ head lvls}
          nApp = app {appLevels = lvls, appPlayer = nPlayer, appHandle = handle}
            in
              if handleQuit handle then return nApp else loop nApp-}
loop app = do
  (_, h) <- prepareLoop app
  if not $ null $ handleKeys h
    then do
      isNotPlayingMusic <- fmap not SDLm.playingMusic
      if isNotPlayingMusic
        then SDLm.playMusic (music $ appConfig app) (-1)
        else do
            pausedMusic <- SDLm.pausedMusic
            if pausedMusic
                then SDLm.resumeMusic
                else SDLm.pauseMusic
      loop app
     else
      if handleQuit h then return app
                      else loop app
  {-(cTime, handle) <- prepareLoop app
  let timeForSaver = time - cTime + dtim
    in
      if timeForSaver > 0
        then let
         nApp = app {appLevels = (lvl {levelLength = timeForSaver}):lvls, appHandle = handle}
            in
              if handleQuit handle then return nApp else loop nApp
        else let
          nPlayer = player {beastPosition = levelStartPos $ head lvls}
          nApp = app {appLevels = lvls, appPlayer = nPlayer, appHandle = handle}
            in
              if handleQuit handle then return nApp else loop nApp-}