Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Games
Kapman
Commits
9f10c019
Commit
9f10c019
authored
Apr 05, 2021
by
Frederik Schwarzer
Browse files
pause prey and bonus timers if game is paused
parent
b14383b8
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/game.cpp
View file @
9f10c019
...
...
@@ -119,6 +119,8 @@ void Game::start()
{
// Restart the Game timer
m_timer
->
start
();
m_bonusTimer
->
start
();
m_preyTimer
->
start
();
m_state
=
RUNNING
;
Q_EMIT
pauseChanged
(
false
,
false
);
}
...
...
@@ -127,6 +129,19 @@ void Game::pause(bool p_locked)
{
// Stop the Game timer
m_timer
->
stop
();
if
(
m_bonusTimer
->
isActive
())
{
const
auto
remainingTime
{
m_bonusTimer
->
remainingTime
()};
m_bonusTimer
->
stop
();
m_bonusTimer
->
setInterval
(
remainingTime
);
}
if
(
m_preyTimer
->
isActive
())
{
const
auto
remainingTime
{
m_preyTimer
->
remainingTime
()};
m_preyTimer
->
stop
();
m_preyTimer
->
setInterval
(
remainingTime
);
}
if
(
p_locked
)
{
m_state
=
PAUSED_LOCKED
;
}
else
{
...
...
@@ -288,8 +303,17 @@ void Game::setTimersDuration()
// Updates the timers duration ratio with the ghosts speed
s_durationRatio
=
Character
::
MEDIUM_SPEED
/
m_ghosts
[
0
]
->
getNormalSpeed
();
// Updates the timers duration
setPreyTimerDuration
();
setBonusTimerDuration
();
}
void
Game
::
setBonusTimerDuration
()
{
m_bonusTimer
->
setInterval
((
int
)(
s_bonusDuration
*
s_durationRatio
));
}
void
Game
::
setPreyTimerDuration
()
{
m_preyTimer
->
setInterval
((
int
)(
s_preyStateDuration
*
s_durationRatio
));
}
...
...
@@ -526,6 +550,8 @@ void Game::nextLevel()
void
Game
::
hideBonus
()
{
Q_EMIT
bonusOff
();
setBonusTimerDuration
();
}
void
Game
::
endPreyState
()
...
...
@@ -535,4 +561,6 @@ void Game::endPreyState()
m_ghosts
[
i
]
->
setState
(
Ghost
::
HUNTER
);
}
}
setPreyTimerDuration
();
}
src/game.h
View file @
9f10c019
...
...
@@ -229,6 +229,8 @@ private:
* The value is in Ghost::s_speed
*/
void
setTimersDuration
();
void
setPreyTimerDuration
();
void
setBonusTimerDuration
();
public
Q_SLOTS
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment