With all the raw elements of the game’s DirectDraw components in place, we now need to update the main() function so that the GameLoop, Initialise, RenderSurface and GameOver routines are called at the appropriate times. The default C# main function looks like this:
static void Main()
{
Application.Run(new Form1());
}
Assuming our form is renamed to frmGame, we want the main function to look like this instead:
static void Main()
{
frmGame frmGameWindow=new frmGame();
Application.Exit();
}
As for the form’s constructor, it should initialise COM, show the form, create the DirectDraw device, run the initialisation routine and then launch the game loop. We have also decided to run this game in full screen mode, which is achieved by passing the relevant flags to the device as shown here.
public frmGame()
{
InitializeComponent();
this.Show();
ddDevice=new Device();
ddDevice.SetCooperativeLevel(this,CooperativeLevelFlags.FullscreenExclusive);
Initialise();
GameLoop();
}
The scene is now set for our game, which will now compile and show a black background in full screen mode when executed. Not much to look at yet, but the groundwork is almost done!