-
Notifications
You must be signed in to change notification settings - Fork 0
Source code walkthrough
BubbleGrow is designed to be "easier" to understand and is filled with comments to help navigate each section. The basic breakdown of the game is into two sections: the "game state", which holds all information regarding the game and processes the game; and the "GUI" section, which handles everything the player sees, hears, and inputs into the game from his keyboard and mouse.
This walk through is divided by the two sections and covers the source code by the main classes in the source code.
The game state handles the game's logic and units, and can run completely on its own (it has no knowledge of the graphics, audio, and input). The game state is divided into 3 major classes: the World, the Players that belong to that World, and the Units that belong to each Player.
The "World" class manages a single game. It holds references to each Player (including computer players), determines the size of the game world, and has functions that process the entire game world.
Important variables
- std::unordered_map<uint64_t, std::shared_ptr> players: A map that contains each Player reference, access by their unique id.
- double map_radius: Determines the size of the game world. Players who leave this area automatically lose all their units and are removed from the game.
Important methods
- void UpdateAndProcess(double duration): Processes one "cycle" of the game (where duration the length of a single frame in the game).
- std::shared_ptr<Player> AddPlayer(): Adds a new Player to the game, automatically assigning it a unique id.
- std::shared_ptr<Resources> AddResources(unsigned int amount, float radius, float density): Adds a "resource Player" to the game, which is a special player type that only exists to create the resource bubbles you see in game.
- std::shared_ptr<Unit> FindUnit(uint64_t owner_id, uint64_t unit_id): A helper function used by other classes to retrieve the reference for a specific Unit based on its unique id.
- void EndWorld(): This cleans up the game world, removing circular shared pointer references that would normally cause memory leaks. Since both the Player and Unit class also reference World, this has to be manually called instead of being in the destructor.