Snakes Pygame: Difference between revisions

From OpenHatch wiki
Content added Content deleted
imported>Jesstess
imported>Jesstess
Line 35: Line 35:


=== 2. Give snakes the ability to move in all directions ===
=== 2. Give snakes the ability to move in all directions ===

So far, the snake can only move up or down. Complete the "Handle the remaining movement keys" TODO in the <code>move</code> method of the <code>Snake</code> class. Test your changes by re-running the game and moving your snake left and right.


=== 3. Set a key repeat speed ===
=== 3. Set a key repeat speed ===

Revision as of 01:39, 25 May 2013

Project

Implement parts of a Snakes clone using the Pygame graphical game development library.

Goals

  • practice using the Pygame library
  • practice using an event loop to make action happen

Project setup

1. Install the project dependencies

Install Pygame. On Linux, you can use your package manager to install the python-pygame package. On Windows and OSX, you can download the appropriate binary from http://www.pygame.org/download.shtml.

2. Download and un-archive the Snakes project skeleton code

Un-archiving will produce a Snakes folder containing several Python files.

3. Test your setup

Run the snakes.py script in your Snakes directory. A window with a Snakes game should pop up, including square bits of food, the snake you can control, and the enemy snake. Try using the Up and Down keys to move your snake.

Project steps

1. Familiarize yourself with codebase

  • What is in snakes.py? What parts of the game is pygame responsible for?
  • What is in objects/snake.py? What actions can a snake take?
  • What is in objects/food.py? What determines where food shows up on the screen?

2. Give snakes the ability to move in all directions

So far, the snake can only move up or down. Complete the "Handle the remaining movement keys" TODO in the move method of the Snake class. Test your changes by re-running the game and moving your snake left and right.

3. Set a key repeat speed

4. Handle quit and restart key presses