Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add pause functionality #16

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ Collect as many alcoholic drinks as possible, while avoiding the `Beer` drinks.
| w | Accelerate |
| s | Decelerate |
| q | Quit game |
| p | Pause game |

### Installation

Expand Down
15 changes: 11 additions & 4 deletions asciiracer/game.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
'debris': [], # debris objects drawn in scene
'money': [], # money objects drawn in scene
'score': 0,
'pdb': False} # for testing
'pdb': False, # for testing
'paused': False} # Add the 'paused' key


@limit_fps(fps=FPS)
Expand All @@ -41,12 +42,18 @@ def main(screen):
key = screen.getch()
if key == ord('q'):
break
elif key == ord('p'):
elif key == ord('p'): # Use the 'p' key to pause the game
state['paused'] = not state['paused'] # Toggle the 'paused' state
elif key == ord('t'): # Use the 't' key to enable testing/debugging mode
state['pdb'] = True
else:
state['pdb'] = False

if not state['paused']: # If the game is not paused, update the state
draw_scene(screen)
update_state(key, state)
state['frames'] += 1
state['time'] += 1/FPS
state['frames'] += 1
state['time'] += 1/FPS
screen.clear()
screen.getkey()

Expand Down