Game Development Reference
In-Depth Information
passes control to the Input Action, which connects the logic to the button. The Input
Action is a component connected to the player entity, so that when it fires, the action
communicates with the Bullet Manager to create a new bullet entity. Inside this entity
is a Bullet Controller, which acts as the brains for the bullet. The bullet manager can
then loop through the Bullet Controllers during an update, which allows them to move
the bullet forward. Once the collision system detects a collision between the bullet
collision shapes, the controller can detect this state and destroy the bullet entity. The
enemy has its own controller, a collision shape, and a health component. The Bullet
Controller determines the enemy entity from the collision and notifies its Health Com-
ponent that it should take damage using the appropriate value. The Health Compon-
ent then determines if the enemy is still alive. The Enemy Controller can then detect
the health and destroy the enemy. Alternatively the Health Component can check its
state and destroy the enemy itself if desired.
There are many different ways you can assign control and responsibility, so that you
have the flexibility to choose what is best for your game. If only the enemies have
health, you could add that as a field to the enemy controller and remove the health
component. However if you keep the health controller, it's quite easy to add in sup-
port for enemies that shoot the player, by just adding in code to tell the enemies to
shoot, and creating a health object for the player.
Putting it all together
Let's put together some classes that will support the mechanics in our game, and
then build on these later in the chapter to complete them. But before we write any
code, be sure to clean out all of the test code we wrote into Game.h and Game.cpp .
We'll be taking those visuals and turning them into a set of objects that should make
designing the logic easier.
Note
To make things simpler, and not jump between native C++ and C++/CX all the
time, we will change the texture from a reference class to a native class.
To begin, we need two classes: one which we will call Ship , and the other Player .
Search WWH ::




Custom Search