Welcome to week 2
Welcome back, this week, we're transforming our Pygame window into a basic version of Tron. We'll focus on creating a modular structure and provide test code for each component to help you verify your implementation.
Set up the game board
Create a player that responds to input
Implement basic collision detection
Copy the GameBoard class from the link below. You will need to implement each of the functions outlined in the file.
Tips:
Use a 2D list to represent your game board
Each cell in your grid can be represented by a number (0 for empty, 1 for player, 2 for trail)
Use Pygame's drawing functions to visualize this grid on the screen
Resources:
Copy the Player class from the file below. You will need to implement each of the functions outlined in the file.
player.pyTips:
Store the player's position, direction, and trail
Use Pygame's event handling to capture keyboard input in your main game loop
Update the player's position based on their direction
Resources
Copy the functions from the file below. You will need to implement each of the functions outlined.
tron_game.pyTips:
Use Pygame's clock to control the game speed
Implement collision detection in the update_game_state function
Create a game over state when a collision is detected
Resources
We've provided test files for each component in the links below. After implementing each part, run the corresponding test (Make sure you're in the week2 directory you made at the start):
test_game_board.pytest_player.pytest_tron_game.pyThese tests will help you verify that your implementation meets the basic requirements. However, remember that passing all tests doesn't guarantee a perfect game - always test by playing it yourself too!
Your task is to implement these functions and create a basic, playable version of Tron (without the other player). Here's a general flow of how your game should work:
Initialize the game
Enter the game loop:
Handle events (player input)
Update the game state (move player, check for collisions)
Draw the game
Control game speed
End the game when a collision is detected
Remember, the goal is to understand these concepts deeply. Focus on getting the core functionality working, and don't worry if it doesn't look exactly like a polished Tron game quite yet.
If you finish early or want to push yourself:
Implement a scoring system
Add a "game over" screen with the option to restart
Next week, we'll expand on this foundation to create a two-player version and start thinking about how we'll integrate our AI. Keep up the great work!