Game Development Reference
In-Depth Information
game. You can imagine adding a lot of useful things to this class such as han-
dling dragging and dropping, selecting, handling special key combinations such as
Shift-F7, and even managing other input devices such as a multi-touch screen or
a gamepad. However, for the Painter game, the current version is sufficient. In the
remaining chapters of this topic, we will keep using and improving this class.
If you look at the file containing the class definition, you will see that the
InputHelper class does not contain a constructor. So what happens when we create
the object as follows?
inputHelper = new InputHelper();
The compiler does not generate an error complaining that it cannot construct the ob-
ject because there is no constructor. The reason is that there actually is a constructor:
the default constructor . Whenever you define a class and you do not provide a con-
structor, the compiler adds a default, empty constructor:
public InputHelper()
{
}
The default constructor is an empty constructor method that does not take any pa-
rameters and that does not contain any instructions.
7.5.2 The GameWorld Class
The goal of the GameWorld class is to manage all the game objects. Managing a game
object means: creating it, updating it, and drawing it. Currently, the game world is
quite basic. It only consists of a background sprite, and a cannon.
Next to the game objects, what else could we say is part of the game world?
One part of the game world is its border. In the case of this game, the border is
determined by the width and height of the playing screen. The background image
is also part of the game world. Therefore, we will declare in any case the following
member variables:
Texture2D background;
Cannon cannon;
Now we need to manage the game objects that are inside this game world. The first
step is creating the objects. Like in any class, this is done in the constructor method.
One of these game objects is the cannon. In order to create a Cannon instance, we
need to pass along the content manager to the constructor. But since we are in the
GameWorld constructor, and not in the Painter class, we need to get access to the
content manager by using a parameter, just like we did with the Cannon class. We,
therefore, pass the content manager as a parameter to the GameWorld constructor.
Search WWH ::




Custom Search