![]() |
OO Game Programming tutorial - Part 5 |
The other objects
The class diagram:
* We’ll assume the width runs along X-axis and height along the Y-axis. These are just rectangles that we can position at the top and bottom of the board. We will use these to bounce the ball off when we do some collision detection. We add lines to the Game_Init() function that position the walls and as with the other objects we need to draw we add a Draw() command to the rendering section. Here is the code:-
The paddles Class diagram:
:Paddles aren’t much different from wall, except we will give them a movement speed and a player score. We also initialise their positions in Game_Init(). The Reset() function will be called when a new game starts, it will just reset the player's score back to zero. The goal Since the wall and goal are so similar, we can use a wall object to represent the goal. We don't need to see the goal so we'll just leave out the command for drawing it. When checking we have positioned the goal in the right spot we can just do a call to the Draw() function and see it on screen. Note: The objects share a lot of attributes which we could use to make an abstract base class to derive them from, but since this is a beginners project and there’s not too many objects we shall leave it be. If you don’t know what I mean, don’t worry it’s just a more advanced OO technique that can be learnt later.
Get the complete project here
|