making a pause function
Posted: Wed Oct 02, 2019 9:58 pm
I am trying to make a replica of Flappy Bird. One part of the assignment is to make a pause function. I have implemented one but it does not work in the game. Here is the code.
Code: Select all
PauseState = Class{__includes = BaseState}
function PauseState:init()
self.timer = 0
self.enterParams = {}
end
function PauseState:update(dt)
self.timer = self.timer + dt
if love.keyboard.wasPressed('enter') or love.keyboard.wasPressed('return') then
self.enterParams = {
['bird'] = self.bird,
['pipePairs'] = self.pipePairs,
['timer'] = self.timer,
['score'] = self.score
}
self.timer = self.timer + 10
gStateMachine:change('play', self.enterParams)
end
end
function PauseState:enter(enterParams)
scrolling = false
self.bird = enterParams.bird
self.pipePairs = enterParams.pipePairs
self.timer = enterParams.timer
self.score = enterParams.score
end
function PauseState:render()
love.graphics.setFont(flappyFont)
love.graphics.printf('The game paused!', 0, 64, VIRTUAL_WIDTH, 'center')
love.graphics.setFont(mediumFont)
love.graphics.printf('Press Enter to continue', 0, 100, VIRTUAL_WIDTH, 'center')
love.graphics.print(self.timer .. tostring(self.score), 8, 38)
end