Game Development Reference
In-Depth Information
Chapter 7
BasicGameObjects
7.1 Introduction
In this chapter, we are going to start organizing the source code of the Painter game.
This is necessary because the source code of a game contains many lines of code.
If we want to understand what such a complicated program is doing, we need to
organize it.
7.2 Structuring the Game World
7.2.1 The Basics
In the Painter2 version of the game, we already had quite a few member variables:
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;
Texture2D background, cannonBarrel;
Vector2 barrelPosition, barrelOrigin;
float angle;
Texture2D colorRed, colorGreen, colorBlue;
Texture2D currentColor;
Vector2 colorOrigin;
MouseState currentMouseState, previousMouseState;
KeyboardState currentKeyboardState, previousKeyboardState;
Some of these member variables are used for running the game in general (such as
spriteBatch and graphics ), others are for representing the colored cannon, and there are
some variables for handling player input. You can imagine that this list will become
even longer when we add the flying ball and the falling paint cans to this game.
And then Painter is just a basic game! Once we start building more complicated
games, having a huge list of member variables will result in code that is impossible
 
Search WWH ::




Custom Search