Game Development Reference
In-Depth Information
Our
Entity
class at the moment is very straightforward; all we want it to do is provide our inherited
classes with an
Update
method. The
Update
method can be important when developing game
software, as your program will likely be
updating
your objects once per frame.
Adding Inheritance to the Player Class
Your
Player
class can now be changed to inherit from
Entity
. The new
Player
class can be seen in
Listing 10-12.
Listing 10-12. Inheriting
Player
from
Entity
class Player
: public Entity
{
private:
std::string m_name;
public:
Player()
{
}
void SetName(const std::string& name)
{
m_name = name;
}
const std::string& GetName() const
{
return m_name;
}
};
You will see what the
Player
class's
Update
method will look like once we have added some rooms
for the player to move through.
Adding Rooms
To be able to have the player move through rooms in the game you will need to create a
Room
class,
and the code for this is shown in Listing 10-13.
Listing 10-13. The
Room
Class
class Room
: public Entity
{
public:
enum class JoiningDirections
{
North = 0,
East,