Game.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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 <unordered_map>
  10. #include <string>
  11. #include <vector>
  12. #include "Math.h"
  13. #include "SoundEvent.h"
  14. #include <SDL/SDL_types.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. class Renderer* GetRenderer() { return mRenderer; }
  25. class AudioSystem* GetAudioSystem() { return mAudioSystem; }
  26. class PhysWorld* GetPhysWorld() { return mPhysWorld; }
  27. class HUD* GetHUD() { return mHUD; }
  28. // Manage UI stack
  29. const std::vector<class UIScreen*>& GetUIStack() { return mUIStack; }
  30. void PushUI(class UIScreen* screen);
  31. class FPSActor* GetPlayer() { return mFPSActor; }
  32. enum GameState
  33. {
  34. EGameplay,
  35. EPaused,
  36. EQuit
  37. };
  38. GameState GetState() const { return mGameState; }
  39. void SetState(GameState state) { mGameState = state; }
  40. void LoadFont(const std::string& fileName);
  41. class Font* GetFont(const std::string& fileName);
  42. void LoadText(const std::string& fileName);
  43. const std::string& GetText(const std::string& key);
  44. // Game-specific
  45. void AddPlane(class PlaneActor* plane);
  46. void RemovePlane(class PlaneActor* plane);
  47. std::vector<class PlaneActor*>& GetPlanes() { return mPlanes; }
  48. private:
  49. void ProcessInput();
  50. void HandleKeyPress(int key);
  51. void UpdateGame();
  52. void GenerateOutput();
  53. void LoadData();
  54. void UnloadData();
  55. // All the actors in the game
  56. std::vector<class Actor*> mActors;
  57. std::vector<class UIScreen*> mUIStack;
  58. std::unordered_map<std::string, class Font*> mFonts;
  59. // Map for text localization
  60. std::unordered_map<std::string, std::string> mText;
  61. // Any pending actors
  62. std::vector<class Actor*> mPendingActors;
  63. class Renderer* mRenderer;
  64. class AudioSystem* mAudioSystem;
  65. class PhysWorld* mPhysWorld;
  66. class HUD* mHUD;
  67. Uint32 mTicksCount;
  68. GameState mGameState;
  69. // Track if we're updating actors right now
  70. bool mUpdatingActors;
  71. // Game-specific code
  72. std::vector<class PlaneActor*> mPlanes;
  73. class FPSActor* mFPSActor;
  74. class SpriteComponent* mCrosshair;
  75. SoundEvent mMusicEvent;
  76. };