| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- // ----------------------------------------------------------------
- // From Game Programming in C++ by Sanjay Madhav
- // Copyright (C) 2017 Sanjay Madhav. All rights reserved.
- //
- // Released under the BSD License
- // See LICENSE in root directory for full details.
- // ----------------------------------------------------------------
- #pragma once
- #include "SDL/SDL.h"
- #include <unordered_map>
- #include <string>
- #include <vector>
- #include "Math.h"
- class Game
- {
- public:
- Game();
- bool Initialize();
- void RunLoop();
- void Shutdown();
- void AddActor(class Actor* actor);
- void RemoveActor(class Actor* actor);
- void AddSprite(class SpriteComponent* sprite);
- void RemoveSprite(class SpriteComponent* sprite);
-
- class Texture* GetTexture(const std::string& fileName);
-
- // Game-specific (add/remove asteroid)
- void AddAsteroid(class Asteroid* ast);
- void RemoveAsteroid(class Asteroid* ast);
- std::vector<class Asteroid*>& GetAsteroids() { return mAsteroids; }
- private:
- void ProcessInput();
- void UpdateGame();
- void GenerateOutput();
- bool LoadShaders();
- void CreateSpriteVerts();
- void LoadData();
- void UnloadData();
-
- // Map of textures loaded
- std::unordered_map<std::string, class Texture*> mTextures;
- // All the actors in the game
- std::vector<class Actor*> mActors;
- // Any pending actors
- std::vector<class Actor*> mPendingActors;
- // All the sprite components drawn
- std::vector<class SpriteComponent*> mSprites;
- // Sprite shader
- class Shader* mSpriteShader;
- // Sprite vertex array
- class VertexArray* mSpriteVerts;
- SDL_Window* mWindow;
- SDL_GLContext mContext;
- Uint32 mTicksCount;
- bool mIsRunning;
- // Track if we're updating actors right now
- bool mUpdatingActors;
- // Game-specific
- class Ship* mShip;
- std::vector<class Asteroid*> mAsteroids;
- };
|