How phatcao1205/flappy-nyan-sdl2 works
Project Type & Purpose
• This is a C++ game project that recreates the mechanics of Flappy Bird but with a Nyan Cat theme. It is built as a desktop game using the SDL2 graphics library.
• The game features core mechanics (character physics, collision detection, scoring, and game state management), animated graphics, and audio playback.
Main Components to Model
a. Game Engine / Main Module:
• Represented by src/main.cpp and src/Game.cpp.
• Acts as the central orchestrator that sets up the game loop, initializes SDL2, loads resources, and manages overall game state transitions (Menu, Playing, Game Over, Pause, etc).
b. Game Logic & Entity Modules:
• Bird Module: (include/Bird.h, src/Bird.cpp) encapsulating the player character behavior, movement (gravity and jump dynamics), and animation handling.
• Pipe Module: (include/Pipe.h, src/Pipe.cpp) for handling obstacles, generating pipes with a gap, and managing their movement across the screen.
• Background Module: (include/background.h; src/background.cpp) to manage the scrolling backgrounds and parallax effects.
• Menu Module: (include/menu.h; src/menu.cpp) to handle UI components for various game states (Menu, Pause, Info screens, etc).
• Score Module: (include/score.h; src/score.cpp) to manage in-game scoring, display of scores using imagery (digits), and updating high score records saved in highScore.txt.
c. Audio Manager:
• Sound Module: (include/sound.h; src/sound.cpp) handling sound effects and background music (assets in sounds directory).
d. Resource Management:
• Assets Management for loading images and other graphics (assets directory) and sounds (sounds directory).
• File I/O for persistent high score storage (include/highScore.txt).
Relationships and Interactions
• The Main Module initializes all subsystems (graphics, audio, input).
• The Game Engine interacts with the Bird, Pipe, and Background modules to update their states each frame.
• The Menu and Score components are used during the different game state screens (Start, Game Over, Pause).
• The Sound module is invoked by other modules (e.g., Bird jumps, collision detection) to play the appropriate effects.
• Input events (keyboard and mouse) are processed by the main loop and key dispatches go to change game states or trigger actions in the game logic.
• File I/O is used at startup and when scoring updates occur (reading/writing highScore.txt).
Important Architectural Patterns or Design Principles
• Modular design: Each game component (Bird, Pipe, Menu, Score, Sound, etc.) is encapsulated in its own module.
• State Machine: The game state transitions (Menu, Playing, Game Over, Pause, etc.) are clearly managed; this should be highlighted as controlling the flow of the game.
• Separation of Concerns: Rendering, collision logic, audio, and input are split across different modules.
Elements
• At the center: the Game Engine (from main.cpp and Game.cpp).
• Surrounding the engine: the core gameplay modules (Bird, Pipe, Background) that update per frame and interact with the engine.
• Off to one side: UI components, including Menu and Score modules, which are invoked based on game state.
• At the bottom or periphery: the Resource Manager area that handles assets (graphics and sounds) and file I/O for high scores.
• Audio Module: depicted as a connected service that receives events from various modules for triggering sound effects.