1 #ifndef JVGS_GAME_LEVEL_H 2 #define JVGS_GAME_LEVEL_H 3 4 #include "../sketch/Sketch.h" 5 #include "../video/Renderer.h" 6 #include "../core/XMLLoadable.h" 7 #include "../core/View.h" 8 #include "../math/BoundingBox.h" 9 #include "../math/CollisionDetector.h" 10 #include <vector> 11 #include <string> 12 #include <map> 13 14 class TiXmlElement; 15 16 namespace jvgs 17 { 18 namespace game 19 { 20 class Entity; 21 class Camera; 22 class CameraFactory; 23 24 /** Class that represents a level the player can play through. 25 */ 26 class Level: public core::XMLLoadable, public core::View 27 { 28 private: 29 /** The game world. */ 30 sketch::Sketch *world; 31 32 /** Collision detector for the world. */ 33 math::CollisionDetector *collisionDetector; 34 35 /** The entities in the game world. */ 36 std::vector<Entity*> entities; 37 38 /** Entities by id. */ 39 std::map<std::string, Entity*> entitiesById; 40 41 /** Camera. */ 42 Camera *camera; 43 44 /** Level bounding box. */ 45 math::BoundingBox boundingBox; 46 47 /** Camera factories. */ 48 static std::map<std::string, CameraFactory*> cameraFactories; 49 50 protected: 51 /* Override. 52 */ 53 void loadData(TiXmlElement *element); 54 55 public: 56 /** Constructor. 57 */ 58 Level(); 59 60 /** Constructor. 61 * @param element TiXmlElement to load the data from. 62 */ 63 Level(TiXmlElement *element); 64 65 /** Constructor. 66 * @param fileName XML file to load the data from. 67 */ 68 Level(const std::string &fileName); 69 70 /** Detructor. 71 */ 72 virtual ~Level(); 73 74 /** Get the level world. 75 * @return The level world. 76 */ 77 virtual sketch::Sketch *getWorld() const; 78 79 /** Get the level world collision detector. 80 * @return The level world collision detector. 81 */ 82 virtual math::CollisionDetector *getCollisionDetector() const; 83 84 /** Get the number of entities. 85 * @return The number of entities. 86 */ 87 virtual int getNumberOfEntities() const; 88 89 /** Get an entity by index. 90 * @param index Index of the entity to retrieve. 91 * @return The requested entity. 92 */ 93 virtual Entity *getEntity(int index) const; 94 95 /** Add an entity to the level. 96 * @param entity Entity to add. 97 */ 98 # ifdef SWIG 99 %apply SWIGTYPE *DISOWN {Entity* entity}; 100 # endif 101 virtual void addEntity(Entity *entity); 102 103 /** Get an entity by id. 104 * @param id Id of the entity to retrieve. 105 * @return The requested entity. 106 */ 107 virtual Entity *getEntityById(const std::string &id); 108 109 /* Override 110 */ 111 virtual void update(float ms); 112 113 /* Override 114 */ 115 virtual void render(); 116 }; 117 } 118 } 119 120 #endif 121