How ycchnn/final-project works
Project Type and Purpose
• This is a single-executable C++ game (tower-defense style) using the Allegro graphics/audio library.
File Structure
• Top-level code: Main.cpp, Game.cpp/h, Level.cpp/h, UI.cpp/h, OperationCenter, DataCenter and other “Center” classes under data/.
• Assets: assets/ contains subfolders for fonts, images, GIFs, sounds, and level text files.
• Support libraries: algif5/ for GIF decoding.
• Build & config: makefile, Doxyfile.
Core Components
a. External Library
• Allegro5 (graphics, input, audio)
• algif5 (GIF decoding)
b. Application Entry Point
• Main (Main.cpp) → initializes Engine
c. Core Engine / Game Loop
• Game class (Game.cpp/h): init(), runLoop(), cleanup()
• Level class: encapsulates level data and progression
d. Resource Managers (“Centers”)
• DataCenter → orchestrates resource loading/unloading
• FontCenter, GIFCenter, ImageCenter, SoundCenter → wrap Allegro calls
• OperationCenter → input handling & event dispatch
e. Entities & Domain Objects
• Monsters (monsters/): Monster base and specific types
• Towers (towers/): Tower base, specialized towers, bullets
• Player, Object, UI classes
f. Assets Storage
• File-based assets under assets/ (images, GIFs, sounds, levels)
g. Utilities
• algif5 library
• Utils.h for shared definitions
Relationships & Data Flows
• Main → Game.init()
• Game.init() → DataCenter.loadAll():
• FontCenter, GIFCenter, ImageCenter, SoundCenter read files from assets/
• Game.runLoop():
• OperationCenter polls Allegro events (keyboard, mouse)
• Input events → OperationCenter → Game/Level/Player
• Game.update() updates Level, Entities (monsters, towers)
• SoundCenter plays effects/music on events
• Level contains & manages Entities; Entities request assets from DataCenter
• On exit: Game.cleanup() → DataCenter.freeAll()
Architectural Patterns & Principles
• Manager/Center pattern: centralized resource management.
• Game Loop pattern.
• Component-based entities: base classes + specialized subclasses.
• Separation of concerns: rendering, input, audio, logic all in separate modules.
Final Checklist
• Initialization sequence
• Game loop data flows