Krig Game Engine
Engine.h
Go to the documentation of this file.
1 
7 #ifndef _ENGINE_H_
8 #define _ENGINE_H_
9 
10 #include <GL/glut.h>
11 #include <string>
12 
13 #include "SoundFX.h"
14 #include "gametimer.h"
15 #include "KeyState.h"
16 #include "GameLevel.h"
17 #include "TextGameObject.h"
18 
19 extern "C" {
20  #include "lua5.1/lua.h"
21  #include "lua5.1/lualib.h"
22  #include "lua5.1/lauxlib.h"
23 }
24 
25 class Engine {
26  public:
27  Engine();
28  ~Engine();
29 
30  void gameCycle();
31  void prepare();
32  void initGL();
33 
34  void processKeyUp(const int&);
35  void processKeyDown(const int&);
36  void processCommands();
37  void processNormalKeyUp(const unsigned char&);
38  void processNormalKeyDown(const unsigned char&);
39 
40  KeyState* getKeyState() { return &keyState_; }
41  KeyState* getSpecialKeyState() { return &specialKeyState_; }
42 
43  void processMouseMove(const int&, const int&);
44  float getMouseX() { return mouseX_; }
45  float getMouseY() { return mouseY_; }
46 
47  void loadLevel(const char*);
48  void loadLevelFromBuffer(const char*);
49 
50  bool loadGame(const std::string&);
51  bool loadIntroCredits();
52 
53  void updateGame(const float&);
54  void unloadGame();
55  void unload();
56 
57  void shutdown();
58  void pause();
59 
60  float getFps() { return fps_; }
61 
62  void loadModels();
63  void loadTextures();
64 
65  void renderText(const char* s, const float &x, const float &y) {
66  glRasterPos2f (x, y);
67  TextGameObject::render_string(GLUT_BITMAP_HELVETICA_18, s);
68  }
69 
70  SoundFX* getSoundFxClass() { return &soundFx_; }
71  bool getIsRunning() { return isRunning_; }
72 
73  GameLevel* getCurrentLevel() { return currentLevel_; }
74 
75  void swapLevel() {
76  GameLevel *temp = currentLevel_;
77  currentLevel_ = storedLevel_;
78  storedLevel_ = temp;
79  }
80 
81  bool loadPng(const char*, unsigned char**, unsigned int*, unsigned int*, unsigned int*);
82 
83 #if EDIT
84  void getTerrainInfo(int &x, int &z, float &height, int &type, float &red, float &green, float &blue);
85  void updateTerrain(int &x, int &z, float &height, int &type, float &red, float &green, float &blue);
86 
87  void updateColor(float &red, float &green, float &blue);
88 
89  void setMouseX(float mouseX) { mouseX_ = mouseX; }
90  void setMouseY(float mouseY) { mouseY_ = mouseY; }
91 #endif
92 
93  private:
94  GameLevel *currentLevel_, *storedLevel_;
95  Camera *mainCamera_, *c1_, *c2_, *c3_, *c4_;
96  KeyState keyState_, specialKeyState_;
97  SoundFX soundFx_;
98 
99  GameTimer timer_; // game's timer
100  float timeElapsed_; // time elapsed in game
101  float fps_;
102 
103  lua_State* luaState_;
104 
105  bool isRunning_, isIntroRunning_, isPaused_;
106 
107  float mouseX_, mouseY_;
108 
109  // Used through game for cel shading
110  GLuint shaderTexture_[1];
111  unsigned int lists_; // lists used for rendering
112 
113  void prepLevelLoad();
114 
115 #if EDIT
116  // Mouse control values
117  float lastX, lastY;
118 
119  // Terrain editing values
120  int last_x, last_z, last_type;
121  float last_height;
122  float last_red, last_green, last_blue;
123  bool paint, paintColor;
124 #endif
125 };
126 
127 #endif
Definition: SoundFX.h:17
Representation of a game level or scene.
Definition: Engine.h:25
Load and play sounds.
Definition: gametimer.h:16
Definition: GameLevel.h:30
Definition: KeyState.h:16
Lookup state of all keyboard keys.
Definition: Camera.h:13