How ansari-1417/centipede-game-programming-fundamentals works
Project type and purpose
• This is a standalone desktop game written in C++ using SFML. It recreates Atari’s Centipede, with added themes, textures, sounds, and a state-driven menu system.
File structure
• Centipede.cpp: single entry point containing setup and the main game loop.
• Music/, Sound_Effects/, Textures/, Text/: resource folders loaded at runtime.
• README.md: confirms SFML usage, game states (menu, instructions, settings, gameplay), and asset‐driven design.
Main components
a. Core Application
• Main/Entry Point (Centipede.cpp) – initializes SFML RenderWindow, Resource Manager, Game State Manager, starts the game loop.
• Game Loop – the heartbeat: handles input, updates game logic, renders frames, plays audio.
b. Resource Manager
• Asset Loader – reads from Music/, Sound_Effects/, Textures/, Text/ → loads SFML textures, sounds, fonts.
• Cache – stores loaded SFML::Texture, SFML::SoundBuffer, etc., to avoid reloading.
c. State Management
• GameState Manager – switches between MenuState, PlayState, PauseState, SettingsState, HighscoreState, ExitState.
• Individual State Modules – encapsulate UI rendering, input handling, and state-specific updates.
d. Game Logic / Entities
• Entities – Centipede segments, player shooter, mushrooms, bullets, enemies (spiders, fleas, scorpions).
• Entity Controller – updates positions, resolves collisions, spawns/despawns.
• Difficulty Manager – increases centipede speed, mushrooms count per level.
e. Rendering Subsystem
• SFML Graphics – draws sprites, UI overlays, text.
• Renderer – invoked each frame by the game loop.
f. Input and Audio
• Input Handler – polls SFML events, dispatches to active GameState.
• Audio Manager – plays background music (Music/…), sound effects (Sound_Effects/…) on game events.
Relationships and interactions
• Entry Point → initializes Resource Manager, GameState Manager, Audio Manager.
• Game Loop → iteratively calls Input Handler → GameState Manager (current state’s handleEvent/ update) → Renderer → Audio Manager.
• Resource Manager ↔ all subsystems (states, entities, renderer, audio) to supply assets on demand.
• State Modules rely on Entity Controller and Renderer.
• Difficulty Manager influences Entity Controller parameters each level.
Architectural patterns & design principles
• State Pattern for screens/menu/gameplay.
• Singleton or central managers for Resources and Audio.
• Separation of concerns: input, update, render, resource loading.
• Labels: component names, “loads”, “renders”, “updates.”
• Arrowheads: direction of calls or data.
• Detail level: break states into submodules (MenuState vs PlayState) only if needed.