Tuesday, November 3, 2009

Introducing the arc.game Game class

Here is the first incarnation of the Game class. The idea behind the class is that the user will overload the this() class for init, process() for game loop, and shutdown() for shutdown code, and the Game class will handle the mundane details, such as input processing and window swapping. After creating their own class to extend the Game class and overloading the correct functions, the main loop simplifies to

// main entry
int main()
{
// initialize game
Game g = new MyGame("Arc
Graphics Primitives", Size.d640x480, false);

// loop game
g.loop();

// shutdown() is called by loop() after loop exits
return 0;
}

Here is an example I’ve modified to make use of the game class: http://svn.dsource.org/projects/arclib/trunk/examples/arc/draw.d

Of course, use of this class is optional. It may gain more features in the future, such as setting up game states and integration with the GUI. For now, its very simple.

No comments: