Game.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. class Font* GetFont(const std::string& fileName);
  41. void LoadText(const std::string& fileName);
  42. const std::string& GetText(const std::string& key);
  43. // Game-specific
  44. void AddPlane(class PlaneActor* plane);
  45. void RemovePlane(class PlaneActor* plane);
  46. std::vector<class PlaneActor*>& GetPlanes() { return mPlanes; }
  47. private:
  48. void ProcessInput();
  49. void HandleKeyPress(int key);
  50. void UpdateGame();
  51. void GenerateOutput();
  52. void LoadData();
  53. void UnloadData();
  54. // All the actors in the game
  55. std::vector<class Actor*> mActors;
  56. std::vector<class UIScreen*> mUIStack;
  57. std::unordered_map<std::string, class Font*> mFonts;
  58. // Map for text localization
  59. std::unordered_map<std::string, std::string> mText;
  60. // Any pending actors
  61. std::vector<class Actor*> mPendingActors;
  62. class Renderer* mRenderer;
  63. class AudioSystem* mAudioSystem;
  64. class PhysWorld* mPhysWorld;
  65. class HUD* mHUD;
  66. Uint32 mTicksCount;
  67. GameState mGameState;
  68. // Track if we're updating actors right now
  69. bool mUpdatingActors;
  70. // Game-specific code
  71. std::vector<class PlaneActor*> mPlanes;
  72. class FPSActor* mFPSActor;
  73. class SpriteComponent* mCrosshair;
  74. SoundEvent mMusicEvent;
  75. };