Jump to content
  • Advertisement
Sign in to follow this  
eektor

How do you pause a game?

This topic is 4350 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I am trying to implement a pause for my pong game. I was wondering how you go about doing it. I tried already and I've been having problems. Anyways this is an abstraction of my game loop right now
While (user hasn’t quit)

{    Read input

     If user quits,
	Quit game

     Handle user input

     Computer AI

     Check Collisions

     Check for scoring

     Update positions on sprites

     Render sprites

     Control Framerate
}
What I've been trying to do to make a pause is this:
While (user hasn’t quit)

{    do 
        Read input

        If user quits,
	   Quit game
 
        Handle user input
     while ( game is paused and user hasn't quit)

     Computer AI

     Check Collisions

     Check for scoring

     Update positions on sprites

     Render sprites

     Control Framerate
}
Is this the right direction? or am I going about this wrong?

Share this post


Link to post
Share on other sites
Advertisement
Try something like -

While (user hasn’t quit)

{ Read input

If user quits,
Quit game

Check to see if game pause state has updated

if ( currently unpaused ) {

Handle user input

Computer AI

Check Collisions

Check for scoring

Update positions on sprites

Render sprites

}

Control Framerate
}


Share this post


Link to post
Share on other sites
You could also implement a state system to manage all of your different game states:


class State
{
Enter()
Exit()
Update()
Draw()
ReadInput()
}

class Pause : State
{
Draw()
{
Print on Screen ("Pausued!")
}
Update()
{
check if player presses ESC to set currentState to InGame state
}
}

class InGame : State
{
Update()
{
Move character and enemies
check if player presses ESC to set currentState to pause state
}
Draw()
{
Draw character and enemies
}
}

State currentState

While (user hasn’t quit)
{
currentState.ReadInput()
currentState.Update()
currentState.Draw()
Control Framerate
}

Share this post


Link to post
Share on other sites
Quote:
Original post by Mushu
Try something like -

While (user hasn’t quit)

{ Read input

If user quits,
Quit game

Check to see if game pause state has updated

if ( currently unpaused ) {

Handle user input

Computer AI

Check Collisions

Check for scoring

Update positions on sprites

Render sprites

}

Control Framerate
}




Might want to still render sprites and handle input out side of the if block

Share this post


Link to post
Share on other sites
so, you have the logic part, read input, update states, AI, etc, and the drawing part. When you pause the game, don't execute the logic part except reading input of course.

Share this post


Link to post
Share on other sites
In a pong game you only need to stop the player/computer paddle and the boll movement. Let's say you have a bool variable named "started". Make if statements in the movement code of the ball and the paddles. When you want to pause/unpause the game, you can do something like this:

// input code
if (keydown(P)) {
if (started)
started=false;
else
started=true;
}

Where you replace keydown(P) with the function you use for getting input.

Share this post


Link to post
Share on other sites
Thanks for the input.

@Rob Loach I think that is something I would like to do but in my next project. Thanks a lot, you gave me a good starting point to set up a state system manager. Is there a book or a tutorial that talks more about managing game states? Right now all I have for game states are Menu, Instructions, and Game.

@Mushu Thanks, I originally had the check to see if it was paused in the handle keyboard input, but I think its best to just separate it.

@Grain Why would I want to render sprites and handle input outside of the if block? This is for a simple pong game.

@password I have something similar. I have a bool variable named quit and one named pause.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Quote:
Original post by eektor
Thanks for the input.

@Rob Loach I think that is something I would like to do but in my next project. Thanks a lot, you gave me a good starting point to set up a state system manager. Is there a book or a tutorial that talks more about managing game states? Right now all I have for game states are Menu, Instructions, and Game.

@Mushu Thanks, I originally had the check to see if it was paused in the handle keyboard input, but I think its best to just separate it.

@Grain Why would I want to render sprites and handle input outside of the if block? This is for a simple pong game.

@password I have something similar. I have a bool variable named quit and one named pause.


you can make some cool effects while its paused :) (scroll the pause text or something).

as for handling input, well you want to handle input even if the game is paused (since you would want to be able to detect when the player unpauses)

Share this post


Link to post
Share on other sites
Also,
you might want to render outside the ifblock because what if you want the player to see the paddle and ball still? I did that when I made my pong clone (about a year ago now...lol).



Chad

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!