![]() |
Dragonfly 2.2
A text-based game engine
|
00001 /// 00002 /// The game world manager 00003 /// 00004 00005 #ifndef __WORLD_MANAGER_H__ 00006 #define __WORLD_MANAGER_H__ 00007 00008 #include "Box.h" 00009 #include "Circle.h" 00010 #include "ObjectList.h" 00011 #include "Line.h" 00012 #include "Manager.h" 00013 #include "Position.h" 00014 #include "SceneGraph.h" 00015 #include "ViewObject.h" 00016 00017 #define MAX_ALTITUDE 4 ///< Drawing order 0 to MAX 00018 00019 class WorldManager : public Manager { 00020 00021 private: 00022 WorldManager(); ///< Private since a singleton. 00023 WorldManager (WorldManager const&); ///< Don't allow copy. 00024 void operator=(WorldManager const&); ///< Don't allow assignment. 00025 int obj_id; ///< Next object id to assign. 00026 int next_level; ///< Next level to assign (0 no change). 00027 00028 protected: 00029 SceneGraph scene_graph; ///< Storage for all objects, Game and View. 00030 ObjectList deletions; ///< List of all GameObjects to delete. 00031 GameObject *p_view_following; ///< GameObject view is following. 00032 Box boundary; ///< World boundaries. 00033 Box view; ///< Player window view. 00034 00035 public: 00036 ~WorldManager(); 00037 00038 /// Get the one and only instance of the WorldManager. 00039 static WorldManager &getInstance(); 00040 00041 /// Startup the game world (initialize everthing to empty). 00042 /// Return 0. 00043 int startUp(); 00044 00045 /// Shutdown the game world. 00046 void shutDown(); 00047 00048 /// Add Object to world. 00049 /// Return 0 if ok, else -1. 00050 int insertObject(GameObject *p_go); 00051 int insertObject(ViewObject *p_vo); 00052 00053 /// Remove Object from world. 00054 /// Return 0 if ok, else -1. 00055 int removeObject(GameObject *p_go); 00056 int removeObject(ViewObject *p_vo); 00057 00058 /// Return a list of all GameObjects in world. 00059 /// Return NULL if list is empty. 00060 ObjectList getAllGameObjects(void); 00061 00062 /// Return a list of all ViewObjects in world. 00063 /// Return NULL if list is empty. 00064 ObjectList getAllViewObjects(void); 00065 00066 /// Indicate object is to be deleted at end of current game loop. 00067 /// Return 0 if ok, else -1. 00068 int markForDelete(Object *p_o); 00069 00070 /// Update world. 00071 /// Send "step" event to all interested objects. 00072 /// Update positions of GameObjects based on their velocities. 00073 /// Update the SceneGraph for those marked for updates. 00074 /// Lastly, delete GameObjectsmarked for deletion. 00075 void update(); 00076 00077 /// Draw, sending draw event to all GameObjects in view. 00078 /// Draw bottom up, from -MAX_ALTITUDE to MAX_ALTITUDE 00079 /// Draw ViewObjects last. 00080 void draw(); 00081 00082 /// Move GameObject. 00083 /// If no collision with solid, move ok else don't move object. 00084 /// If p_go is Spectral, move ok. 00085 /// If move ok, adjust camera if following this GameObject. 00086 /// Return 0 if move ok, else -1 if collision with solid. 00087 int moveGameObject(GameObject *p_go, Position where); 00088 00089 /// Return list of GameObjects collided with at Position 'where'. 00090 /// Collisions only with solid GameObjects. 00091 /// Does not consider if p_go is solid or not. 00092 ObjectList isCollision(GameObject *p_go, Position where); 00093 00094 /// Return list of all GameObjects at Position 'where'. 00095 /// Does include bounding boxes. Return empty list if none found. 00096 ObjectList gameObjectsAtPosition(Position where); 00097 00098 /// Return list of all GameObjects in Box. 00099 /// Does include bounding boxes. Return empty list if none found. 00100 ObjectList gameObjectsInBox(Box box); 00101 00102 /// Return a list of all GameObjects on line from point1 to point2. 00103 /// Does include bounding boxes. Return empty list if none found. 00104 ObjectList gameObjectsOnLine(Line line); 00105 00106 /// Return a list of all GameObjects in circle. 00107 /// Does include bounding boxes. Return empty list if none found. 00108 ObjectList gameObjectsInCircle(Circle circle); 00109 00110 /// Get game world boundary. 00111 Box getBoundary(); 00112 00113 /// Set game world boundary. 00114 void setBoundary(Box new_boundary); 00115 00116 /// Get camera view for game world. 00117 Box getView(); 00118 00119 /// Set camera view for game world. 00120 void setView(Box new_view); 00121 00122 /// Set camera view to center camera on GameObject. 00123 /// If p_new_view_following not legit, return -1 else return 0. 00124 /// Set to NULL to stop following. 00125 int setViewFollowing(GameObject *p_new_view_following); 00126 00127 /// Set camera view to center on Position view_pos. 00128 /// View edge will not go beyond world boundary. 00129 void setViewPosition(Position view_pos); 00130 00131 /// Return current game level. 00132 int getLevel(); 00133 00134 /// Set game level. Return 0 if ok, else -1. 00135 int setLevel(int new_level); 00136 00137 /// Return a reference to SceneGraph. 00138 SceneGraph &getSceneGraph(); 00139 }; 00140 00141 #endif // __WORLD_MANAGER_H__