ComputerGraphik TU WIEN
gameLogic.hpp
Go to the documentation of this file.
1 #ifndef GAMELOGIC_HPP
2 #define GAMELOGIC_HPP
3 
4 #include <vector>
5 #include <memory>
6 
7 #include "sceneObject.hpp"
8 
9 class Tank;
10 class Scene;
11 class Model;
12 class Shader;
13 class Bullet;
14 class Texture;
15 class SceneObject;
16 
18 
75 class GameLogic : public SceneObject
76 {
77 public:
79  class Terrain : public SceneObject{
80  public:
81  Terrain(size_t dimX,
82  size_t dimY,
83  float cellSize,
84  const std::vector<float>& heights,
85  const std::string& name,
86  Scene* scene = 0, Model* model = 0, Shader* shader = 0);
87  virtual ~Terrain() {}
88 
89  float getHeight(float x, float y);
90 
91  private:
92  size_t dimX;
93  size_t dimY;
94  float cellSize;
95  std::vector<float> heights;
96 
97  float lerp(float a, float b, float t);
98  };
99 
100 public:
102  ~GameLogic();
103 
104  void update(double deltaT);
105  void addTank(std::shared_ptr<SceneObject> tank);
106 
107  bool isGameFinished() const { return gameFinished; }
108  size_t getWinner() const { return activeTank; }
109  std::shared_ptr<Terrain> getTerrain() const { return terrain; }
110 
111 private:
112  class Bullet;
113 
114  double turnTime;
115  size_t activeTank;
117  std::unique_ptr<Model> waterModel;
118  std::unique_ptr<Model> terrainModel;
119  std::unique_ptr<Texture> waterTexture;
120  std::shared_ptr<Bullet> bullet;
121  std::shared_ptr<Terrain> water;
122  std::shared_ptr<Terrain> terrain;
123  std::vector<std::shared_ptr<Tank> > tanks;
124 };
125 
126 #endif //GAMELOGIC_HPP
std::shared_ptr< Bullet > bullet
Definition: gameLogic.hpp:120
float lerp(float a, float b, float t)
Definition: gameLogic.cpp:115
virtual ~Terrain()
Definition: gameLogic.hpp:87
Encapsulates a graphical object model in the GPU.
Definition: model.hpp:14
void update(double deltaT)
Definition: gameLogic.cpp:166
Model * model
Definition: sceneObject.hpp:69
void addTank(std::shared_ptr< SceneObject > tank)
Definition: gameLogic.cpp:158
size_t activeTank
Definition: gameLogic.hpp:115
bool isGameFinished() const
Definition: gameLogic.hpp:107
std::unique_ptr< Model > terrainModel
Definition: gameLogic.hpp:118
~GameLogic()
Definition: gameLogic.cpp:153
size_t dimY
Definition: gameLogic.hpp:93
Implements terrain height query.
Definition: gameLogic.hpp:79
std::shared_ptr< Terrain > getTerrain() const
Definition: gameLogic.hpp:109
size_t getWinner() const
Definition: gameLogic.hpp:108
Encapsulates the Rendering Engine, holds a complete scene and it's assets.
Definition: scene.hpp:71
Scene * scene
Definition: sceneObject.hpp:68
GameLogic(Scene *scene)
Definition: gameLogic.cpp:120
bool gameFinished
Definition: gameLogic.hpp:116
Terrain(size_t dimX, size_t dimY, float cellSize, const std::vector< float > &heights, const std::string &name, Scene *scene=0, Model *model=0, Shader *shader=0)
Definition: gameLogic.cpp:52
Implements the bullet movement on CPU.
Definition: gameLogic.cpp:14
std::vector< std::shared_ptr< Tank > > tanks
Definition: gameLogic.hpp:123
double turnTime
Definition: gameLogic.hpp:112
Encapsulates a texture in the GPU.
Definition: texture.hpp:10
std::unique_ptr< Texture > waterTexture
Definition: gameLogic.hpp:119
float cellSize
Definition: gameLogic.hpp:94
std::string name
Definition: sceneObject.hpp:73
Encapsulates a shader program.
Definition: shader.hpp:9
std::shared_ptr< Terrain > terrain
Definition: gameLogic.hpp:122
std::vector< float > heights
Definition: gameLogic.hpp:95
std::shared_ptr< Terrain > water
Definition: gameLogic.hpp:121
The base class of the objects which are rendered.
Definition: sceneObject.hpp:30
Implements the tank functionalities.
Definition: tank.hpp:15
size_t dimX
Definition: gameLogic.hpp:92
float getHeight(float x, float y)
Definition: gameLogic.cpp:69
Shader * shader
Definition: sceneObject.hpp:70
std::unique_ptr< Model > waterModel
Definition: gameLogic.hpp:117
Implements the game logic of SteelWorms.
Definition: gameLogic.hpp:75