Game Development Reference
In-Depth Information
1.
It renders it's graphics.
2.
It handles it's movement trajectories and other physics.
3.
It treats Explosion as part of it's own lifecycle.
4.
Draws graphics on screen.
5.
Handles sound effects.
Even the relatively small Explosion class is too monolithic:
1.
It loads it's graphics.
2.
It handles rendering, animation and frame skipping
3.
It loads and plays it's sound effects.
Decoupling Using Component Pattern
Best design separates concerns in code so that everything has it's own place, and every
class handles only one thing. Let's try splitting up Tank class into components that handle
specific domains:
Decoupled Tank
We will introduce GameObject class will contain shared functionality for all game
objects ( Tank , Bullet , Explosion ), each of them would have it's own set of
components. Every component will have it's parent object, so it will be able to interact with
it, change it's attributes, or possibly invoke other components if it comes to that.
Search WWH ::




Custom Search