Game.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. // Game-specific (add/remove asteroid)
  26. void AddAsteroid(class Asteroid* ast);
  27. void RemoveAsteroid(class Asteroid* ast);
  28. std::vector<class Asteroid*>& GetAsteroids() { return mAsteroids; }
  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. class Ship* mShip; // Player's ship
  51. std::vector<class Asteroid*> mAsteroids;
  52. };