Game.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. // ----------------------------------------------------------------
  2. // From Game Programming in C++ by Sanjay Madhav
  3. // Copyright (C) 2017 Sanjay Madhav. All rights reserved.
  4. //
  5. // Released under the BSD License
  6. // See LICENSE in root directory for full details.
  7. // ----------------------------------------------------------------
  8. #pragma once
  9. #include "SDL/SDL.h"
  10. #include <unordered_map>
  11. #include <string>
  12. #include <vector>
  13. #include "Math.h"
  14. #include "Board.h"
  15. class Game
  16. {
  17. public:
  18. Game();
  19. bool Initialize();
  20. void RunLoop();
  21. void Shutdown();
  22. void AddActor(class Actor* actor);
  23. void RemoveActor(class Actor* actor);
  24. void AddSprite(class SpriteComponent* sprite);
  25. void RemoveSprite(class SpriteComponent* sprite);
  26. SDL_Texture* GetTexture(const std::string& fileName);
  27. // Helper to draw a texture without sprite components
  28. void DrawTexture(SDL_Texture* texture, const Vector2& pos, const Vector2& size);
  29. private:
  30. void ProcessInput();
  31. void UpdateGame();
  32. void GenerateOutput();
  33. void LoadData();
  34. void UnloadData();
  35. // Map of textures loaded
  36. std::unordered_map<std::string, SDL_Texture*> mTextures;
  37. // All the actors in the game
  38. std::vector<class Actor*> mActors;
  39. // Any pending actors
  40. std::vector<class Actor*> mPendingActors;
  41. // All the sprite components drawn
  42. std::vector<class SpriteComponent*> mSprites;
  43. SDL_Window* mWindow;
  44. SDL_Renderer* mRenderer;
  45. Uint32 mTicksCount;
  46. bool mIsRunning;
  47. // Track if we're updating actors right now
  48. bool mUpdatingActors;
  49. // Game-specific
  50. BoardState mBoardState;
  51. };