Having trouble making a pause cool down

Hello, I’m trying to implement pausing in my game and have noticed that when I press the button combo to pause it pauses and resumes over and over again. So I tried to make a pause cool down when the game is unpaused so you cannot pause it over and over by accident. However my code doesn’t seem to work. Currently once the game is unpaused I made a loop in the game part of the code if the cool down variable is true the pause command wouldn’t work, however it doesn’t work. My code is all at https://github.com/GerdGames/CowBro if you want to look at it and tell me what is wrong. Thank you.

Without looking at your specific code, here is how I would do it:

boolean pausebuttonfree = true;
boolean gamepaused = false;
void loop() {
    if(arduboy.pressed(A_BUTTON) && pausebuttonfree) {
        pausebuttonfree = false;
        gamepaused = !gamepaused;
    if(gamepaused) {
        //Code for when the game is paused...
    } else {
        //Code for when the game is not paused...
    if(arduboy.notPressed(A_BUTTON)) {
        pausebuttonfree = true;

I had a look at your game. (Nice graphics :slight_smile: )
The problem is that after enabling a pause, you don’t have any ‘cool down’, you just set pause=true but not unpauseCooldown, so a microsecond later in the next cycle the code goes immediately into the ‘pause’ code, finds that A+B are still pressed and un-pauses. Hope that makes some sense. Also, it might be better instead of using ‘count’ and counting down, just use something like delay(1000) instead to ‘pause’ for a second or so.

The Arglib library that Team A.R.G. uses in their games (each game has its own copy) has poll() and justPressed() functions for handling buttons in a way that can be used for pause and other button detection. These functions came from the ArduboyExtra project.

Very soon, I plan to release a new version of my Arduboy2 library, which adds most of the additional functionality that Arglib provides, including the above functions. Instead of poll(), I named it pollButtons() for clarity but it’s the same function.

You may wish to implement the above functions locally in your code (and then maybe switch from using the Arduboy library to the Ardbuboy2 library when I release the next version).

Moderator Note:
Links to Team ARG’s website have been removed due to malicious new owners.


Thanks everyone! I ended up going with the solution from @crait and it also ended up making it so that the game screen was taken away when pause was active so it encourages twitchy and impulsive gameplay. Thanks for the compliment on my graphics too @Brian ! I tried to emulate older monochrome games, most specifically Sheriff by Nintendo.


I’m glad I could help! I can’t wait until your game’s done! Be sure to make a post when you release the game.

I certainly will! I think quick action oriented games with high scores and lots of skill involved would work best on the arduboy as they have lots of replay value, and little memory footprint. It’s pretty close to being finished with one more game play mechanic I want to add, and then just some more cosmetic things like a menu graphic, some background objects, and maybe more variety in targets.

1 Like