A sample game state
Just to demonstrate the full use of our system, let's get something bouncing on the screen that will demonstrate switching between the menu, game, and paused states. For testing purposes, a bouncing mushroom from previous chapters will more than suffice. We also need methods for switching to the menu state, as well as the paused state. Knowing that, let's bang out the header for the game-play state:
class State_Game : public BaseState{ public: ... void MainMenu(EventDetails* l_details); void Pause(EventDetails* l_details); private: sf::Texture m_texture; sf::Sprite m_sprite; sf::Vector2f m_increment; };
We begin, like many other times, with resource allocation and set up of data members in the OnCreate
method:
void State_Game::OnCreate(){ m_texture.loadFromFile("Mushroom.png"); m_sprite.setTexture(m_texture); m_sprite.setPosition(0,0); m_increment = sf::Vector2f(400.0f,400.0f); EventManager* evMgr = m_stateMgr->GetContext(...