How trung24012001/opengl_gravity_duck works
Project type and purpose
• This is a stand-alone 2D platformer game (“Gravity Duck”) written in C++ using OpenGL for graphics and SDL2/SDL2_mixer for audio.
• It reads plain-text map files, loads sprites and sounds, runs a game loop to process input, update game logic (gravity, collisions, enemies), render frames, and play audio.
File structure
• Top-level source files (main.cpp, game.cpp, menu.cpp, move.cpp, sound.cpp, aFunc.cpp) contain the application entry point, game loop, input handling, rendering calls, audio calls, and utility functions.
• “cPlayer.cpp, cEnemy.cpp, cBullet.cpp, cSwitch.cpp” implement entity classes and their behaviors.
• Resource folders:
• Images/ (textures, sprite sheets organized by Enemies, Game, Menu)
• Sounds/ (background music and effects)
• Maps/ (.txt files describing level layout, switches, enemy placement)
• Build artifacts and scripts: Makefile.win, Dev C++ project file (Gravity_Duck.dev, .layout).
Key insights from README
• Dependencies and linker flags (OpenGL, GLU, GLUT, SDL2, SDL2_mixer)
• File format (duck spawn, goal, tile grid, switches, enemies)
• Of enemy types and their parameters
• Single-binary Win32/Ubuntu builds, no client-server split
Components
a. Main modules
1. Application Entry & Initialization (main.cpp)
2. Game Loop (game.cpp)
3. Input Manager (SDL2 event polling)
4. Resource Manager / Map Loader (parses Maps/*.txt, loads textures/sounds)
5. Entity System (cPlayer, cEnemy, cBullet, cSwitch classes)
6. Physics & Collision (gravity direction, tile collisions, switch logic)
8. Audio Manager (sound.cpp using SDL2_mixer)
9. Menu & UI (menu.cpp)
10. Utility Functions (aFunc.cpp, move.cpp helper routines)
b. External libraries
– OpenGL (graphics pipeline)
– GLU/GLUT (window/context creation, input hookup)
– SDL2 (input, window management)
– SDL2_mixer (audio playback)
c. Data stores
– Map files (Maps/*.txt)
– Image assets (Images/)
– Sound assets (Sounds/)
Relationships and data flows
• Startup → initialize SDL2, OpenGL, audio
• Game Loop:
• Input Manager → reads keyboard/joystick events → pushes to Game Logic
• Resource Manager → provides textures, sound buffers, map data
• Game Logic → updates Entities (position, velocity, collisions)
• Renderer ← draws current game state
• Audio Manager ← plays background/stage music and effects
• Menu component branches off from Game Loop on pause/start
Architectural patterns and design principles
• Modular separation: Input, Logic, Rendering, Audio in distinct modules
• Entity-component style: each game object (player, enemy, bullet, switch) has its own class and update/render methods
• Single-process, event-driven game loop
• Resource centralization: one loader for all assets to avoid duplication
Final checklist
• All major modules are present and labeled
• Resource inputs (Maps, Images, Sounds) are clearly linked
• External libraries are shown