Snakes Pygame: Difference between revisions

Content added Content deleted
imported>Jesstess
imported>Jesstess
Line 40: Line 40:
So far, the snake can only move up or down. Fix this by completing 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.
So far, the snake can only move up or down. Fix this by completing 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. Give the game a better background ===

The game has a pretty boring solid color background. Spice it up by adding a background image. We've provided a sample background file call <code>leaves.jpg</code> in the Snakes directory, but create and add your own if you want!

Use [http://www.pygame.org/docs/ref/image.html#pygame.image.load pygame.image.load] to load the background. You'll need to re-display the background on every tick of the game, just like we currently do with the solid color using <code>game_surface.fill(BACKGROUND_COLOR)</code>.

=== 4. Set a key repeat speed ===


So far, you have to press an arrow key for each movement of the snake. Wouldn't it be convenient to be able to just hold down an arrow key to keep moving our snake?
So far, you have to press an arrow key for each movement of the snake. Wouldn't it be convenient to be able to just hold down an arrow key to keep moving our snake?
Line 48: Line 54:
Test your changes by re-running the game and holding down the arrow key while moving your snake around.
Test your changes by re-running the game and holding down the arrow key while moving your snake around.


=== 4. Handle quit and restart key presses ===
=== 5. Handle quit and restart key presses ===


I want to keep playing! So far, there's no way to quit (besides closing the window) or restart the game.
I want to keep playing! So far, there's no way to quit (besides closing the window) or restart the game.