1 //==============================================================================
2 // This program is free software; you can redistribute it and/or modify
3 // it under the terms of the GNU General Public License as published by
4 // the Free Software Foundation; either version 2 of the License, or
5 // (at your option) any later version.
6 //
7 // This program is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10 // GNU Library General Public License for more details.
11 //
12 // You should have received a copy of the GNU General Public License
13 // along with this program; if not, write to the Free Software
14 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
15 //==============================================================================
16 
17 //==============================================================================
18 // File: cWorld.hpp
19 // Project: Shooting Star
20 // Author: Jarmo Hekkanen <jarski@2ndpoint.fi>
21 // Copyrights (c) 2003 2ndPoint ry (www.2ndpoint.fi)
22 //------------------------------------------------------------------------------
23 // Revision history
24 //==============================================================================
25 #ifndef cWorld_hpp
26 #define cWorld_hpp
27 //==============================================================================
28 // Includes
29 #include <list>
30 #include <vector>
31 #include <string>
32 #include "cMap.hpp"
33 #include "Types.hpp"
34 //------------------------------------------------------------------------------
35 // Namespaces
36 using namespace std;
37 namespace ShootingStar {
38 //------------------------------------------------------------------------------
39 // Forward declarations
40 class cObject;
41 class cRenderable;
42 class cCollidable;
43 class cPositionable;
44 //==============================================================================
45 
46 //==============================================================================
47 //! Game world (map and objects) singleton
48 //------------------------------------------------------------------------------
49 class cWorld
50 {
51 	// Constructor & Destructor
52 	private:
53 		//! Constructor
54 		cWorld (void);
55 	public:
56 		//! Destructor
57 		~cWorld (void);
58 
59 	// Public methods
60 	public:
61 		//! Return singleton
62 		static cWorld &GetInstance (void);
63 
64 		//! Load map from file
65 		void LoadMap (string filename);
66 
67 		//! Spawn object
68 		void SpawnObject (cObject *pObject);
69 		//! Remove object
70 		void RemoveObject (cObject *pObject);
71 		//! Remove all objects
72 		void RemoveAllObjects (void);
73 		//! Return object with matching ID
74 		cObject *GetObject (ObjectID ID);
75 
76 		//! Render the world
77 		void Render (Uint32 deltaTime);
78 		//! Update the world
79 		void Update (Uint32 deltaTime);
80 
81 		//! Select random position & rotation for positionable object
82 		void RandomPlace (cPositionable *pObject, float range=0.0f);
83 		bool CollidesWithWalls (cVector2f begin, cVector2f end);
84 
85 		//! Get map size
GetMapSize(int & width,int & height) const86 		void GetMapSize (int &width, int &height) const
87 		{
88 			width = mMap.GetWidth ();
89 			height = mMap.GetHeight ();
90 		};
GetObjectCount(void) const91 		int GetObjectCount (void) const { return mObjectList.size (); };
92 
93 	// Private methods
94 	private:
95 		void CollisionDetection (Uint32 deltaTime);
96 		void MoveObject (cCollidable *pObject, list<cCollidable*>::iterator temp, Uint32 deltaTime);
97 		/*void DebugRenderWalls (void);
98 		void BuildSectors (void);*/
99 
100 	// Member variables
101 	private:
102 		list<cObject*> mObjectList;	//!< List of objects in the world
103 		list<cRenderable*> mRenderList;		//!< List of renderable objects
104 		list<cCollidable*> mCollisionList;	//!< List of collidable objects
105 		cMap mMap;
106 
107 		// --- Collision detection ---
108 		vector<tWall> mWallList;
109 		/*int mSectorSize;	Stuff for more advanced collision detection
110 		int mHSectors;
111 		int mVSectors;
112 		vector<cVector2f> mPoints;
113 		vector<vector <tWall> > mSectors;*/
114 };
115 //==============================================================================
116 
117 //==============================================================================
118 }		// End of the ShootingStar namespace
119 #endif // cWorld_hpp
120 //------------------------------------------------------------------------------
121 // EOF
122 //==============================================================================
123