How to Make a Mini-Game

From TACWiki
Revision as of 19:57, 8 January 2009 by Belmonte (Talk | contribs)

Jump to: navigation, search

The purpose of this tutorial is to help a new developer get started with their own mini-game addition to the project.

It's expected that reader will have some knowledge of programming, preferably C# and XNA.

Your Project

It's not necessary for your mini-game to be integrated into the main code base. To get started, create a new XNA Project using either the Windows Game or Windows Game Library template. Next, your project needs to reference the main code. Right-click on References in your project and select 'Add Reference', Navigate to the main code base, either via SVN or from an installed copy, and select Util.dll. Util.dll is a shared library that contains many common elements between the existing mini-games.

Your Game

Next, we need to modify the XNA code to work with the mini-game system.

Game.cs

First, open the Game.cs file that came with the XNA template. Instead of being a subclass of Game, change it to be a subclass of GameScreen. GameScreen is a DrawableGameComponent that contains common functionality for mini-games to use, and is run by the main system for your game to be played.

Constructor

Because your mini-game object may be constructed at any time, your constructor should contain as little as possible, and need not exist.

Initialize

The Initialize method should contain all of your mini-game's start-up logic. In particular, you should do the following, if needed:

  • Call GetLogger(); and initialize your logger object.
  • Call GetInputHandler(); and initialize your input handler object.
  • Bind the inputs your mini-game needs in your InputHandler. (see information on event codes)

(example)

Update

The Update method should contain all of your mini-game's runtime game logic. In particular, you must handle input, if set up in your initialization.

(example input handling loop)

Game Info

In order for the main system to find and display your mini-game correctly, you need to provide some additional information. For this purpose, you will need to create a new class in your project. The class will be a subclass of MiniGameInfo, which is also from Util.dll. MiniGameInfo specifies a number of abstract methods, which must be overridden.

  • GetDisplayName() - Return a string that will be used by the main system for display of your mini-game in menus and the like.
  • GetGameScreen() - Return a constructed instance of your main Game, in this case, a new Game() from the code we edited above.

Playing

For the main system to find your mini-game, the built exe or dll and any required content must be placed in a subdirectory of the main project. It's recommended to follow the pattern of /minigames/"minigamename"/ currently used, to prevent conflicts. That's all.