failureMenu :: Application -> Parent -> RenderStateRefs -> GameState
    -> AppState
failureMenu app parent sceneRenderState gameState =
  AppStateLooped (renderable waitFailureScreen) $ do
    config <- get
    triggerSound config $ failureSound $ applicationSounds app
    gameStateRef <- io $ newIORef gameState
    ignore $ waitForPressedButtonBackgroundScene app gameStateRef
                 (sceneMVar sceneRenderState) (const False)
                 (Just $ realToFrac afterLevelWaitTime)
    return $ menuAppStateSpecialized app (poller gameStateRef)
        (renderable backGround) AppStateLooped
        FailureMenu Nothing menuItems 0
  where
    menuItems =
--     (p "rewind to last savepoint", todo) :
        MenuItem (p "retry from beginning") (const $ freeGameState gameState (retryLevel gameState)) :
        MenuItem (p "quit level") (const $ freeGameState gameState parent) :
        []

    poller gameStateRef =
        waitForPressedButtonBackgroundScene app gameStateRef (sceneMVar sceneRenderState)
            (const True) Nothing
    backGround =
        sceneRenderState |:>
        MenuBackgroundTransparent
    waitFailureScreen =
        backGround |:>
        (addBottomLineSpacer $ centered $ vBox (length lines) $ lines)
    lines =
        renderable (failurePixmap (applicationPixmaps app)) :
        replicate (length menuItems + 1) lineSpacer ++
        []

-- | show a textual message and wait for a keypress
-- PRE: score /= Score_1_Tried
failureMenu :: Application -> Parent -> RenderStateRefs -> GameState
    -> AppState
failureMenu app parent sceneRenderState gameState =
  AppStateLooped (renderable waitFailureScreen) $ do
    config <- get
    triggerSound config $ failureSound $ applicationSounds app
    gameStateRef <- io $ newIORef gameState
    ignore $ waitForPressedButtonBackgroundScene app gameStateRef
                 (sceneMVar sceneRenderState) (const False)
                 (Just $ realToFrac afterLevelWaitTime)
    return $ menuAppStateSpecialized app (poller gameStateRef)
        (renderable backGround) AppStateLooped
        FailureMenu Nothing menuItems 0
  where
    menuItems =
--     (p "rewind to last savepoint", todo) :
        MenuItem (p "retry from beginning") (const $ freeGameState gameState (retryLevel gameState)) :
        MenuItem (p "quit level") (const $ freeGameState gameState parent) :
        []

    poller gameStateRef =
        waitForPressedButtonBackgroundScene app gameStateRef (sceneMVar sceneRenderState)
            (const True) Nothing
    backGround =
        sceneRenderState |:>
        MenuBackgroundTransparent
    waitFailureScreen =
        backGround |:>
        (addBottomLineSpacer $ centered $ vBox (length lines) $ lines)
    lines =
        renderable (failurePixmap (applicationPixmaps app)) :
        replicate (length menuItems + 1) lineSpacer ++
        []

-- | show a textual message and wait for a keypress
-- PRE: score /= Score_1_Tried
failureMenu app parent sceneRenderState gameState =
  AppStateLooped (renderable waitFailureScreen) $ do
    config <- get
    triggerSound config $ failureSound $ applicationSounds app
    gameStateRef <- io $ newIORef gameState
    ignore $ waitForPressedButtonBackgroundScene app gameStateRef
                 (sceneMVar sceneRenderState) (const False)
                 (Just $ realToFrac afterLevelWaitTime)
    return $ menuAppStateSpecialized app (poller gameStateRef)
        (renderable backGround) AppStateLooped
        FailureMenu Nothing menuItems 0
  where
    menuItems =
--     (p "rewind to last savepoint", todo) :
        MenuItem (p "retry from beginning") (const $ freeGameState gameState (retryLevel gameState)) :
        MenuItem (p "quit level") (const $ freeGameState gameState parent) :
        []

    poller gameStateRef =
        waitForPressedButtonBackgroundScene app gameStateRef (sceneMVar sceneRenderState)
            (const True) Nothing
    backGround =
        sceneRenderState |:>
        MenuBackgroundTransparent
    waitFailureScreen =
        backGround |:>
        (addBottomLineSpacer $ centered $ vBox (length lines) $ lines)
    lines =
        renderable (failurePixmap (applicationPixmaps app)) :
        replicate (length menuItems + 1) lineSpacer ++
        []

-- | show a textual message and wait for a keypress
-- PRE: score /= Score_1_Tried