Code Overview

From TACWiki
Revision as of 10:33, 20 January 2009 by Adn1646 (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

This page contains a high-level overview of the code for the Autism Game.

XNA

This game is built on XNA, which is suite of classes written by Microsoft. It provides methods for importing and playing content, a basic program flow (detailed below), portability, and has a good online community of homebrew game developers and hobbyists.

Layout

The code is divided into three categories: the engine code, utility code, and the game code.

The engine code is a self-contained XNA project, AC_GraphicsEngine. This code encompasses all the basic engine fundamentals. It includes lighting support, sprite and model entity support, sound management, game management, and game screens for use with basic applications. For more information, please see the tAC_Engine page.

The utility code is another self-contained XNA project called Util. This project defines input handlers, a logger for logging events for experimental data, and event-related information. For further details, please see the Util page.

The game code is stored in individual game projects. These individual game projects each represent either the main game (the Colony Simulator) or one of the several mini-games. The Content folders of each of these contain any and all content (non-code files such as graphics and sounds) used by the games. These are usually divided further into subsets: Fonts, Textures, Models, Shaders, and Audio. A sample breakdown of a game project and its related hierarchy can be seen on the Sample Game page.

Program Flow

An XNA game has 2 main cycles, Draw and Update. Both are called up to 60 times per second (usually). If the CPU load is high, XNA will automatically skip Draw cycles in an attempt to keep up with the Update cycles.

Below is the intended program flow for the game.

  • The entry point for the game is Program.Main() (located in ColonySimulator\Program.cs)
    • Main instantiates all the major components used in this game.
    • The game mode is set to the startup sequence
  • mainGame.Run() is called
    • This calls several initialization functions.
    • The Update and Draw cycles start.
  • Games are held in a stack. When a minigame starts, it is pushed on top of the Colony Sim, which is suspended until the minigame finishes.

Object Interactions

  • Each game is responsible for running and drawing itself (that is, a game must implement Update() and Draw())
    • This responsibility can be delegated to helper classes
  • Games should be independent
    • Mini-games can give the main game resources, but should do so only indirectly.
    • With the exception of resources, any one game should not have any impact on any other game.
  • Every game object should derive from Entity
  • Except for certain circumstances, ALL major objects or classes used in a game should derive from some class in the tAC_Engine or Util namespaces.