Game.h 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. class Game
  14. {
  15. public:
  16. Game();
  17. bool Initialize();
  18. void RunLoop();
  19. void Shutdown();
  20. void AddActor(class Actor* actor);
  21. void RemoveActor(class Actor* actor);
  22. void AddSprite(class SpriteComponent* sprite);
  23. void RemoveSprite(class SpriteComponent* sprite);
  24. SDL_Texture* GetTexture(const std::string& fileName);
  25. private:
  26. void ProcessInput();
  27. void UpdateGame();
  28. void GenerateOutput();
  29. void LoadData();
  30. void UnloadData();
  31. // Map of textures loaded
  32. std::unordered_map<std::string, SDL_Texture*> mTextures;
  33. // All the actors in the game
  34. std::vector<class Actor*> mActors;
  35. // Any pending actors
  36. std::vector<class Actor*> mPendingActors;
  37. // All the sprite components drawn
  38. std::vector<class SpriteComponent*> mSprites;
  39. SDL_Window* mWindow;
  40. SDL_Renderer* mRenderer;
  41. Uint32 mTicksCount;
  42. bool mIsRunning;
  43. // Track if we're updating actors right now
  44. bool mUpdatingActors;
  45. // Game-specific
  46. class Ship* mShip; // Player's ship
  47. };