Game Development Reference
In-Depth Information
Inheritance
Inheritance is the idea that a more specialized subclass can be created from another object by
extending the first object, and only defining new and altered properties and methods. For
example, creating a basic Screen class might work most of the time (e.g., Title Screen or Instructions
Screen). However, you might need some different methods and properties to support a Between
Levels screen. We use inheritance in the game framework to effectively reuse objects and
simplify game development.
You will see that by using inheritance we will significantly reduce the amount of cut-and-paste
code that needs to be created when you start a new game project. We have found (on our own
projects) that using inheritance has reduced our development time for new projects by 10-30
percent depending on the scope of the work. That means that not only is inheritance a good idea,
it will actually save you money if it is used effectively.
Using object-oriented design to make games
Using OO design with game development involves breaking your game idea down to component
parts and defining how those parts interact. For a game, you might sit down for a short time and
consider the objects you will need when developing.
Let's pretend we are making a space rocks style space shooter. For that type of game, you might
think about the following parts:
Player ship
Player shots
Asteroids (3 sizes)
UFO (2 sizes)
UFO shots
Scoreboard
In a very basic sense, you have just created your object model. It's not code, but you could
quickly mock up these objects to organize your thoughts. However, you can do more to help
design your game before you write any code. Objects in objected-oriented methodology contain
both properties (variables) and methods (functions). You can organize your design further by
thinking of variables and methods that your objects might contain.
The player ship might contain
Properties
Speed
Angle
Rotation
Functions
turn()
thrust()
fire()
Search WWH ::




Custom Search