Home > Computer Programming > Pygame stuff

Pygame stuff

November 7, 2014 Leave a comment Go to comments

Install Python 2.7 and Pygame 1.9. Make sure you get the right versions. Mac? Windows? 64-bit? 32-bit? etc

Basic tasks to start with

  • Get the Pygame screen to appear.
  • Get a small image to appear.
  • Make it move.
  • Make it responds to mouse clicks.

Only now can you begin to think about games.

A basic game loop:

HighLevelGameLoopArchitecture_1149081_11

  • Processing user input will use the pygame.event module.
  • Updating the game world will almost certainly be a nested loop to run through each sprite to get them to react to the current game state. Pygame allows you to group similar sprites and call their update() methods. If you don’t use a pygame.sprite.Group then you will almost certainly keep multiple sprites of the same type in a list and run through the list:
     for enemy in enemiesList:
         enemy.update()
  • Rendering the game world will involve making calls to the Pygame objects’ draw() methods.

Other obvious functions you might program are:

  • gameOver(): Checks to see if a game over state has been reached and returns true if it has, false otherwise.
  • changeScore(): Keeps the score up-to-date.
Advertisements
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s