2
0

Game.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. class Game
  15. {
  16. public:
  17. Game();
  18. bool Initialize();
  19. void RunLoop();
  20. void Shutdown();
  21. void AddActor(class Actor* actor);
  22. void RemoveActor(class Actor* actor);
  23. void AddSprite(class SpriteComponent* sprite);
  24. void RemoveSprite(class SpriteComponent* sprite);
  25. SDL_Texture* GetTexture(const std::string& fileName);
  26. class Grid* GetGrid() { return mGrid; }
  27. std::vector<class Enemy*>& GetEnemies() { return mEnemies; }
  28. class Enemy* GetNearestEnemy(const Vector2& pos);
  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. std::vector<class Enemy*> mEnemies;
  51. class Grid* mGrid;
  52. float mNextEnemy;
  53. };