You can do this by having a variable to hold the state the game is in.
It can be set first in
love.load.
Code: Select all
function love.load()
state = 'play'
end
If the state is
'play' and the escape key is pressed, you can then set the state to something else, e.g.
'quitting'.
And if the state is
'quitting' and some special key is pressed (like y for yes), then the game can quit.
And if the state is
'quitting' and some other key was pressed, then the state can change back to
'play'.
Code: Select all
function love.keypressed(key)
if state == 'play' then
if key == 'escape' then
print('this happens?')
state = 'quitting'
end
elseif state == 'quitting' then
if key == 'y' then
love.event.quit()
else
state = 'play'
end
end
end
What is drawn in
love.draw can be changed depending on the state.
Code: Select all
function love.draw()
love.graphics.print('Testing! The state is '..state, 10, 10)
if state == 'quitting' then
love.graphics.print('Are you sure you want to quit? (press "y" to quit)', 250, 250)
end
end
A .love file is attached with this example.
I hope this helps!