logo.jpg (7978 bytes)

OO Game Programming tutorial - Part 3



Where do we start?

 

With most of my projects I like to get something happening on the screen so I can test things as I go. For this project I think a good place to start would be to get the board drawn on the screen. Just a simple rectangle will do for now. We can modify and add to it as we go.

We’ll create a new class CBoard to do this. This class will need to have attributes and functions added to operate in our game world.

Our class diagram for the board will be like this:-

CBoard
width
height
color[3]
Draw()

 

Pretty simple. The color array is just an RGB (red, green, blue) set for the board. We may add some attributes later, such as a texture for the board.

We’ll set the width/height and color attributes in the class constructor.

The class definition and implementation will look like this

CBoard.h
CBoard.cpp

We need to include the class definition in main.cpp, and for such a simple game we will declare the objects as globals and refer to them in our main.cpp functions.

Adding a couple of lines to the Game_Main() function to call the board class' Draw() function and we get something happening.

Fancy stuff!

Get the complete project here

 

Next page

Back to main page