An interacting world
A lot of game logic has been implemented in the different entities, now we look at functionality that is defined in the World
class. You have already seen the collision in the last section.
Cleaning everything up
During the game, entities are destroyed in battle, and have to be removed from the scene graph. We do not remove them instantly. Once in a frame, we iterate through the scene graph, check which nodes have been destroyed, and detach them from their parents. To find out whether a node has been destroyed, we write the virtual function SceneNode::isDestroyed()
. By default, it returns false. A derived entity may specify a condition under which it returns true. Usually, this will be the case when the hitpoints are zero or less (that is, the entity is destroyed).
bool Entity::isDestroyed() const { return mHitpoints <= 0; }
In addition, we add a virtual function that checks if a scene node should be removed from the scene graph. By default, this is true as soon as...