Now that some basic XNA is in place, I can start to think about architecture. I'm going to use something like the following top-level objects:
- HumanPlayer - manages pieces representing entities controlled by human players via the CameraTracker
- DenizenPlayer - manages non-player pieces in the world (AI)
- WorldPlayer - manages environment pieces like the world grid, buildings, and the like
- Simulator - calculates physical interactions with the world and between pieces (physics simulation, such as it is)
- GameRef - the state manager for game "logic" (win/lose conditions, turns) based on pieces, simulator results, and game state
- GameState - the current state of the game (points per side, etc)
- GameController - the XNA Game object, renamed, handling high-level game start/stop/running.
- GameHUD - the GUI overlay for the game
- PieceWrangler - utility class for handling all the pieces in the game as groups between players
- SoundMgr - manages environmental sound from pieces and the world
Player classes manipulate Pieces, which are representations of the various "self-determining" entities in the game. Pieces possess the following kinds of information at minimum:
- Physical Properties for use by Simulator: position, direction, velocity, geometry, size
- Visual representation (model)
- Life state (spawning, alive, dying, dead)
- Helper methods for related to managing the above three classes of properties
- AI-relevant data: Current "State of Mind" and "Intention" in subclasses
- Other "piece type specific" data in subclasses
- Update() and Draw() methods
Player classes also implement Update() and Draw(). Each Player class maintain a list of managed pieces.
The GameController class, which is the root-level object, essentially will call the following loop:
- Player.Update(gameTime) on each Player class so each Player can update its pieces
- Simulator.Update(gameTime) tells all player pieces how to update their physical properties
- GameRef.Update(gameTime) examines the state of all Player and Piece classes, and changes their states accordingly. Also sets GameState for inspection by GameHUD and GameController
- All players Draw() in order of World, Denizens, and Players
- GameHUD.Draw()
- Loop
The actual loop may be more complicated than this to handle tricky interdependencies, but this is the basic idea.
