Tron - Week 2 Beginner Project

    Tron - Week 2 Beginner Project

    Welcome to week 2

    By AI Club on 9/23/2024
    0

    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.

    Your Mission This Week

    1. Set up the game board

    2. Create a player that responds to input

    3. Implement basic collision detection

    1. Setting Up the Game Board (game_board.py)

    Copy the GameBoard class from the link below. You will need to implement each of the functions outlined in the file.

    game_board.py

    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:

    2. Creating a Player-Controlled 'Bike' (player.py)

    Copy the Player class from the file below. You will need to implement each of the functions outlined in the file.

    player.py

    Tips:

    • 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

    3. Implementing the Main Game Loop (tron_game.py)

    Copy the functions from the file below. You will need to implement each of the functions outlined.

    tron_game.py

    Tips:

    • 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

    Testing your implementation

    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.py

    These 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!

    Bringing It All Together

    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:

    1. Initialize the game

    2. Enter the game loop:

      • Handle events (player input)

      • Update the game state (move player, check for collisions)

      • Draw the game

      • Control game speed

    3. 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.

    Bonus Challenges

    If you finish early or want to push yourself:

    1. Implement a scoring system

    2. 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!

    Comments