#pragma once #include #include #include "../engine/resources.h" #include "../engine/skybox.h" #include "../engine/stateManager.h" /** * @struct ShaysWorldStateSounds * @brief Wraps all the sounds used by shays world in a struct for easier * access. * * @author Chase Percy * */ struct ShaysWorldStateSounds { // Treat as a 2D sound due to Shays worlds scale messing with 3D sound. Sound walk{"walk.ogg", false, 50.f}; Sound ambience{"ambience.ogg", true, 80}; Sound transition{"combat.ogg", true, 80}; float soundDelta{ 1}; /// Time delta so sounds stepping don't play too often. }; /** * @class ShaysWorldState * @brief A struct to wrap the toggling functions in one place to keep it clean. * * @author Chase Percy * */ struct ShaysWorldStateToggles { bool endScreen{false}; bool displayLights{true}; }; /** * @class ShaysWorldTransition * @brief A struct to wrap the transition variables. * * @author Chase Percy * */ struct ShaysWorldTransition { bool lighting{false}; /// to enable or disable lighting bool transitioning{false}; /// Has the scene started the transition std::random_device rd{}; /// obtain a random number from hardware std::mt19937 gen{rd()}; /// seed the generator std::uniform_int_distribution<> distribution{3, 40}; /// define the range int flicker{0}; /// The frames until the next light flicker float wallToCameraOffset{1200}; /// The offset between the camera and wall. float lastX{0}; /// The lastX position of the camera. }; class ShaysWorldState { public: /** * Initialises the ShaysWorldState and sets all its functions to the * function pointers in a state and returns that state. * @param engineResources the resources to be used by the scene. * @return A state shared_ptr with all the associated functions. */ static std::shared_ptr init(Resources& engineResources); /** * Destroys all shaysWorldState data when called. */ static void destroy(); /** * Pauses ShaysWorldState as it currently is and deactivates lighting, * sound, and enables culling when false is the parameter. The opposite when * true is received as a parameter. * @param option true if scene should pause, false if resume. */ static void pause(bool option); /** * Handles all SDL events and process input. * @param event the current event state to read updates from. */ static void handleEvents(SDL_Event& event); /** * Updates all objects and camera within ShaysWorldState. * @param deltaTime the delta time to be used for smooth animations, camera * updates, etc. */ static void update(float deltaTime); /** * The draw function for ShaysWorldState. Draws all shays world data from * shays world's display function then our objects are drawn after. */ static void draw(); /** * The function to signal to the state manager that shaysWorldState is ready * to shutdown. * @return true if ready to shutdown, else false. */ static bool shutdown(); /** * Returns the next state that will start after shaysWorldState. * @return nullptr if no new state, else a shared_ptr to the new state. */ static std::shared_ptr newState(); /** * Sets the state camera and updates it according the shays worlds own * functions that were exposed. Each camera updates the other, but ours is * used to display. */ static void setCamera(); /** * Updates the state camera and updates it according the shays worlds own * functions that were exposed. Each camera updates the other, but ours is * used to display. * @param deltaTime The delta time to use when calling the camera.update() * method. */ static void updateCamera(float deltaTime); /** * Creates the sky bridge above the ESL for assignment one and all its * collision. */ static void createSkyBridge(); /** * Creates the tavern and all of its collision for assignment one */ static void createTav(); /** * Creates the light objects to replace the original lighting cylinders from * shays world. */ static void createLightObjects(); /** * Checks to see if the mouse is clicking within the bounds of the exit * screen image and sets m_stop to true if it is. */ static void checkExitClick(); /** * Checks if the player has entered the level transition area to be * transported to the next state (The Archanist). */ static void checkLevelTransition(); /* * Calls all code related to the transition event out of shays world. */ static void transition(); /** * Called when the player leaves shays world or backs out of the transition. */ static void resetTransition(); private: static std::shared_ptr m_thisState; /// The pointer to this state. static Camera_ temp; /// A temp camera used for shays world collision detection. static ShaysWorldStateSounds m_sounds; /// The sounds that shays world state will play. static ShaysWorldStateToggles m_toggles; /// All the bool toggles for the state. static ShaysWorldTransition m_transition; /// The transition data. static unsigned int newExitTexture; /// index of the new Exit picture };