Krig Game Engine
GameLevel.h
Go to the documentation of this file.
1 
7 #ifndef _GAME_LEVEL_H_
8 #define _GAME_LEVEL_H_
9 
10 #include "ObjectList.h"
11 #include "Object.h"
12 #include "ModelGameObject.h"
13 #include "Terrain.h"
14 #include "Camera.h"
15 #include "QuadTree.h"
16 #include "Music.h"
17 
18 extern "C" {
19  #include "lua5.1/lua.h"
20  #include "lua5.1/lualib.h"
21  #include "lua5.1/lauxlib.h"
22 }
23 
24 #define MAX_LEVEL_OBJECTS 1024
25 
26 #define TYPE_GAME_OBJECT 1
27 #define TYPE_GAME_TEXT 2
28 #define TYPE_GAME_SPRITE 3
29 
30 class GameLevel {
31  public:
32  GameLevel(const unsigned int&);
33  ~GameLevel();
34 
35  void updateLevel();
36  void animateLevel();
37  void prepareLevel();
38  void drawLevel();
39 
40  bool loadLevel(const char*);
41  bool loadLevelFromBuffer(const char*);
42  void loadScript(const std::string &);
43 
44  Object* findEnemyOfType(const int&);
45  float findDistance(Object*, Object*);
46 
47  void drawSky();
48  bool checkComplete();
49  void unloadLevel();
50  void removeObjects();
51 
52  void postDraw();
53 
54  void updateTerrain(int &x, int &z, float &height, int &type, float &red, float &green, float &blue);
55  void updateColor(int &x, int &z, float &red, float &green, float &blue);
56 
57  void getTerrainInfo(int &x, int &z, float &height, int &type, float &red, float &green, float &blue);
58  void saveTerrain(const char*);
59  void toggleGrid();
60  void toggleBoundingBoxes();
61  void toggleControlTriangles();
62 
63  void drawObjects();
64  void drawObjectOutlines();
65  void drawShadows(Vector*);
66 
67  void updateObjects(Vector*);
68  void prepareObjects();
69  void animateObjects(const float&);
70 
71  Object* addObject(const std::string&, lua_State*, const unsigned int&);
72 
73  ObjectList* getObjects() { return &objects_; }
74  Terrain* getTerrain() { return((Terrain*)terrain_); }
75  Camera* getCamera() { return((Camera*)camera_); }
76  ModelGameObject* getPlayer() { return((ModelGameObject*)player_); }
77  Music* getMusic() { return &music_; }
78  void setCamera(Camera* camera) {
79  camera_ = camera;
80  idToObjectMap_[0] = (Object*)camera_;
81  camera_->setGameLevelId(0);
82  }
83 
84  void setId(const int &id) { id_ = id; }
85  int getId() { return id_; }
86 
87  float getElapsedTime() { return elapsedTime_; }
88  void setElapsedTime(const float &elapsedTime) { elapsedTime_ = elapsedTime; }
89 
90  void setComplete(const bool &isComplete) { isComplete_ = isComplete; }
91  std::string getMusicPath() { return musicPath_; }
92  void setMusicPath(const std::string &musicPath) { musicPath_ = musicPath; }
93  Vector* getLightDirection() { return &lightDirection_; }
94 
95  void setSkyBox(float[][3], const int&, const int&);
96  void setLightDirection(const float &x, const float &y, const float &z) {
97  lightDirection_.setVector(x, y, z);
98  lightDirection_.normalize();
99  }
100 
101  Object* getObjectFromId(const int &id) {
102  return (id >= 0 && id < MAX_LEVEL_OBJECTS ? idToObjectMap_[id] : NULL);
103  }
104 
105  private:
106  unsigned int lists_; // display lists used for rendering
107 
108  Vector lightDirection_;
109 
110  ModelGameObject* player_; // player object
111  Object* camera_; // camera
112  Terrain *terrain_; // Terrain for this level (if one is loaded)
113 
114  Music music_;
115 
116  ObjectList objects_;
117  std::map <std::string, ObjectList> freeObjects_;
118  Object* idToObjectMap_[MAX_LEVEL_OBJECTS];
119  unsigned int numObjects_;
120 
121  // colors for sky box
122  float bgcolor_[3][3];
123 
124  bool isComplete_;
125 
126  float elapsedTime_;
127 
128  QuadTree quadTree_;
129  DisplayList displayList_;
130 
131  bool grid_;
132  bool bboxes_;
133  bool controlTriangles_;
134 
135  std::string musicPath_;
136 
137  int id_;
138 
139  lua_State* luaState_;
140 
141  bool prepLevelLoad(const char* luaCode);
142  bool finishLevelLoad();
143 };
144 
145 #endif
Definition: Object.h:35
Camera management.
Definition: QuadTree.h:18
Definition: Vector.h:15
Definition: terrain.h:14
Create a linked list of game objects.
Definition: DisplayList.h:12
Definition: ObjectList.h:13
Load and play songs.
Base game object from which all concrete types are defined.
Definition: GameLevel.h:30
representation of a quadtree.
Definition: Camera.h:13
Definition: Music.h:17