Acting on states

Now that we have our states defined, let's now make it so that we can actually do something in our code based on what state our object is in. For this first example, I'm going to update the ChasePlayerComponent class that already exists in the EngineTest project.

From the Solution Explorer tab on the right-hand side, open up the SpaceShooter/Components/ChasePlayerComp folder and access the ChasePlayerComponent.h file. From there, replace the class with the following changes in bold:

enum State{  Idle,  Follow,  Death};  //!< Simple AI to Chase the Player class ChasePlayerComponent : public M5Component { public:   ChasePlayerComponent(void);   virtual void Update(float dt);   virtual void FromFile(M5IniFile& iniFile);  virtual ...

Get Game Development Patterns and Best Practices now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.