Folders and files
| Name | Name | Last commit date | ||
|---|---|---|---|---|
Repository files navigation
This is a multiplayer version of the classic Flappy Bird game, built using Pygame. The game allows two players to compete side by side in a split-screen format, where each player controls their own bird to navigate through pipes. The game ends when one player collides with an obstacle, and the other player is declared the winner. Game Components: 1. Bird (Bird.py) The Bird class represents the player-controlled bird in the game. Key Attributes: image: Loads the bird sprite. rect: Defines the position and size of the bird. x_speed: The horizontal speed of the bird. y_speed: The vertical speed of the bird. y_acceleration: The gravitational acceleration affecting the bird. should_flip: Determines whether the bird image should be flipped. Key Methods: update(should_jump): Updates the bird’s position and animation. update_img_if_needed(): Animates the bird's wing flapping. update_pos(should_jump): Moves the bird in response to user input. apply_jump(): Makes the bird jump. change_dir(): Reverses the bird’s direction upon collision. 2. Pipe (Pipe.py) The Pipe class represents the obstacles that the birds must avoid. Key Attributes: image: Loads the pipe sprite. rect: Defines the position and size of the pipe. Key Methods: get_pipe_width(): Returns the width of the pipe. __init__(x_rel, y, screen_surface, is_up): Creates an instance of a pipe. 3. Player (Player.py) The PlayerInGame class manages an individual player's bird and pipes. Key Attributes: bird: An instance of the Bird class. pipe_group: A group of pipes for the player. score: The player's score. screen_surface: The player's half-screen for rendering. is_over: Indicates whether the player has lost. Key Methods: update(player_jumps): Updates the bird’s movement and checks for collisions. result_screen(won): Displays the game result screen with a color overlay. Additionally, create_pipe_group() is used to generate a set of pipes with a random gap. 4. Game (Game.py) The Game class manages the two-player gameplay. Key Attributes: player1: The first player’s PlayerInGame instance. player2: The second player’s PlayerInGame instance. screen: The main game screen. game_over: Boolean flag for game state. Key Methods: update(player1jumps, player2jumps): Updates both players and determines if the game is over. 5. Main (main.py) The main.py script initializes the game and handles the game loop. Key Features: Initializes Pygame and sets up the game window. Runs the game loop to capture player inputs and update the game state. Handles game-over conditions and restarts the game when necessary. Player Controls: Player 1 (Left Side): Press Left Arrow (←) to jump. Player 2 (Right Side): Press Right Arrow (→) to jump. Restart Game: Press Spacebar after a game over. Quit Game: Press Escape to exit. Game Flow The game starts with two birds positioned on separate halves of the screen. Players press their respective keys to make their birds jump. Birds automatically move horizontally while pipes spawn randomly. The game continues until a bird collides with an obstacle or the screen edges. The game announces the winner and allows players to restart.